From a79286113ed848ba263150c4e1efeb8ff5843e38 Mon Sep 17 00:00:00 2001 From: David Mak Date: Tue, 3 Oct 2023 17:24:02 +0800 Subject: [PATCH] standalone: Add output_bool in demo library --- nac3standalone/demo/demo.c | 17 +++++++++++------ nac3standalone/demo/interpret_demo.py | 1 + nac3standalone/demo/src/demo_test.py | 9 +++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/nac3standalone/demo/demo.c b/nac3standalone/demo/demo.c index 4369b70..1c107fc 100644 --- a/nac3standalone/demo/demo.c +++ b/nac3standalone/demo/demo.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -11,6 +12,10 @@ #error "Unsupported platform - Platform is not 32-bit or 64-bit" #endif +void output_bool(const bool x) { + puts(x ? "True" : "False"); +} + void output_int32(const int32_t x) { printf("%d\n", x); } @@ -31,7 +36,7 @@ void output_float64(const double x) { printf("%f\n", x); } void output_asciiart(const int32_t x) { - const char* chars = " .,-:;i+hHM$*#@ "; + static const char *chars = " .,-:;i+hHM$*#@ "; if (x < 0) { putchar('\n'); } else { @@ -40,12 +45,12 @@ void output_asciiart(const int32_t x) { } struct cslice { - const void* data; + const void *data; usize len; }; -void output_int32_list(struct cslice* slice) { - const int32_t* data = (const int32_t*) slice->data; +void output_int32_list(struct cslice *slice) { + const int32_t *data = (const int32_t *) slice->data; putchar('['); for (usize i = 0; i < slice->len; ++i) { @@ -59,8 +64,8 @@ void output_int32_list(struct cslice* slice) { putchar('\n'); } -void output_str(struct cslice* slice) { - const char* data = (const char*) slice->data; +void output_str(struct cslice *slice) { + const char *data = (const char *) slice->data; for (usize i = 0; i < slice->len; ++i) { putchar(data[i]); diff --git a/nac3standalone/demo/interpret_demo.py b/nac3standalone/demo/interpret_demo.py index 69c0cf0..0a1007f 100755 --- a/nac3standalone/demo/interpret_demo.py +++ b/nac3standalone/demo/interpret_demo.py @@ -58,6 +58,7 @@ def patch(module): elif name == "output_float64": return output_float elif name in { + "output_bool", "output_int32", "output_int64", "output_int32_list", diff --git a/nac3standalone/demo/src/demo_test.py b/nac3standalone/demo/src/demo_test.py index f75f869..acc89bb 100644 --- a/nac3standalone/demo/src/demo_test.py +++ b/nac3standalone/demo/src/demo_test.py @@ -1,3 +1,7 @@ +@extern +def output_bool(x: bool): + ... + @extern def output_int32(x: int32): ... @@ -30,6 +34,10 @@ def output_asciiart(x: int32): def output_str(x: str): ... +def test_output_bool(): + output_bool(True) + output_bool(False) + def test_output_int32(): output_int32(-128) @@ -63,6 +71,7 @@ def test_output_str_family(): output_str("hello world") def run() -> int32: + test_output_bool() test_output_int32() test_output_int64() test_output_uint32()