Compiling Expressions 17
This commit is contained in:
parent
8fb449825d
commit
41404633da
18 changed files with 546 additions and 64 deletions
|
|
@ -1,25 +1,6 @@
|
|||
module clox.util;
|
||||
|
||||
struct Stack(T, size_t N){
|
||||
T* top;
|
||||
T[N] data;
|
||||
invariant{ assert(top <= data.ptr + N); assert(top >= data.ptr); }
|
||||
this(int _) @nogc nothrow{
|
||||
top = data.ptr;
|
||||
}
|
||||
void push(T value) @nogc nothrow{
|
||||
assert(top < data.ptr + N);
|
||||
debug assert(*top is T.init);
|
||||
*(top++) = value;
|
||||
}
|
||||
T pop() @nogc nothrow{
|
||||
assert(top > data.ptr);
|
||||
T t = *(--top);
|
||||
debug *(top) = T.init;
|
||||
return t;
|
||||
}
|
||||
const(T)[] live() @nogc nothrow const{
|
||||
return data[0 .. (top - data.ptr)];
|
||||
}
|
||||
}
|
||||
import std.stdio;
|
||||
import std.traits : isUnsigned;
|
||||
import std.container.array;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue