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

@@ -33,7 +33,7 @@ void writeCompiler(Compiler* compiler, Node* node) {
switch(node->type) {
//TODO: more types, like variables, etc.
case NODE_ERROR: {
printf("[internal] NODE_ERROR encountered in writeCompiler()");
fprintf(stderr, "[Internal] NODE_ERROR encountered in writeCompiler()");
compiler->bytecode[compiler->count++] = OP_EOF; //1 byte
}
break;
@@ -80,6 +80,16 @@ void writeCompiler(Compiler* compiler, Node* node) {
compiler->bytecode[compiler->count++] = (unsigned char)OP_GROUPING_END; //1 byte
break;
case NODE_BLOCK:
compiler->bytecode[compiler->count++] = (unsigned char)OP_SCOPE_BEGIN; //1 byte
for (int i = 0; i < node->block.count; i++) {
writeCompiler(compiler, &(node->block.nodes[i]));
}
compiler->bytecode[compiler->count++] = (unsigned char)OP_SCOPE_END; //1 byte
break;
//TODO: conditional
}
}
@@ -202,6 +212,10 @@ unsigned char* collateCompiler(Compiler* compiler, int* size) {
emitByte(&collation, &capacity, &count, '\0'); //terminate the string
}
break;
default:
fprintf(stderr, "[Internal] Unknown literal type encountered within literal cache\n");
return NULL;
}
}