forked from M-Labs/nac3
1
0
Fork 0

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 <stdio.h>
#include <stdlib.h>
@ -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]);

View File

@ -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",

View File

@ -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()