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:
2024-11-16 21:02:37 +11:00
parent 04f0653595
commit 2f9489d5fd
12 changed files with 164 additions and 75 deletions

View File

@@ -2,17 +2,15 @@
#include "toy_common.h"
#include "toy_bytecode.h"
#include "toy_bucket.h"
#include "toy_stack.h"
#include "toy_scope.h"
typedef struct Toy_VM {
//hold the raw bytecode
unsigned char* bc;
//raw instructions to be executed
unsigned char* routine;
unsigned int routineSize;
unsigned char* module;
unsigned int moduleSize;
unsigned int paramSize;
unsigned int jumpsSize;
@@ -25,7 +23,7 @@ typedef struct Toy_VM {
unsigned int dataAddr;
unsigned int subsAddr;
unsigned int routineCounter;
unsigned int programCounter;
//stack - immediate-level values only
Toy_Stack* stack;
@@ -41,8 +39,8 @@ typedef struct Toy_VM {
} Toy_VM;
TOY_API void Toy_initVM(Toy_VM* vm);
TOY_API void Toy_bindVM(Toy_VM* vm, unsigned char* bytecode); //process the version data
TOY_API void Toy_bindVMToRoutine(Toy_VM* vm, unsigned char* routine); //process the routine only
TOY_API void Toy_bindVM(Toy_VM* vm, struct Toy_Bytecode* bc); //process the version data
TOY_API void Toy_bindVMToModule(Toy_VM* vm, unsigned char* module); //process the module only
TOY_API void Toy_runVM(Toy_VM* vm);
TOY_API void Toy_freeVM(Toy_VM* vm);