diff options
author | c | 2024-04-16 15:19:57 -0400 |
---|---|---|
committer | c | 2024-04-16 15:19:57 -0400 |
commit | c26ffc484d30dce65754c0081baa5402346c703a (patch) | |
tree | 0c8c98eed4ba68fac761e26ef63fce8d660bdf55 /src | |
parent | 2e6d3b3343f8e51bc2f3749017ee8a22d7e8b2f6 (diff) |
One may now add and subtract integers.
Diffstat (limited to 'src')
-rw-r--r-- | src/doer.c | 23 | ||||
-rw-r--r-- | src/include/doer.h | 4 |
2 files changed, 25 insertions, 2 deletions
@@ -229,9 +229,9 @@ tree_t* blin_add(doer_t* doer) { tree_t* arg1 = args; tree_t* arg2 = arg1->data.carg.nxt; - doer->tree = arg1; + doer->tree = arg1->data.carg.val; int a = doer_eval_lint(doer); - doer->tree = arg2; + doer->tree = arg2->data.carg.val; int b = doer_eval_lint(doer); tree_t* newt = tree_init(TREE_TYPE_LINT, tree->parent); @@ -241,6 +241,25 @@ tree_t* blin_add(doer_t* doer) { return newt; } +tree_t* blin_sub(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; diff --git a/src/include/doer.h b/src/include/doer.h index 30b514e..14f0a31 100644 --- a/src/include/doer.h +++ b/src/include/doer.h @@ -72,6 +72,9 @@ static tree_type_t blin_str_cat_args[] = { TREE_TYPE_LSTR, TREE_TYPE_LSTR }; // `+`: Add two integers. tree_t* blin_add(doer_t* doer); 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 }; void doer_do_call(doer_t* doer); tree_t* doer_do_call_blin(doer_t* doer); @@ -91,6 +94,7 @@ static blinf_t blinfs[] = { { blin_printl, TREE_TYPE_LSTR, blin_printl_args, "printl" }, { 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, "-" }, }; #endif |