From 25d2de67f7fb00f7e382bf8dddce3f8efbe1df67 Mon Sep 17 00:00:00 2001 From: David Mak Date: Mon, 8 Jul 2024 14:40:22 +0800 Subject: [PATCH] standalone: Add output_range and tests --- nac3standalone/demo/demo.c | 12 ++++++++++++ nac3standalone/demo/src/demo_test.py | 14 ++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/nac3standalone/demo/demo.c b/nac3standalone/demo/demo.c index 9fc14893e..28c643386 100644 --- a/nac3standalone/demo/demo.c +++ b/nac3standalone/demo/demo.c @@ -44,6 +44,18 @@ void output_float64(double x) { } } +void output_range(int32_t range[3]) { + printf("range("); + if (range[0] != 0) { + printf("%d, ", range[0]); + } + printf("%d", range[1]); + if (range[2] != 1) { + printf(", %d", range[2]); + } + puts(")"); +} + void output_asciiart(int32_t x) { static const char *chars = " .,-:;i+hHM$*#@ "; if (x < 0) { diff --git a/nac3standalone/demo/src/demo_test.py b/nac3standalone/demo/src/demo_test.py index d31aab0ba..951bbafd0 100644 --- a/nac3standalone/demo/src/demo_test.py +++ b/nac3standalone/demo/src/demo_test.py @@ -22,6 +22,10 @@ def output_uint64(x: uint64): def output_float64(x: float): ... +@extern +def output_range(x: range): + ... + @extern def output_int32_list(x: list[int32]): ... @@ -63,6 +67,15 @@ def test_output_float64(): output_float64(16.25) output_float64(-16.25) +def test_output_range(): + r = range(1, 100, 5) + output_int32(r.start) + output_int32(r.stop) + output_int32(r.step) + output_range(range(10)) + output_range(range(1, 10)) + output_range(range(1, 10, 2)) + def test_output_asciiart(): for i in range(17): output_asciiart(i) @@ -82,6 +95,7 @@ def run() -> int32: test_output_uint32() test_output_uint64() test_output_float64() + test_output_range() test_output_asciiart() test_output_int32_list() test_output_str_family()