nac3standalone: add test for min function

This commit is contained in:
ychenfo 2022-03-08 21:54:27 +08:00
parent adb5c69e67
commit e9a17cf8f8
3 changed files with 68 additions and 2 deletions

View File

@ -28,6 +28,21 @@ pub extern "C" fn output_int64(x: i64) {
println!("{}", x);
}
#[no_mangle]
pub extern "C" fn output_uint32(x: u32) {
println!("{}", x);
}
#[no_mangle]
pub extern "C" fn output_uint64(x: u64) {
println!("{}", x);
}
#[no_mangle]
pub extern "C" fn output_float64(x: f64) {
println!("{}", x);
}
#[no_mangle]
pub extern "C" fn output_asciiart(x: i32) {
let chars = " .,-:;i+hHM$*#@ ";

View File

@ -5,7 +5,7 @@ import importlib.util
import importlib.machinery
import pathlib
from numpy import int32, int64
from numpy import int32, int64, uint32, uint64
def patch(module):
@ -19,13 +19,22 @@ def patch(module):
name = fun.__name__
if name == "output_asciiart":
return output_asciiart
elif name in {"output_int32", "output_int64", "output_int32_list"}:
elif name in {
"output_int32",
"output_int64",
"output_int32_list",
"output_uint32",
"output_uint64",
"output_float64"
}:
return print
else:
raise NotImplementedError
module.int32 = int32
module.int64 = int64
module.uint32 = uint32
module.uint64 = uint64
module.extern = extern

View File

@ -0,0 +1,42 @@
@extern
def output_int32(x: int32):
...
@extern
def output_uint32(x: uint32):
...
@extern
def output_int64(x: int64):
...
@extern
def output_uint64(x: uint64):
...
@extern
def output_float64(x: float):
...
def run() -> int32:
output_int32(int32(min(True, False)))
output_int32(int32(min(True, True)))
output_int32(int32(min(False, False)))
output_int32(min(-12, 0))
output_int32(min(1, -3))
output_int32(min(2, 2))
output_int64(min(int64(-12), int64(0)))
output_int64(min(int64(1), int64(-3)))
output_int64(min(int64(2), int64(2)))
output_uint32(min(uint32(12), uint32(0)))
output_uint32(min(uint32(12), uint32(24)))
output_uint32(min(uint32(2), uint32(2)))
output_uint64(min(uint64(12), uint64(0)))
output_uint64(min(uint64(12), uint64(24)))
output_uint64(min(uint64(2), uint64(2)))
output_float64(min(-12.234, 3.23))
output_float64(min(0.1, 12.3))
output_float64(min(1.1, 1.1))
return 0