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; }