standalone: Add output_bool in demo library

This commit is contained in:
David Mak 2023-10-03 17:24:02 +08:00
parent 901e921e00
commit a79286113e
3 changed files with 21 additions and 6 deletions

View File

@ -1,3 +1,4 @@
#include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -11,6 +12,10 @@
#error "Unsupported platform - Platform is not 32-bit or 64-bit" #error "Unsupported platform - Platform is not 32-bit or 64-bit"
#endif #endif
void output_bool(const bool x) {
puts(x ? "True" : "False");
}
void output_int32(const int32_t x) { void output_int32(const int32_t x) {
printf("%d\n", x); printf("%d\n", x);
} }
@ -31,7 +36,7 @@ void output_float64(const double x) {
printf("%f\n", x); printf("%f\n", x);
} }
void output_asciiart(const int32_t x) { void output_asciiart(const int32_t x) {
const char* chars = " .,-:;i+hHM$*#@ "; static const char *chars = " .,-:;i+hHM$*#@ ";
if (x < 0) { if (x < 0) {
putchar('\n'); putchar('\n');
} else { } else {

View File

@ -58,6 +58,7 @@ def patch(module):
elif name == "output_float64": elif name == "output_float64":
return output_float return output_float
elif name in { elif name in {
"output_bool",
"output_int32", "output_int32",
"output_int64", "output_int64",
"output_int32_list", "output_int32_list",

View File

@ -1,3 +1,7 @@
@extern
def output_bool(x: bool):
...
@extern @extern
def output_int32(x: int32): def output_int32(x: int32):
... ...
@ -30,6 +34,10 @@ def output_asciiart(x: int32):
def output_str(x: str): def output_str(x: str):
... ...
def test_output_bool():
output_bool(True)
output_bool(False)
def test_output_int32(): def test_output_int32():
output_int32(-128) output_int32(-128)
@ -63,6 +71,7 @@ def test_output_str_family():
output_str("hello world") output_str("hello world")
def run() -> int32: def run() -> int32:
test_output_bool()
test_output_int32() test_output_int32()
test_output_int64() test_output_int64()
test_output_uint32() test_output_uint32()