Chunks of Bytecode 14

This commit is contained in:
nazrin 2025-06-03 01:54:47 +00:00
parent 848c846e09
commit 7fa01b4fb9
5 changed files with 102 additions and 0 deletions

26
src/clox/chunk.d Normal file
View file

@ -0,0 +1,26 @@
module clox.chunk;
import std.container.array;
import std.stdio;
import clox.value;
enum OpCode : ubyte{
OP_CONSTANT,
OP_RETURN,
}
struct Chunk{
Array!ubyte code;
Array!uint lines;
Array!Value constants;
ubyte addConstant(in Value value) @nogc nothrow {
constants ~= value;
return cast(ubyte)((constants.length) - 1);
}
void write(ubyte b, uint line = 0) @nogc nothrow {
code ~= b;
lines ~= line;
}
}