Global Variables 21
This commit is contained in:
parent
a7b7348f61
commit
4f2211eb72
9 changed files with 178 additions and 36 deletions
|
|
@ -1,5 +1,7 @@
|
|||
module clox.chunk;
|
||||
|
||||
import std.algorithm.searching;
|
||||
|
||||
import clox.memory;
|
||||
import clox.value;
|
||||
|
||||
|
|
@ -13,6 +15,11 @@ enum OpCode : ubyte{
|
|||
@(OpColour("255", "200", "100")) True,
|
||||
@(OpColour("255", "200", "100")) False,
|
||||
|
||||
@(OpColour("000", "200", "100")) Pop,
|
||||
@(OpColour("000", "200", "150")) GetGlobal,
|
||||
@(OpColour("000", "200", "150")) DefineGlobal,
|
||||
@(OpColour("000", "200", "150")) SetGlobal,
|
||||
|
||||
@(OpColour("255", "100", "100")) Equal,
|
||||
@(OpColour("255", "100", "100")) Greater,
|
||||
@(OpColour("255", "100", "100")) Less,
|
||||
|
|
@ -27,6 +34,7 @@ enum OpCode : ubyte{
|
|||
|
||||
@(OpColour("200", "100", "100")) Not,
|
||||
@(OpColour("100", "100", "200")) Negate,
|
||||
@(OpColour("000", "200", "100")) Print,
|
||||
@(OpColour("000", "200", "100")) Return,
|
||||
}
|
||||
|
||||
|
|
@ -55,8 +63,12 @@ struct Chunk{
|
|||
count++;
|
||||
}
|
||||
int addConstant(Value value){
|
||||
constants.write(value);
|
||||
return constants.count - 1;
|
||||
int index = cast(int)constants.values[0 .. constants.count].countUntil(value);
|
||||
if(index >= 0)
|
||||
return index;
|
||||
assert(constants.count <= ubyte.max);
|
||||
constants.write(value);
|
||||
return constants.count - 1;
|
||||
}
|
||||
void free(){
|
||||
FREE_ARRAY!ubyte(code, capacity);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue