aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-20 18:44:41 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-20 18:44:41 -0800
commit479df1ff2ab4a6cf8f7a42b9b6f4fa4c403590ff (patch)
tree790c13689d406c42cd416e6f0e77682fe71fd05d
parent8e843f97849f93147dddabbcf671a0877c5fa528 (diff)
vat works for words
-rw-r--r--src/builtins.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/builtins.c b/src/builtins.c
index 64de6b5..8d985fe 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -1012,6 +1012,7 @@ void qstack(value_t *v) {
}
void vat(value_t *v) {
+ value_t *retval;
value_t *v2 = array_pop(STACK);
if (v2 == NULL) {
eval_error("EMTPY STACK");
@@ -1040,7 +1041,7 @@ void vat(value_t *v) {
array_append(STACK, v2);
array_append(STACK, value_copy(v2->quote->items[(int)v1->int_float]));
value_free(v1);
- } else if (v2->type == VSTR) {
+ } else if (v2->type == VSTR || v2->type == VWORD) {
if (v2->str_word->length <= v1->int_float) {
array_append(STACK, v1);
array_append(STACK, v2);
@@ -1049,7 +1050,11 @@ void vat(value_t *v) {
}
char *a = (char[]){v2->str_word->value[(int)v1->int_float], '\0'};
string_t *s = init_string(a);
- value_t *retval = init_value(VSTR);
+ if (v2->type == VWORD) {
+ retval = init_value(VWORD);
+ } else {
+ retval = init_value(VSTR);
+ }
retval->str_word = s;
array_append(STACK, v2);
array_append(STACK, retval);