aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorc2024-04-20 09:34:44 -0400
committerc2024-04-20 09:34:44 -0400
commit44d1f80279000efddbd8f24108f33297a9d2ad52 (patch)
treec4d8d67f4d4a332cd603d448593741cbb01d22ee /src
parentc26ffc484d30dce65754c0081baa5402346c703a (diff)
Multiplication may now be possible.
It may have been possible before, too.
Diffstat (limited to 'src')
-rw-r--r--src/doer.c23
-rw-r--r--src/include/doer.h4
2 files changed, 26 insertions, 1 deletions
diff --git a/src/doer.c b/src/doer.c
index bc6d4bd..683e183 100644
--- a/src/doer.c
+++ b/src/doer.c
@@ -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