Added scopes using '{}' symbols, read more

I've also added a new literal type called 'identifier'. This will be
used for variable names, and has a type mask embedded in it.
This commit is contained in:
2022-08-08 15:02:12 +01:00
parent 08ce270e06
commit 6d5549fc8e
15 changed files with 335 additions and 68 deletions

View File

@@ -19,6 +19,7 @@ static void stderrWrapper(const char* output) {
void initInterpreter(Interpreter* interpreter, unsigned char* bytecode, int length) {
initLiteralArray(&interpreter->literalCache);
interpreter->scope = pushScope(NULL);
interpreter->bytecode = bytecode;
interpreter->length = length;
interpreter->count = 0;
@@ -31,6 +32,7 @@ void initInterpreter(Interpreter* interpreter, unsigned char* bytecode, int leng
void freeInterpreter(Interpreter* interpreter) {
freeLiteralArray(&interpreter->literalCache);
interpreter->scope = popScope(interpreter->scope);
FREE_ARRAY(char, interpreter->bytecode, interpreter->length);
freeLiteralArray(&interpreter->stack);
}
@@ -283,6 +285,15 @@ static void execInterpreter(Interpreter* interpreter) {
case OP_GROUPING_END:
return;
//scope
case OP_SCOPE_BEGIN:
interpreter->scope = pushScope(interpreter->scope);
break;
case OP_SCOPE_END:
interpreter->scope = popScope(interpreter->scope);
break;
default:
printf("Unknown opcode found %d, terminating\n", opcode);
printLiteralArray(&interpreter->stack, "\n");