aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorc2024-03-16 10:59:12 -0400
committerc2024-03-16 10:59:12 -0400
commitaaf2ae7693e2b48358f7d3007aca9f0cb5f4950f (patch)
tree7bda5c35f11ff7e76116c123ffb40cc4aa470501 /src
parent8848b46c2873faa019f96b0194237745a80f78f2 (diff)
Can print multiple string variables.
Diffstat (limited to 'src')
-rw-r--r--src/doer.c32
-rw-r--r--src/include/doer.h2
-rw-r--r--src/lexer.c6
3 files changed, 28 insertions, 12 deletions
diff --git a/src/doer.c b/src/doer.c
index c2db0cc..8e11e6e 100644
--- a/src/doer.c
+++ b/src/doer.c
@@ -47,29 +47,39 @@ void doer_destroy(doer_t* doer) {
void doer_add_target(doer_t* doer, target_t* target) {
// First target being added.
if (!doer->targets) doer->targets = doer->ltarget = target;
- else doer->ltarget->nxt = target;
+ else {
+ doer->ltarget->nxt = target;
+ doer->ltarget = target;
+ }
}
-/*
-
- :str:var = "Hello"
- printl.var
+tree_t* doer_find_target_from_call(target_t* targetl, tree_t* call) {
+ if (!targetl) { DIE("Call to missing value."); }
+
+ char* last_target_name = targetl->tree->data.def.tag->data.tag.nxt->data.tag.val;
+ char* call_name = call->data.call.target;
-*/
+ if (!strcmp(last_target_name, call_name)) {
+ return targetl->tree;
+ } else {
+ return doer_find_target_from_call(targetl->nxt, call);
+ }
+}
char* doer_eval_str(doer_t* doer) {
// Assume tree type is a simple call to variable.
// Search through target list for matching variable.
// Return its value as a string (assume it's a string).
- // Assume there is only 1 target in the target list.
switch (doer->tree->type) {
case TREE_TYPE_CALL:
- // Assume there is only 1 target in the target list.
- doer->tree = doer->ltarget->tree->data.def.val;
+ doer->tree = doer_find_target_from_call(doer->targets, doer->tree);
+ return doer_eval_str(doer);
+ case TREE_TYPE_DEF:
+ doer->tree = doer->tree->data.def.val;
return doer_eval_str(doer);
case TREE_TYPE_LSTR:
- // Already done \o/
+ // Already done \o/.
return doer->tree->data.lstr.val;
default:
DIE("Wrong type, FOOL!");
@@ -118,7 +128,7 @@ void doer_do_expr(doer_t* doer) {
doer_do_def(doer);
break;
default:
- LOG_WARF("unknown tree type: %d", doer->tree->type);
+ LOG_WARF("Unknown tree type: %d", doer->tree->type);
}
}
diff --git a/src/include/doer.h b/src/include/doer.h
index 00c3c19..314edc3 100644
--- a/src/include/doer.h
+++ b/src/include/doer.h
@@ -47,7 +47,7 @@ typedef struct BLINF {
} blinf_t;
void doer_add_target(doer_t* doer, target_t* target);
-
+tree_t* doer_find_target_from_call(target_t* targetl, tree_t* call);
// Given a tree, evaluate it to a string (or type error).
char* doer_eval_str(doer_t* doer);
diff --git a/src/lexer.c b/src/lexer.c
index aa068a9..4ad8fd6 100644
--- a/src/lexer.c
+++ b/src/lexer.c
@@ -7,6 +7,12 @@
#include "include/syntax.h"
#include "include/token.h"
+/*
+
+ TODO: Fix bug where calls ending with numbers get interpreted as lints.
+
+*/
+
lexer_t* lexer_init(char* src) {
lexer_t* lexer;