Variable references in blocks now work.

:D :D :D
This commit is contained in:
Jacob Signorovitch 2025-02-04 17:00:28 -05:00
parent 78e31c3e27
commit fbabf71d64
3 changed files with 13 additions and 0 deletions

View File

@ -29,6 +29,7 @@ void ast_destroy(AST* ast) {
case AST_TYPE_CALL: ast_call_data_destroy(ast->data); break;
case AST_TYPE_VREF: ast_vref_data_destroy(ast->data); break;
case AST_TYPE_VDEF: ast_vdef_data_destroy(ast->data); break;
case AST_TYPE_BLOCK: ast_block_data_destroy(ast->data); break;
default:
log_dbgf("Unknown ast type %d (max: %d)", ast->type, AST_TYPE_MAX);
}

View File

@ -35,6 +35,7 @@ ASTNumData exec_start(AST* ast) {
ASTNumData exec_exp(AST* ast, Stack* scope) {
log_dbg("Started execution.");
switch (ast->type) {
case AST_TYPE_BLOCK: return exec_block(ast, scope);
case AST_TYPE_CALL: return exec_call(ast, scope);
case AST_TYPE_NUM: return *(ASTNumData*)ast->data;
case AST_TYPE_VREF: return exec_vref(ast, scope);
@ -44,6 +45,16 @@ ASTNumData exec_exp(AST* ast, Stack* scope) {
}
}
ASTNumData exec_block(AST* ast, Stack* scope) {
ASTBlockData* block = (ASTBlockData*) ast->data;
// Loop through all but last ast.
for (int i = 0; i < block->ln - 1; i++)
exec_exp(block->inside[i], scope);
return exec_exp(block->inside[block->ln - 1], scope);
}
ASTNumData exec_call(AST* ast, Stack* scope) {
log_dbg("Started call execution.");
fflush(stdout);

View File

@ -8,6 +8,7 @@
// Start executing at the root of the AST. Initialize the `scope`.
ASTNumData exec_start(AST* ast);
ASTNumData exec_exp(AST* ast, Stack* scope);
ASTNumData exec_block(AST* ast, Stack* scope);
ASTNumData exec_call(AST* ast, Stack* scope);
ASTNumData exec_vref(AST* ast, Stack* scope);
ASTNumData exec_vdef(AST* ast, Stack* scope);