aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-07 22:48:35 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-07 22:48:35 -0800
commit22eb9a274386c7fbc5cdee2b86f621c44fd823e2 (patch)
treea215e21bf18d75914b9edd568a0da6a8b49ac2d0
parent5907934e467bf28291901ed3595125ef1ed724d9 (diff)
forgot what i did lol
-rw-r--r--Makefile3
-rw-r--r--examples/repl.stem5
-rw-r--r--examples/stdlib.stem2
-rw-r--r--main.c1
-rw-r--r--parser.c33
5 files changed, 38 insertions, 6 deletions
diff --git a/Makefile b/Makefile
index 9dec505..b5991f6 100644
--- a/Makefile
+++ b/Makefile
@@ -9,4 +9,7 @@ all:
clean:
rm stem
+
+install:
+ cp stem /usr/local/bin/
# end
diff --git a/examples/repl.stem b/examples/repl.stem
index 7f2010f..1468835 100644
--- a/examples/repl.stem
+++ b/examples/repl.stem
@@ -1 +1,4 @@
-loop [ "> " . read strquote eval loop ] func loop
+"./stdlib.stem" fread strquote eval
+"./math.stem" include
+
+repl [ "> " . read strquote eval repl ] func repl
diff --git a/examples/stdlib.stem b/examples/stdlib.stem
new file mode 100644
index 0000000..eca48c8
--- /dev/null
+++ b/examples/stdlib.stem
@@ -0,0 +1,2 @@
+evalstr [ strquote eval ] func
+include [ fread evalstr ] func
diff --git a/main.c b/main.c
index 4c058b4..afa2e65 100644
--- a/main.c
+++ b/main.c
@@ -2,6 +2,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
extern ht_t *WORD_TABLE;
extern array_t *STACK;
diff --git a/parser.c b/parser.c
index 32b0a94..1bbf793 100644
--- a/parser.c
+++ b/parser.c
@@ -1012,10 +1012,6 @@ bool eval_builtins(value_t *v) {
array_append(v2->quote, v1);
array_append(STACK, v2);
- } else if (strcmp(str, "clear") == 0) {
- for (int i = 0; i < STACK->size; i++) {
- value_free(array_pop(STACK));
- }
} else if (strcmp(str, "del") == 0) {
v2 = array_pop(STACK);
if (v2 == NULL) {
@@ -1071,6 +1067,33 @@ bool eval_builtins(value_t *v) {
eval(v1);
}
array_append(STACK, v1);
+ } else if (strcmp(str, "dip") == 0) {
+ v2 = array_pop(STACK);
+ if (v2 == NULL) {
+ value_free(v);
+ return eval_error();
+ }
+ v1 = array_pop(STACK);
+ if (v1 == NULL) {
+ value_free(v);
+ array_append(STACK, v2);
+ return eval_error();
+ }
+
+ if (v2->type == VQUOTE) {
+ array_append(EVAL_STACK, v);
+ array_append(EVAL_STACK, v1);
+ array_append(EVAL_STACK, v2);
+ for (int i = 0; i < v2->quote->size; i++) {
+ eval(value_copy(v2->quote->items[i]));
+ }
+ value_free(array_pop(EVAL_STACK));
+ value_free(array_pop(EVAL_STACK));
+ array_pop(EVAL_STACK);
+ } else {
+ eval(v1);
+ }
+ array_append(STACK, v1);
} else if (strcmp(str, "len") == 0) {
v1 = array_pop(STACK);
if (v1 == NULL) {
@@ -1182,7 +1205,7 @@ bool eval_builtins(value_t *v) {
array_append(STACK, v1);
return eval_error();
}
- char *val;
+ char *val = NULL;
size_t len;
FILE *fp = fopen(v1->str_word->value, "rb");
if (!fp) {