aboutsummaryrefslogtreecommitdiff
path: root/parser.c
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 /parser.c
parent5907934e467bf28291901ed3595125ef1ed724d9 (diff)
forgot what i did lol
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c33
1 files changed, 28 insertions, 5 deletions
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) {