Calls and Functions 24

This commit is contained in:
nazrin 2025-06-09 03:54:01 +00:00
parent 2cd7a44bc7
commit a45f6a9e17
18 changed files with 550 additions and 285 deletions

View file

@ -13,6 +13,7 @@ struct OpColour{
enum OpConst;
enum OpStack;
enum OpJump;
enum OpCall;
enum OpCode : ubyte{
@OpConst @(OpColour("200", "200", "100")) Constant,
@ -48,7 +49,9 @@ enum OpCode : ubyte{
@(OpColour("200", "100", "100")) Not,
@(OpColour("100", "100", "200")) Negate,
@(OpColour("000", "200", "100")) Print,
@(OpColour("000", "200", "100")) Return,
@OpCall @(OpColour("250", "200", "250")) Call,
@(OpColour("250", "190", "200")) Return,
}
struct Chunk{
@ -68,12 +71,12 @@ struct Chunk{
code ~= b;
lines ~= line;
}
size_t addConstant(Value value){
long index = constants[].countUntil(value);
int addConstant(Value value){
int index = cast(int)constants[].countUntil(value);
if(index >= 0)
return index;
constants ~= value;
return constants.count - 1;
return cast(int)constants.count - 1;
}
void free(){
code.free();