harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit be1498a04af7950f84dbe39e253cba50e6fe5555
parent f6d3b449c97b42579fa47f409db4ca20ac2ef45c
Author: Drew DeVault <sir@cmpwn.com>
Date:   Wed,  4 Aug 2021 13:59:49 +0200

temporary tests: flesh out abort

Signed-off-by: Drew DeVault <sir@cmpwn.com>

Diffstat:
Atests/906-if.ha | 17+++++++++++++++++
Mtests/rt.c | 12++++++++++++
Mtests/rt.ha | 4++--
3 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/tests/906-if.ha b/tests/906-if.ha @@ -0,0 +1,17 @@ +type coords = struct { x: int, y: int }; + +export fn main() int = { + let x = 10; + assert((if (false) x else 20) == 20); + + let x = if (true) 10 else abort(); + assert(x == 10); + + let x = if (true) coords { + x = 10, + y = 20, + } else abort(); + assert(x.x == 10); + + return 0; +}; diff --git a/tests/rt.c b/tests/rt.c @@ -1,4 +1,5 @@ #include <stdlib.h> +#include <unistd.h> void *c_memcpy(void *dest, const void *src, size_t n) { unsigned char *a = dest; @@ -8,3 +9,14 @@ void *c_memcpy(void *dest, const void *src, size_t n) { } return dest; } + +struct ha_str { + size_t len, cap; + char *str; +}; + +void c_abort(struct ha_str str) { + write(2, str.str, str.len); + write(2, "\n", 1); + abort(); +} diff --git a/tests/rt.ha b/tests/rt.ha @@ -1,5 +1,5 @@ -@symbol("abort") fn c_abort() void; -export @symbol("rt.abort") fn abort_() void = c_abort(); +fn c_abort(m: str) void; +export @symbol("rt.abort") fn abort_(m: str) void = c_abort(m); fn c_memcpy(x: *void, y: *void, z: size) *void; export @symbol("rt.memcpy") fn memcpy(x: *void, y: *void, z: size) *void = {