summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler.c81
-rw-r--r--tests/test_conditional_4.tnsl16
-rw-r--r--tests/test_conditional_5.tnsl20
-rw-r--r--tests/test_conditional_6.tnsl8
4 files changed, 94 insertions, 31 deletions
diff --git a/compiler.c b/compiler.c
index da2bd70..ef86ae7 100644
--- a/compiler.c
+++ b/compiler.c
@@ -1725,10 +1725,20 @@ void var_op_not(CompData *out, Variable *base) {
}
char *not_store = _var_get_store(out, base);
-
- vect_push_string(&out->text, "\tnot ");
- vect_push_free_string(&out->text, not_store);
- vect_push_string(&out->text, " ; Complete not\n");
+ if (base->type != NULL && strcmp(base->type->name, "bool") == 0) {
+ // boolean not
+ vect_push_string(&out->text, "\tnot ");
+ vect_push_string(&out->text, not_store);
+ vect_push_string(&out->text, "\n");
+ vect_push_string(&out->text, "\tand ");
+ vect_push_free_string(&out->text, not_store);
+ vect_push_string(&out->text, ", 1 ; Complete and\n");
+ } else {
+ // normal not
+ vect_push_string(&out->text, "\tnot ");
+ vect_push_free_string(&out->text, not_store);
+ vect_push_string(&out->text, " ; Complete not\n");
+ }
}
// test base with itself
@@ -1749,7 +1759,7 @@ void var_op_test(CompData *out, Variable *base) {
vect_push_free_string(&out->text, test_store);
vect_push_string(&out->text, ", ");
vect_push_free_string(&out->text, test_from);
- vect_push_string(&out->text, " ; Complete not\n");
+ vect_push_string(&out->text, " ; Complete test\n");
}
// bit shift base left by "bsl"
@@ -1918,26 +1928,6 @@ void var_op_ne(CompData *out, Variable *base, Variable *cmp) {
*base = tmp;
}
-// Boolean and
-void var_op_band(CompData *out, Scope *s) {
- // Just parsed the left side, short circuit if zero
- vect_push_string(&out->text, "\tjz ");
- vect_push_free_string(&out->text, scope_gen_bool_label(s));
- vect_push_string(&out->text, "false ; bool and\n\n");
-}
-
-// Boolean or
-void var_op_bor(CompData *out, Scope *s) {
- // Just parsed the left side, short circuit if zero
- vect_push_string(&out->text, "\tjnz ");
- vect_push_free_string(&out->text, scope_gen_bool_label(s));
- vect_push_string(&out->text, "true ; bool or\n\n");
-}
-
-void var_op_bxor(CompData *out, Variable *lhs, Variable *rhs) {
- // Nothing for now
-}
-
void var_op_inc(CompData *out, Variable *lhs) {
if (lhs->location == LOC_LITL) {
lhs->offset++;
@@ -4808,6 +4798,7 @@ Variable _eval_literal(Scope *s, CompData *data, Vector *tokens, size_t literal)
vect_push_string(&data->text, "\ttest rax, rax ; literal bool\n\n");
out.offset = 0;
}
+ out.location = LOC_LITL;
} else {
out.location = LOC_LITL;
if (t->data[0] == '\'')
@@ -4843,9 +4834,11 @@ Variable _eval(Scope *s, CompData *data, Vector *tokens, size_t start, size_t en
} else {
i = dcl;
}
- } else if (t->type == TT_AUGMENT && op_order(t) > op) {
- op = op_order(t);
- op_pos = i;
+ } else if (t->type == TT_AUGMENT) {
+ if (op_order(t) > op || (op_order(t) == op && op == 9)) {
+ op = op_order(t);
+ op_pos = i;
+ }
}
}
@@ -4919,9 +4912,35 @@ Variable _eval(Scope *s, CompData *data, Vector *tokens, size_t start, size_t en
// if boolean, eval left to right, not right to left
if (op == 9) {
- printf("ERROR: TO IMPL BOOL\n");
- p2_error = true;
- return out;
+ Variable lhs = _eval(s, data, tokens, start, op_pos);
+
+ char chk = op_token->data[0];
+ if (op_token->data[0] == '!') {
+ printf("WARN: TO IMPL BOOLEAN NOT\n");
+ chk = op_token->data[1];
+ }
+
+ Variable rhs;
+ if (chk == '&') {
+ vect_push_string(&data->text, "\tjz ");
+ vect_push_free_string(&data->text, scope_gen_bool_label(s));
+ vect_push_string(&data->text, " ; boolean and\n");
+ rhs = _eval(s, data, tokens, op_pos + 1, end);
+ } else if (chk == '|') {
+ vect_push_string(&data->text, "\tjnz ");
+ vect_push_free_string(&data->text, scope_gen_bool_label(s));
+ vect_push_string(&data->text, " ; boolean or\n");
+ rhs = _eval(s, data, tokens, op_pos + 1, end);
+ } else if (chk == '^') {
+
+ }
+
+ vect_push_free_string(&data->text, scope_gen_bool_label(s));
+ vect_push_string(&data->text, ": ; boolean end\n");
+ scope_adv_bool_label(s);
+
+ var_end(&rhs);
+ return lhs;
}
if (op_pos == start) {
diff --git a/tests/test_conditional_4.tnsl b/tests/test_conditional_4.tnsl
new file mode 100644
index 0000000..d31944a
--- /dev/null
+++ b/tests/test_conditional_4.tnsl
@@ -0,0 +1,16 @@
+
+/; main [int]
+ int a = 0
+ int b = 69
+ int c = 70
+
+ /; if (a < b && b > c)
+ return c
+ ;; else if (b > c && a < b)
+ return a
+ ;; else if (a > b && b > c)
+ return 1
+ ;/
+
+ return b
+;/
diff --git a/tests/test_conditional_5.tnsl b/tests/test_conditional_5.tnsl
new file mode 100644
index 0000000..2c68c17
--- /dev/null
+++ b/tests/test_conditional_5.tnsl
@@ -0,0 +1,20 @@
+
+/; main [int]
+
+ /; if (true && false)
+ return 0
+ ;; else if (false && true)
+ return 1
+ ;; else if (false && false)
+ return 2
+ ;/
+
+ /; if (false || false)
+ return 3
+ ;; else if (true || false)
+ return 69
+ ;/
+
+ return 4
+
+;/
diff --git a/tests/test_conditional_6.tnsl b/tests/test_conditional_6.tnsl
new file mode 100644
index 0000000..051b0f3
--- /dev/null
+++ b/tests/test_conditional_6.tnsl
@@ -0,0 +1,8 @@
+/; main [int]
+ bool a = false
+ /; if (false || !a && true)
+ return 69
+ ;/
+
+ return 0
+;/