summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-03-14 15:23:25 -0400
committerLeo Tenenbaum <pommicket@gmail.com>2020-03-14 15:23:25 -0400
commit110725a5566ca0091e440df49a6e290c268c2b26 (patch)
tree3848b1fb77695d6060b1f2e13a1fc609e5ad4472
parent6b62b3caada6ce2859dfda24d6eb6fb273ca1a3f (diff)
discovered foreign varargs bug
-rw-r--r--eval.c2
-rw-r--r--main.c4
-rw-r--r--test.toc29
3 files changed, 5 insertions, 30 deletions
diff --git a/eval.c b/eval.c
index 5385771..feb6796 100644
--- a/eval.c
+++ b/eval.c
@@ -1126,7 +1126,7 @@ static Status eval_expr(Evaluator *ev, Expression *e, Value *v) {
eval_unary_op_nums_only(-);
} break;
case UNARY_NOT:
- v->boolv = !val_truthiness(*v, &e->unary.of->type);
+ v->boolv = !val_truthiness(of, &e->unary.of->type);
break;
case UNARY_DEL:
if (of_type->kind == TYPE_PTR)
diff --git a/main.c b/main.c
index 906b22a..a5c8c22 100644
--- a/main.c
+++ b/main.c
@@ -8,7 +8,9 @@
/*
TODO:
-#returns_code (function/struct body is a block, to be evaluated at compile time, which returns the actual statements -- you can use this for implementation of printf)
+fix foreign varargs
+user-generated errors
+#returns_code (struct body is a block, to be evaluated at compile time, which returns the actual statements)
- struct varargs
break
continue
diff --git a/test.toc b/test.toc
index 52d952e..56ba2e0 100644
--- a/test.toc
+++ b/test.toc
@@ -1,35 +1,8 @@
printf ::= #foreign("printf","libc.so.6") fn(#C &"const char", #C ..) #C int;
-tprintf_valid ::= fn(fmt :: []char, nargs: int) bool {
- if fmt[fmt.len-1] != '\0' {
- return false;
- }
- count := 0;
- for x, i := fmt {
- if x == '%' {
- if i == fmt.len-1 {
- count += 1;
- } elif fmt[i+1] != '%' {
- count += 1;
- } else {
- count -= 1;
- }
- }
- }
- count == nargs
-};
-
-
-tprintf ::= fn(fmt :: []char, args: ..) where tprintf_valid(fmt, args.len) {
- f := fmt;
- printf(&f[0], args);
-};
main ::= fn() {
- tprintf("Hello\n\0");
- return;
- x := 5;
- tprintf("%d %d%%\n\0", 3, 4);
+ printf("hey\n\0");
};
main(); \ No newline at end of file