From 110725a5566ca0091e440df49a6e290c268c2b26 Mon Sep 17 00:00:00 2001 From: Leo Tenenbaum Date: Sat, 14 Mar 2020 15:23:25 -0400 Subject: discovered foreign varargs bug --- eval.c | 2 +- main.c | 4 +++- test.toc | 29 +---------------------------- 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 -- cgit v1.2.3