forked from M-Labs/nac3
standalone: Rename output_str to output_strln and add output_str
output_str is for outputting strings without newline, and the newly introduced output_strln now has the old behavior of ending with a newline.
This commit is contained in:
parent
76defac462
commit
9238a5e86e
|
@ -79,6 +79,10 @@ void output_str(struct cslice *slice) {
|
|||
for (usize i = 0; i < slice->len; ++i) {
|
||||
putchar(data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
void output_strln(struct cslice *slice) {
|
||||
output_str(slice);
|
||||
putchar('\n');
|
||||
}
|
||||
|
||||
|
|
|
@ -107,6 +107,9 @@ def patch(module):
|
|||
def output_float(x):
|
||||
print("%f" % x)
|
||||
|
||||
def output_strln(x):
|
||||
print(x, end='')
|
||||
|
||||
def dbg_stack_address(_):
|
||||
return 0
|
||||
|
||||
|
@ -120,6 +123,8 @@ def patch(module):
|
|||
return output_asciiart
|
||||
elif name == "output_float64":
|
||||
return output_float
|
||||
elif name == "output_str":
|
||||
return output_strln
|
||||
elif name in {
|
||||
"output_bool",
|
||||
"output_int32",
|
||||
|
@ -127,7 +132,7 @@ def patch(module):
|
|||
"output_int32_list",
|
||||
"output_uint32",
|
||||
"output_uint64",
|
||||
"output_str",
|
||||
"output_strln",
|
||||
}:
|
||||
return print
|
||||
elif name == "dbg_stack_address":
|
||||
|
|
|
@ -7,7 +7,7 @@ def output_int64(x: int64):
|
|||
...
|
||||
|
||||
@extern
|
||||
def output_str(x: str):
|
||||
def output_strln(x: str):
|
||||
...
|
||||
|
||||
|
||||
|
@ -33,7 +33,7 @@ class A:
|
|||
|
||||
class Initless:
|
||||
def foo(self):
|
||||
output_str("hello")
|
||||
output_strln("hello")
|
||||
|
||||
def run() -> int32:
|
||||
a = A(10)
|
||||
|
|
|
@ -34,6 +34,10 @@ def output_asciiart(x: int32):
|
|||
def output_str(x: str):
|
||||
...
|
||||
|
||||
@extern
|
||||
def output_strln(x: str):
|
||||
...
|
||||
|
||||
def test_output_bool():
|
||||
output_bool(True)
|
||||
output_bool(False)
|
||||
|
@ -68,7 +72,8 @@ def test_output_int32_list():
|
|||
output_int32_list([0, 1, 3, 5, 10])
|
||||
|
||||
def test_output_str_family():
|
||||
output_str("hello world")
|
||||
output_str("hello")
|
||||
output_strln(" world")
|
||||
|
||||
def run() -> int32:
|
||||
test_output_bool()
|
||||
|
|
|
@ -23,11 +23,12 @@ def run() -> int32:
|
|||
output_int32(x)
|
||||
output_str(" * ")
|
||||
output_float64(n / x)
|
||||
output_str("\n")
|
||||
except: # Assume this is intended to catch x == 0
|
||||
break
|
||||
else:
|
||||
# loop fell through without finding a factor
|
||||
output_int32(n)
|
||||
output_str(" is a prime number")
|
||||
output_str(" is a prime number\n")
|
||||
|
||||
return 0
|
Loading…
Reference in New Issue