From e9a17cf8f83bf8b86b7a865098750544a54d11e5 Mon Sep 17 00:00:00 2001 From: ychenfo Date: Tue, 8 Mar 2022 21:54:27 +0800 Subject: [PATCH] nac3standalone: add test for min function --- nac3standalone/demo/demo.rs | 15 +++++++++ nac3standalone/demo/interpret_demo.py | 13 ++++++-- nac3standalone/demo/src/min_max_abs.py | 42 ++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 nac3standalone/demo/src/min_max_abs.py diff --git a/nac3standalone/demo/demo.rs b/nac3standalone/demo/demo.rs index d27dd839c..2a00eabde 100644 --- a/nac3standalone/demo/demo.rs +++ b/nac3standalone/demo/demo.rs @@ -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$*#@ "; diff --git a/nac3standalone/demo/interpret_demo.py b/nac3standalone/demo/interpret_demo.py index 3125410a0..6d61aadf7 100755 --- a/nac3standalone/demo/interpret_demo.py +++ b/nac3standalone/demo/interpret_demo.py @@ -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 diff --git a/nac3standalone/demo/src/min_max_abs.py b/nac3standalone/demo/src/min_max_abs.py new file mode 100644 index 000000000..fa99a39f0 --- /dev/null +++ b/nac3standalone/demo/src/min_max_abs.py @@ -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