aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/doer.c23
-rw-r--r--src/include/doer.h4
2 files changed, 25 insertions, 2 deletions
diff --git a/src/doer.c b/src/doer.c
index 5262fb1..bc6d4bd 100644
--- a/src/doer.c
+++ b/src/doer.c
@@ -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