aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/doer.c88
-rw-r--r--src/include/tree.h6
-rw-r--r--src/include/util.h2
-rw-r--r--src/tree.c22
4 files changed, 114 insertions, 4 deletions
diff --git a/src/doer.c b/src/doer.c
index 683e183..6d38bd3 100644
--- a/src/doer.c
+++ b/src/doer.c
@@ -3,6 +3,29 @@
#include "include/util.h"
#include <string.h>
+
+/*
+
+
+ find_target();
+ args = read_args() {
+ return args
+ }
+
+ for (arg in args) {
+ stack_add(targets, args)
+ }
+
+ :int:add1.:int:x, :int:y = +.x,+.y,1;
+
+ :int:a = 5
+ :int:b 99
+
+ add1.a,99
+
+
+*/
+
target_t* target_init(char* name, tree_t* tree) {
target_t* target = emalloc(sizeof(target_t));
target->tree = tree;
@@ -77,6 +100,8 @@ tree_t* doer_find_target_from_call(doer_t* doer) {
}
}
+ for (target_t* t = doer->targets; t; printf("%s\n", t->tree->data.def.tag->data.tag.nxt->data.tag.val) && (t = t->nxt));
+
DIEF("Call to missing target: %s", call_name);
}
@@ -92,7 +117,7 @@ tree_t* doer_eval_prim(doer_t* doer) {
case TREE_TYPE_LINT:
return doer->tree;
default:
- DIE("???");
+ DIEF("Unknown primitive type: %d", doer->tree->type);
}
}
@@ -308,8 +333,8 @@ void doer_do_expr(doer_t* doer) {
void doer_do_def(doer_t* doer) {
tree_t* tag2 = doer->tree->data.def.tag->data.tag.nxt;
target_t* target = target_init(
- tag2->data.tag.val, // HACK: Grab the 2nd tag's value, without
- // checking if it's actually there…
+ tag2->data.tag.val, // HACK: Grab the 2nd tag's value, without
+ // checking if it's actually there…
doer->tree
);
@@ -319,13 +344,68 @@ void doer_do_def(doer_t* doer) {
void doer_do_call(doer_t* doer) {
tree_t* the_call = doer->tree;
tree_t* resolved = NULL;
+ tree_t* target_def = NULL;
// Could modify the *current* tree, but only if it's a blin.
resolved = doer_do_call_blin(doer);
if (!resolved) {
doer->tree = the_call;
- resolved = doer_find_target_from_call(doer);
+ target_def = doer_find_target_from_call(doer); // Is def.
+
+ tree_t* darg = target_def->data.def.arg;
+ LOG_DBGF("------------------------------");
+ tree_print(darg, 0);
+
+
+ tree_t* carg = the_call->data.call.arg;
+
+ target_t
+ * targs = NULL, // Pointer to first target.
+ * targ = targs; // Pointer to where new targets will be added.
+
+ // Evaluate arguments.
+ while (darg) {
+ doer->tree = carg->data.carg.val;
+ // HACK: Assume already a primitive.
+ tree_t* carg_resolved = doer->tree; //doer_eval_prim(doer);
+
+ char
+ * darg_type = darg->data.darg.tag->data.tag.val,
+ * carg_type = tree_type2str(carg_resolved->type);
+
+ if (strcmp(darg_type, carg_type)) DIE("Type mismatch.");
+
+ targ = target_init(
+ "This field doesn't actually do anything but I can't be bothered to remove it :P",
+ carg_resolved
+ );
+
+ targ = targ->nxt;
+ darg = darg->data.darg.nxt;
+
+ printf("\n\n[---\n");
+ for (target_t* t = doer->targets; t; printf("%s\n", t->tree->data.def.tag->data.tag.nxt->data.tag.val) && (t = t->nxt));
+ printf("---]\n");
+ }
+
+ target_t* old_ltarget = doer->ltarget;
+
+ // Append the new targets from the args.
+ doer->ltarget->nxt = targs;
+ doer->ltarget = targ;
+
+ // Execute the call.
+ doer->tree = target_def->data.def.val;
+ printf("[---\n");
+ for (target_t* t = doer->targets; t; printf("%s\n", t->tree->data.def.tag->data.tag.nxt->data.tag.val) && (t = t->nxt));
+ printf("---]\n");
+ resolved = doer_eval_prim(doer);
+
+ // Clean up temporary targets.
+ target_destroy(targs);
+ old_ltarget->nxt = NULL;
+ doer->ltarget = old_ltarget;
}
tree_swp_call(the_call, resolved);
diff --git a/src/include/tree.h b/src/include/tree.h
index 5e0279f..d22efc1 100644
--- a/src/include/tree.h
+++ b/src/include/tree.h
@@ -101,6 +101,12 @@ int tree_cmp(tree_t* tree_0, tree_t* tree_1);
// Swaps a tree for another.
void tree_swp_call(tree_t* t0, tree_t* t1);
+// Determines if a tree_type_t matches a string.
+int tree_type_str(tree_type_t tree_type, char* str);
+
+// Returns a string for a tree type.
+char* tree_type2str(tree_type_t tree_type);
+
/* Print a tree. */
void tree_print(tree_t* tree, int nest);
diff --git a/src/include/util.h b/src/include/util.h
index 60db492..0d3090a 100644
--- a/src/include/util.h
+++ b/src/include/util.h
@@ -116,6 +116,7 @@
void die(const char*, ...);
#define DIEF(fmt, ...) HIDE( \
fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m CAUSE OF DEATH:\x1b[0m\x1b[31m "); \
+ LOG_FINF; \
fprintf(stderr, fmt, ##__VA_ARGS__); \
fprintf(stderr, "\x1b[0m\n"); \
fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m Exiting...\x1b[0m\n"); \
@@ -124,6 +125,7 @@ void die(const char*, ...);
#define DIE(body) HIDE( \
fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m CAUSE OF DEATH:\x1b[0m\x1b[31m "); \
+ LOG_FINF; \
fprintf(stderr, body); \
fprintf(stderr, "\x1b[0m\n"); \
fprintf(stderr, "\x1b[37m[\x1b[91;1m==\x1b[0m\x1b[37m]\x1b[91;1m Exiting...\x1b[0m\n"); \
diff --git a/src/tree.c b/src/tree.c
index 35c8a3f..916936d 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -229,6 +229,28 @@ void tree_swp_call(tree_t* t0, tree_t* t1) {
}
}
+int tree_type_str(tree_type_t tree_type, char* str) {
+ switch (tree_type) {
+ case TREE_TYPE_LINT:
+ return !strcmp("int", str);
+ case TREE_TYPE_LSTR:
+ return !strcmp("str", str);
+ default:
+ DIE("Invalid primitive type.");
+ }
+}
+
+char* tree_type2str(tree_type_t tree_type) {
+ switch (tree_type) {
+ case TREE_TYPE_LINT:
+ return "int";
+ case TREE_TYPE_LSTR:
+ return "str";
+ default:
+ DIE("Invalid primitive type.");
+ }
+}
+
/*
Every time I think there's a problem with the parser, it turns out it's
just this stupid tree print function. Now it works. Never touching it