Compiling Expressions 17

This commit is contained in:
nazrin 2025-06-04 19:49:53 +00:00
parent 8fb449825d
commit 41404633da
18 changed files with 546 additions and 64 deletions

View file

@ -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;