diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/doer.c | 23 | ||||
-rw-r--r-- | src/include/doer.h | 4 |
2 files changed, 26 insertions, 1 deletions
@@ -77,7 +77,7 @@ tree_t* doer_find_target_from_call(doer_t* doer) { } } - DIE("Call to missing target."); + DIEF("Call to missing target: %s", call_name); } tree_t* doer_eval_prim(doer_t* doer) { @@ -260,6 +260,25 @@ tree_t* blin_sub(doer_t* doer) { return newt; } +tree_t* blin_mul(doer_t* doer) { + tree_t* tree = doer->tree; + + tree_t* args = tree->data.call.arg; + tree_t* arg1 = args; + tree_t* arg2 = arg1->data.carg.nxt; + + doer->tree = arg1->data.carg.val; + int a = doer_eval_lint(doer); + doer->tree = arg2->data.carg.val; + int b = doer_eval_lint(doer); + + tree_t* newt = tree_init(TREE_TYPE_LINT, tree->parent); + + newt->data.lint.val = a * b; + + return newt; +} + void doer_do_block(doer_t* doer) { if (!doer->tree) return; @@ -274,7 +293,9 @@ void doer_do_block(doer_t* doer) { void doer_do_expr(doer_t* doer) { switch (doer->tree->type) { case TREE_TYPE_CALL: + // Add targets doer_do_call(doer); + // Remove targets break; case TREE_TYPE_DEF: doer_do_def(doer); diff --git a/src/include/doer.h b/src/include/doer.h index 14f0a31..24f3911 100644 --- a/src/include/doer.h +++ b/src/include/doer.h @@ -75,6 +75,9 @@ static tree_type_t blin_add_args[] = { TREE_TYPE_LINT, TREE_TYPE_LINT }; // `-`: Subtract two integers. tree_t* blin_sub(doer_t* doer); static tree_type_t blin_sub_args[] = { TREE_TYPE_LINT, TREE_TYPE_LINT }; +// `*`: Multiply two integers. +tree_t* blin_mul(doer_t* doer); +static tree_type_t blin_mul_args[] = { TREE_TYPE_LINT, TREE_TYPE_LINT }; void doer_do_call(doer_t* doer); tree_t* doer_do_call_blin(doer_t* doer); @@ -95,6 +98,7 @@ static blinf_t blinfs[] = { { blin_str_cat, TREE_TYPE_LSTR, blin_str_cat_args, "str_cat" }, { blin_add, TREE_TYPE_LINT, blin_add_args, "+" }, { blin_sub, TREE_TYPE_LINT, blin_sub_args, "-" }, + { blin_mul, TREE_TYPE_LINT, blin_mul_args, "*" }, }; #endif |