Fixed some functions.

This commit is contained in:
Jacob Signorovitch 2025-01-11 11:05:26 -05:00
parent 681e005a68
commit d13bf883b5

View File

@ -9,7 +9,6 @@
extern AST* root; extern AST* root;
ASTNumData exec_expr(AST* ast) { ASTNumData exec_expr(AST* ast) {
// ast_print(ast);
log_dbg("Started execution."); log_dbg("Started execution.");
switch (ast->type) { switch (ast->type) {
case AST_TYPE_CALL: return exec_call(ast); case AST_TYPE_CALL: return exec_call(ast);
@ -22,47 +21,48 @@ ASTNumData exec_call(AST* ast) {
log_dbg("Started call execution."); log_dbg("Started call execution.");
fflush(stdout); fflush(stdout);
ASTCallData* calldata = (ASTCallData*)ast->data; ASTCallData* calldata = (ASTCallData*)ast->data;
if (calldata->argc >= 1) {
if (!strcmp(calldata->to, "sum")) { if (!strcmp(calldata->to, "sum")) {
double total = 0; double total = exec_expr(calldata->argv[0]);
for ( for (
size_t i = 0; size_t i = 1;
i < calldata->argc; i < calldata->argc;
total += exec_expr(calldata->argv[i++]) total += exec_expr(calldata->argv[i++])
); );
return total; return total;
} else if (!strcmp(calldata->to, "sub")) { } else if (!strcmp(calldata->to, "sub")) {
double total = 0; double total = exec_expr(calldata->argv[0]);
for ( for (
size_t i = 0; size_t i = 1;
i < calldata->argc; i < calldata->argc;
total -= exec_expr(calldata->argv[i++]) total -= exec_expr(calldata->argv[i++])
); );
return total; return total;
} else if (!strcmp(calldata->to, "mul")) { } else if (!strcmp(calldata->to, "mul")) {
double total = 1; double total = exec_expr(calldata->argv[0]);
for ( for (
size_t i = 0; size_t i = 1;
i < calldata->argc; i < calldata->argc;
total *= exec_expr(calldata->argv[i++]) total *= exec_expr(calldata->argv[i++])
); );
return total; return total;
} else if (!strcmp(calldata->to, "div")) { } else if (!strcmp(calldata->to, "div")) {
double total = 1; double total = exec_expr(calldata->argv[0]);
for ( for (
size_t i = 0; size_t i = 1;
i < calldata->argc; i < calldata->argc;
total /= exec_expr(calldata->argv[i++]) total /= exec_expr(calldata->argv[i++])
); );
return total; return total;
} }}
return -1000; return -1000;
} }