aboutsummaryrefslogtreecommitdiff
path: root/parser.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-05 16:26:41 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-05 16:26:41 -0800
commita9be28f347585c787215ffb2c3b43fba93cacb0e (patch)
tree5d72d054e09e97d59398c103e9ecdd43db67ebdb /parser.c
parent966905fba74407dfc4086674ecf199f20e2683fb (diff)
discard
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c37
1 files changed, 37 insertions, 0 deletions
diff --git a/parser.c b/parser.c
index 0ea903a..5dd21f1 100644
--- a/parser.c
+++ b/parser.c
@@ -691,6 +691,35 @@ bool eval_builtins(value_t *v) {
array_append(STACK, retval);
value_free(v1);
value_free(v2);
+ } else if (strcmp(str, "!=") == 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();
+ }
+
+ retval = init_value(VINT);
+ if (v1->type == VSTR && v2->type == VSTR ||
+ v1->type == VWORD && v2->type == VWORD) {
+ retval->int_float = strcmp(v1->str_word->value, v2->str_word->value) != 0;
+ } else if ((v1->type == VINT || v1->type == VFLOAT) &&
+ (v2->type == VINT || v2->type == VFLOAT)) {
+ retval->int_float = v1->int_float != v2->int_float;
+ } else {
+ value_free(v);
+ array_append(STACK, v1);
+ array_append(STACK, v2);
+ return eval_error();
+ }
+ array_append(STACK, retval);
+ value_free(v1);
+ value_free(v2);
} else if (strcmp(str, "if") == 0) {
v3 = array_pop(STACK);
if (v3 == NULL) {
@@ -791,6 +820,14 @@ bool eval_builtins(value_t *v) {
retval = value_copy(v1);
array_append(STACK, v1);
array_append(STACK, retval);
+ } else if (strcmp(str, "discard") == 0) {
+ v1 = array_pop(STACK);
+ if (v1 == NULL) {
+ value_free(v);
+ return eval_error();
+ }
+
+ value_free(v1);
} else if (strcmp(str, "type") == 0) {
v1 = array_pop(STACK);
if (v1 == NULL) {