mirror of
https://github.com/krgamestudios/Toy.git
synced 2026-04-15 14:54:07 +10:00
Fixed a 'malformed assignment' issue, read more
I've also added some support for compiler errors in general, but these will get expanded on later. I've also quickly added a valgrind option to the tests and found a few leaks. I'll deal with these later. Summary of changes: * Clarified the lifetime of the bytecode in memory * Erroneous routines exit without compiling * Empty VMs don't run * Added a check for malformed assignments * Renamed "routine" to "module" within the VM * VM no longer tries to free the bytecode - must be done manually * Started experimenting with valgrind, not yet ready
This commit is contained in:
@@ -57,11 +57,17 @@ static void writeBytecodeBody(Toy_Bytecode* bc, Toy_Ast* ast) {
|
||||
//eventually, the bytecode may support multiple modules packed into one file
|
||||
void* module = Toy_compileRoutine(ast);
|
||||
|
||||
//don't try writing an empty module
|
||||
if (module == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
size_t len = (size_t)(((int*)module)[0]);
|
||||
|
||||
expand(bc, len);
|
||||
memcpy(bc->ptr + bc->count, module, len);
|
||||
bc->count += len;
|
||||
bc->moduleCount++;
|
||||
}
|
||||
|
||||
//exposed functions
|
||||
@@ -73,9 +79,11 @@ Toy_Bytecode Toy_compileBytecode(Toy_Ast* ast) {
|
||||
bc.capacity = 0;
|
||||
bc.count = 0;
|
||||
|
||||
bc.moduleCount = 0;
|
||||
|
||||
//build
|
||||
writeBytecodeHeader(&bc);
|
||||
writeBytecodeBody(&bc, ast);
|
||||
writeBytecodeBody(&bc, ast); //TODO: implement module packing
|
||||
|
||||
return bc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user