Functions are working, tests incomplete

This required a massive cross-cutting rework to the scope system,
multiple subtle bugfixes and relearning of the parser internals, but it
does appear that functions are working correctly.

A few caveats: for now, parameters are always constant, regardless of
type, return values can't be specified, and some script tests have been
written.

Most importantly, a key feature is working: closures.
This commit is contained in:
2026-04-12 11:47:26 +10:00
parent b0d9c15d33
commit c0c03a4110
18 changed files with 158 additions and 92 deletions

View File

@@ -334,8 +334,6 @@ int repl(const char* filepath, bool verbose) {
printf("%s> ", prompt); //shows the terminal prompt and begin
unsigned int runCount = 0; //used for initial preserveScope
//read from the terminal
while(fgets(inputBuffer, INPUT_BUFFER_SIZE, stdin)) {
//work around fgets() adding a newline
@@ -366,9 +364,8 @@ int repl(const char* filepath, bool verbose) {
printf("%s> ", prompt); //shows the terminal prompt
continue;
}
unsigned char* bytecode = Toy_compileToBytecode(ast);
Toy_bindVM(&vm, bytecode, runCount++ > 0);
Toy_bindVM(&vm, bytecode, NULL);
//run
Toy_runVM(&vm);
@@ -466,7 +463,7 @@ int main(int argc, const char* argv[]) {
//run the compiled code
Toy_VM vm;
Toy_initVM(&vm);
Toy_bindVM(&vm, bytecode, false);
Toy_bindVM(&vm, bytecode, NULL);
Toy_runVM(&vm);