Compare commits
2 Commits
ea2ab0ef7c
...
6edad72f4a
Author | SHA1 | Date |
---|---|---|
David Mak | 6edad72f4a | |
David Mak | cdc893d252 |
|
@ -5,91 +5,91 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if __SIZEOF_POINTER__ == 8
|
#if __SIZEOF_POINTER__ == 8
|
||||||
#define usize uint64_t
|
#define usize uint64_t
|
||||||
#elif __SIZEOF_POINTER__ == 4
|
#elif __SIZEOF_POINTER__ == 4
|
||||||
#define usize uint32_t
|
#define usize uint32_t
|
||||||
#else
|
#else
|
||||||
#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(bool x) {
|
void output_bool(bool x) {
|
||||||
puts(x ? "True" : "False");
|
puts(x ? "True" : "False");
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_int32(int32_t x) {
|
void output_int32(int32_t x) {
|
||||||
printf("%d\n", x);
|
printf("%d\n", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_int64(int64_t x) {
|
void output_int64(int64_t x) {
|
||||||
printf("%ld\n", x);
|
printf("%ld\n", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_uint32(uint32_t x) {
|
void output_uint32(uint32_t x) {
|
||||||
printf("%d\n", x);
|
printf("%d\n", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_uint64(uint64_t x) {
|
void output_uint64(uint64_t x) {
|
||||||
printf("%ld\n", x);
|
printf("%ld\n", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_float64(double x) {
|
void output_float64(double x) {
|
||||||
printf("%f\n", x);
|
printf("%f\n", x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_asciiart(int32_t x) {
|
void output_asciiart(int32_t x) {
|
||||||
static const char *chars = " .,-:;i+hHM$*#@ ";
|
static const char *chars = " .,-:;i+hHM$*#@ ";
|
||||||
if (x < 0) {
|
if (x < 0) {
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
} else {
|
} else {
|
||||||
putchar(chars[x]);
|
putchar(chars[x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct cslice {
|
struct cslice {
|
||||||
void *data;
|
void *data;
|
||||||
usize len;
|
usize len;
|
||||||
};
|
};
|
||||||
|
|
||||||
void output_int32_list(struct cslice *slice) {
|
void output_int32_list(struct cslice *slice) {
|
||||||
const int32_t *data = (int32_t *) slice->data;
|
const int32_t *data = (int32_t *) slice->data;
|
||||||
|
|
||||||
putchar('[');
|
putchar('[');
|
||||||
for (usize i = 0; i < slice->len; ++i) {
|
for (usize i = 0; i < slice->len; ++i) {
|
||||||
if (i == slice->len - 1) {
|
if (i == slice->len - 1) {
|
||||||
printf("%d", data[i]);
|
printf("%d", data[i]);
|
||||||
} else {
|
} else {
|
||||||
printf("%d, ", data[i]);
|
printf("%d, ", data[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
putchar(']');
|
||||||
putchar(']');
|
putchar('\n');
|
||||||
putchar('\n');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void output_str(struct cslice *slice) {
|
void output_str(struct cslice *slice) {
|
||||||
const char *data = (const char *) slice->data;
|
const char *data = (const char *) slice->data;
|
||||||
|
|
||||||
for (usize i = 0; i < slice->len; ++i) {
|
for (usize i = 0; i < slice->len; ++i) {
|
||||||
putchar(data[i]);
|
putchar(data[i]);
|
||||||
}
|
}
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t dbg_stack_address(__attribute__((unused)) struct cslice *slice) {
|
uint64_t dbg_stack_address(__attribute__((unused)) struct cslice *slice) {
|
||||||
int i;
|
int i;
|
||||||
void *ptr = (void *) &i;
|
void *ptr = (void *) &i;
|
||||||
return (uintptr_t) ptr;
|
return (uintptr_t) ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t __nac3_personality(uint32_t state, uint32_t exception_object, uint32_t context) {
|
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);
|
printf("__nac3_personality(state: %u, exception_object: %u, context: %u\n", state, exception_object, context);
|
||||||
exit(101);
|
exit(101);
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t __nac3_raise(uint32_t state, uint32_t exception_object, uint32_t context) {
|
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);
|
printf("__nac3_raise(state: %u, exception_object: %u, context: %u\n", state, exception_object, context);
|
||||||
exit(101);
|
exit(101);
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|
||||||
void __nac3_end_catch(void) {}
|
void __nac3_end_catch(void) {}
|
||||||
|
@ -97,5 +97,5 @@ void __nac3_end_catch(void) {}
|
||||||
extern int32_t run(void);
|
extern int32_t run(void);
|
||||||
|
|
||||||
int main(void) {
|
int main(void) {
|
||||||
run();
|
run();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,29 +2,29 @@
|
||||||
# Tests whether all boolean variables (expressed as i8s) are lowered into i1s before used in branching instruction (`br`)
|
# Tests whether all boolean variables (expressed as i8s) are lowered into i1s before used in branching instruction (`br`)
|
||||||
|
|
||||||
def bfunc(b: bool) -> bool:
|
def bfunc(b: bool) -> bool:
|
||||||
return not b
|
return not b
|
||||||
|
|
||||||
def run() -> int32:
|
def run() -> int32:
|
||||||
b1 = True
|
b1 = True
|
||||||
b2 = False
|
b2 = False
|
||||||
|
|
||||||
if b1:
|
if b1:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if not b2:
|
if not b2:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
while b2:
|
while b2:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
l = [i for i in range(10) if b2]
|
l = [i for i in range(10) if b2]
|
||||||
|
|
||||||
b_and = True and False
|
b_and = True and False
|
||||||
b_or = True or False
|
b_or = True or False
|
||||||
|
|
||||||
b_and = b1 and b2
|
b_and = b1 and b2
|
||||||
b_or = b1 or b2
|
b_or = b1 or b2
|
||||||
|
|
||||||
bfunc(b1)
|
bfunc(b1)
|
||||||
|
|
||||||
return 0
|
return 0
|
|
@ -1,8 +1,8 @@
|
||||||
def f():
|
def f():
|
||||||
return
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
def run() -> int32:
|
def run() -> int32:
|
||||||
f()
|
f()
|
||||||
|
|
||||||
return 0
|
return 0
|
|
@ -1,83 +1,83 @@
|
||||||
@extern
|
@extern
|
||||||
def output_bool(x: bool):
|
def output_bool(x: bool):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_int32(x: int32):
|
def output_int32(x: int32):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_int64(x: int64):
|
def output_int64(x: int64):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_uint32(x: uint32):
|
def output_uint32(x: uint32):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_uint64(x: uint64):
|
def output_uint64(x: uint64):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_float64(x: float):
|
def output_float64(x: float):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_int32_list(x: list[int32]):
|
def output_int32_list(x: list[int32]):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_asciiart(x: int32):
|
def output_asciiart(x: int32):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_str(x: str):
|
def output_str(x: str):
|
||||||
...
|
...
|
||||||
|
|
||||||
def test_output_bool():
|
def test_output_bool():
|
||||||
output_bool(True)
|
output_bool(True)
|
||||||
output_bool(False)
|
output_bool(False)
|
||||||
|
|
||||||
def test_output_int32():
|
def test_output_int32():
|
||||||
output_int32(-128)
|
output_int32(-128)
|
||||||
|
|
||||||
def test_output_int64():
|
def test_output_int64():
|
||||||
output_int64(int64(-256))
|
output_int64(int64(-256))
|
||||||
|
|
||||||
def test_output_uint32():
|
def test_output_uint32():
|
||||||
output_uint32(uint32(128))
|
output_uint32(uint32(128))
|
||||||
|
|
||||||
def test_output_uint64():
|
def test_output_uint64():
|
||||||
output_uint64(uint64(256))
|
output_uint64(uint64(256))
|
||||||
|
|
||||||
def test_output_float64():
|
def test_output_float64():
|
||||||
output_float64(0.0)
|
output_float64(0.0)
|
||||||
output_float64(1.0)
|
output_float64(1.0)
|
||||||
output_float64(-1.0)
|
output_float64(-1.0)
|
||||||
output_float64(128.0)
|
output_float64(128.0)
|
||||||
output_float64(-128.0)
|
output_float64(-128.0)
|
||||||
output_float64(16.25)
|
output_float64(16.25)
|
||||||
output_float64(-16.25)
|
output_float64(-16.25)
|
||||||
|
|
||||||
def test_output_asciiart():
|
def test_output_asciiart():
|
||||||
for i in range(17):
|
for i in range(17):
|
||||||
output_asciiart(i)
|
output_asciiart(i)
|
||||||
output_asciiart(0)
|
output_asciiart(0)
|
||||||
|
|
||||||
def test_output_int32_list():
|
def test_output_int32_list():
|
||||||
output_int32_list([0, 1, 3, 5, 10])
|
output_int32_list([0, 1, 3, 5, 10])
|
||||||
|
|
||||||
def test_output_str_family():
|
def test_output_str_family():
|
||||||
output_str("hello world")
|
output_str("hello world")
|
||||||
|
|
||||||
def run() -> int32:
|
def run() -> int32:
|
||||||
test_output_bool()
|
test_output_bool()
|
||||||
test_output_int32()
|
test_output_int32()
|
||||||
test_output_int64()
|
test_output_int64()
|
||||||
test_output_uint32()
|
test_output_uint32()
|
||||||
test_output_uint64()
|
test_output_uint64()
|
||||||
test_output_float64()
|
test_output_float64()
|
||||||
test_output_asciiart()
|
test_output_asciiart()
|
||||||
test_output_int32_list()
|
test_output_int32_list()
|
||||||
test_output_str_family()
|
test_output_str_family()
|
||||||
return 0
|
return 0
|
|
@ -1,17 +1,17 @@
|
||||||
@extern
|
@extern
|
||||||
def output_int32(x: int32):
|
def output_int32(x: int32):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_int32_list(x: list[int32]):
|
def output_int32_list(x: list[int32]):
|
||||||
...
|
...
|
||||||
|
|
||||||
def run() -> int32:
|
def run() -> int32:
|
||||||
bl = [True, False]
|
bl = [True, False]
|
||||||
|
|
||||||
bl1 = bl[:]
|
bl1 = bl[:]
|
||||||
bl1[1:] = [True]
|
bl1[1:] = [True]
|
||||||
output_int32_list([int32(b) for b in bl1])
|
output_int32_list([int32(b) for b in bl1])
|
||||||
output_int32_list([int32(b) for b in bl1])
|
output_int32_list([int32(b) for b in bl1])
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
|
|
|
@ -3,31 +3,31 @@
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_int32(x: int32):
|
def output_int32(x: int32):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_float64(x: float):
|
def output_float64(x: float):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def output_str(x: str):
|
def output_str(x: str):
|
||||||
...
|
...
|
||||||
|
|
||||||
def run() -> int32:
|
def run() -> int32:
|
||||||
for n in range(2, 10):
|
for n in range(2, 10):
|
||||||
for x in range(2, n):
|
for x in range(2, n):
|
||||||
try:
|
try:
|
||||||
if n % x == 0:
|
if n % x == 0:
|
||||||
output_int32(n)
|
output_int32(n)
|
||||||
output_str(" equals ")
|
output_str(" equals ")
|
||||||
output_int32(x)
|
output_int32(x)
|
||||||
output_str(" * ")
|
output_str(" * ")
|
||||||
output_float64(n / x)
|
output_float64(n / x)
|
||||||
except: # Assume this is intended to catch x == 0
|
except: # Assume this is intended to catch x == 0
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
# loop fell through without finding a factor
|
# loop fell through without finding a factor
|
||||||
output_int32(n)
|
output_int32(n)
|
||||||
output_str(" is a prime number")
|
output_str(" is a prime number")
|
||||||
|
|
||||||
return 0
|
return 0
|
|
@ -1,15 +1,15 @@
|
||||||
@extern
|
@extern
|
||||||
def output_bool(x: bool):
|
def output_bool(x: bool):
|
||||||
...
|
...
|
||||||
|
|
||||||
@extern
|
@extern
|
||||||
def dbg_stack_address(x: str) -> uint64:
|
def dbg_stack_address(x: str) -> uint64:
|
||||||
...
|
...
|
||||||
|
|
||||||
def run() -> int32:
|
def run() -> int32:
|
||||||
a = dbg_stack_address("a")
|
a = dbg_stack_address("a")
|
||||||
b = dbg_stack_address("b")
|
b = dbg_stack_address("b")
|
||||||
|
|
||||||
output_bool(a == b)
|
output_bool(a == b)
|
||||||
|
|
||||||
return 0
|
return 0
|
Loading…
Reference in New Issue