From d13bf883b5338001132f59e5bf5c174fa07c9838 Mon Sep 17 00:00:00 2001 From: Jacob Date: Sat, 11 Jan 2025 11:05:26 -0500 Subject: [PATCH] Fixed some functions. --- src/exec.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/exec.c b/src/exec.c index d467ff6..f251093 100644 --- a/src/exec.c +++ b/src/exec.c @@ -9,7 +9,6 @@ extern AST* root; ASTNumData exec_expr(AST* ast) { - // ast_print(ast); log_dbg("Started execution."); switch (ast->type) { case AST_TYPE_CALL: return exec_call(ast); @@ -22,47 +21,48 @@ ASTNumData exec_call(AST* ast) { log_dbg("Started call execution."); fflush(stdout); ASTCallData* calldata = (ASTCallData*)ast->data; + if (calldata->argc >= 1) { if (!strcmp(calldata->to, "sum")) { - double total = 0; + double total = exec_expr(calldata->argv[0]); for ( - size_t i = 0; + size_t i = 1; i < calldata->argc; total += exec_expr(calldata->argv[i++]) ); return total; } else if (!strcmp(calldata->to, "sub")) { - double total = 0; + double total = exec_expr(calldata->argv[0]); for ( - size_t i = 0; + size_t i = 1; i < calldata->argc; total -= exec_expr(calldata->argv[i++]) ); return total; } else if (!strcmp(calldata->to, "mul")) { - double total = 1; + double total = exec_expr(calldata->argv[0]); for ( - size_t i = 0; + size_t i = 1; i < calldata->argc; total *= exec_expr(calldata->argv[i++]) ); return total; } else if (!strcmp(calldata->to, "div")) { - double total = 1; + double total = exec_expr(calldata->argv[0]); for ( - size_t i = 0; + size_t i = 1; i < calldata->argc; total /= exec_expr(calldata->argv[i++]) ); return total; - } + }} return -1000; }