2023-10-03 17:24:02 +08:00
|
|
|
#include <stdbool.h>
|
2023-09-29 15:15:18 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#if __SIZEOF_POINTER__ == 8
|
|
|
|
#define usize uint64_t
|
|
|
|
#elif __SIZEOF_POINTER__ == 4
|
|
|
|
#define usize uint32_t
|
|
|
|
#else
|
|
|
|
#error "Unsupported platform - Platform is not 32-bit or 64-bit"
|
|
|
|
#endif
|
|
|
|
|
2023-10-03 17:24:02 +08:00
|
|
|
void output_bool(const bool x) {
|
|
|
|
puts(x ? "True" : "False");
|
|
|
|
}
|
|
|
|
|
2023-09-29 15:15:18 +08:00
|
|
|
void output_int32(const int32_t x) {
|
|
|
|
printf("%d\n", x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_int64(const int64_t x) {
|
|
|
|
printf("%ld\n", x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_uint32(const uint32_t x) {
|
|
|
|
printf("%d\n", x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_uint64(const uint64_t x) {
|
|
|
|
printf("%ld\n", x);
|
|
|
|
}
|
|
|
|
|
|
|
|
void output_float64(const double x) {
|
|
|
|
printf("%f\n", x);
|
|
|
|
}
|
|
|
|
void output_asciiart(const int32_t x) {
|
2023-10-03 17:24:02 +08:00
|
|
|
static const char *chars = " .,-:;i+hHM$*#@ ";
|
2023-09-29 15:15:18 +08:00
|
|
|
if (x < 0) {
|
|
|
|
putchar('\n');
|
|
|
|
} else {
|
|
|
|
putchar(chars[x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct cslice {
|
2023-10-03 17:24:02 +08:00
|
|
|
const void *data;
|
2023-09-29 15:15:18 +08:00
|
|
|
usize len;
|
|
|
|
};
|
|
|
|
|
2023-10-03 17:24:02 +08:00
|
|
|
void output_int32_list(struct cslice *slice) {
|
|
|
|
const int32_t *data = (const int32_t *) slice->data;
|
2023-09-29 15:15:18 +08:00
|
|
|
|
|
|
|
putchar('[');
|
|
|
|
for (usize i = 0; i < slice->len; ++i) {
|
|
|
|
if (i == slice->len - 1) {
|
|
|
|
printf("%d", data[i]);
|
|
|
|
} else {
|
|
|
|
printf("%d, ", data[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
putchar(']');
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
2023-10-03 17:24:02 +08:00
|
|
|
void output_str(struct cslice *slice) {
|
|
|
|
const char *data = (const char *) slice->data;
|
2023-09-29 15:15:18 +08:00
|
|
|
|
|
|
|
for (usize i = 0; i < slice->len; ++i) {
|
|
|
|
putchar(data[i]);
|
|
|
|
}
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t __nac3_personality(uint32_t state, uint32_t exception_object, uint32_t context) {
|
|
|
|
printf("__nac3_personality(state: %u, exception_object: %u, context: %u\n", state, exception_object, context);
|
|
|
|
exit(101);
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t __nac3_raise(uint32_t state, uint32_t exception_object, uint32_t context) {
|
|
|
|
printf("__nac3_raise(state: %u, exception_object: %u, context: %u\n", state, exception_object, context);
|
|
|
|
exit(101);
|
|
|
|
__builtin_unreachable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void __nac3_end_catch(void) {}
|
|
|
|
|
|
|
|
extern int32_t run(void);
|
|
|
|
|
|
|
|
int main(void) {
|
|
|
|
run();
|
|
|
|
}
|