Fixed some functions.
This commit is contained in:
parent
681e005a68
commit
d13bf883b5
20
src/exec.c
20
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;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user