WIP return keyword, read more

Functions are having issues with being copied around, especially
between buckets, leading to the scopes getting looped. The program gets
stuck in 'incrementRefCount()'.

It's past my time limit, so I'll keep working on it tomorrow with a
fresh mind.

All function stuff is still untested.

See #163
This commit is contained in:
2025-02-17 19:07:14 +11:00
parent 02dfc996b4
commit 639250f028
12 changed files with 215 additions and 26 deletions

View File

@@ -752,6 +752,21 @@ static unsigned int writeInstructionContinue(Toy_ModuleCompiler** mb, Toy_AstCon
return 0;
}
static unsigned int writeInstructionReturn(Toy_ModuleCompiler** mb, Toy_AstReturn ast) {
//the things to return
unsigned int retCount = writeModuleCompilerCode(mb, ast.child);
//output the print opcode
EMIT_BYTE(mb, code,TOY_OPCODE_RETURN);
//4-byte alignment
EMIT_BYTE(mb, code,(unsigned char)retCount);
EMIT_BYTE(mb, code,0);
EMIT_BYTE(mb, code,0);
return 0;
}
static unsigned int writeInstructionPrint(Toy_ModuleCompiler** mb, Toy_AstPrint ast) {
//the thing to print
writeModuleCompilerCode(mb, ast.child);
@@ -1158,6 +1173,10 @@ static unsigned int writeModuleCompilerCode(Toy_ModuleCompiler** mb, Toy_Ast* as
result += writeInstructionContinue(mb, ast->continuePoint);
break;
case TOY_AST_RETURN:
result += writeInstructionReturn(mb, ast->fnReturn);
break;
case TOY_AST_PRINT:
result += writeInstructionPrint(mb, ast->print);
break;