diff --git a/src/ast.c b/src/ast.c index 3b1c5d4..24c0cc4 100644 --- a/src/ast.c +++ b/src/ast.c @@ -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); } diff --git a/src/exec.c b/src/exec.c index 8d87d08..dc915f3 100644 --- a/src/exec.c +++ b/src/exec.c @@ -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); diff --git a/src/include/exec.h b/src/include/exec.h index 657e07e..630d33b 100644 --- a/src/include/exec.h +++ b/src/include/exec.h @@ -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);