diff options
author | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-14 15:23:25 -0400 |
---|---|---|
committer | Leo Tenenbaum <pommicket@gmail.com> | 2020-03-14 15:23:25 -0400 |
commit | 110725a5566ca0091e440df49a6e290c268c2b26 (patch) | |
tree | 3848b1fb77695d6060b1f2e13a1fc609e5ad4472 | |
parent | 6b62b3caada6ce2859dfda24d6eb6fb273ca1a3f (diff) |
discovered foreign varargs bug
-rw-r--r-- | eval.c | 2 | ||||
-rw-r--r-- | main.c | 4 | ||||
-rw-r--r-- | test.toc | 29 |
3 files changed, 5 insertions, 30 deletions
@@ -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) @@ -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 @@ -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 |