diff --git a/nac3standalone/demo/interpret_demo.py b/nac3standalone/demo/interpret_demo.py index 8784ce53..fa91ed3c 100755 --- a/nac3standalone/demo/interpret_demo.py +++ b/nac3standalone/demo/interpret_demo.py @@ -67,7 +67,7 @@ def _bool(x): def _float(x): if isinstance(x, np.ndarray): - return np.float_(x) + return np.float64(x) else: return float(x) @@ -111,6 +111,9 @@ def patch(module): def output_strln(x): print(x, end='') + def output_int32_list(x): + print([int(e) for e in x]) + def dbg_stack_address(_): return 0 @@ -126,11 +129,12 @@ def patch(module): return output_float elif name == "output_str": return output_strln + elif name == "output_int32_list": + return output_int32_list elif name in { "output_bool", "output_int32", "output_int64", - "output_int32_list", "output_uint32", "output_uint64", "output_strln", diff --git a/nac3standalone/demo/src/numeric_primitives.py b/nac3standalone/demo/src/numeric_primitives.py index 77a641f8..2c08c16d 100644 --- a/nac3standalone/demo/src/numeric_primitives.py +++ b/nac3standalone/demo/src/numeric_primitives.py @@ -29,10 +29,10 @@ def u32_max() -> uint32: return ~uint32(0) def i32_min() -> int32: - return int32(1 << 31) + return int32(-(1 << 31)) def i32_max() -> int32: - return int32(~(1 << 31)) + return int32((1 << 31)-1) def u64_min() -> uint64: return uint64(0) @@ -63,8 +63,9 @@ def test_conv_from_i32(): i32_max() ]: output_int64(int64(x)) - output_uint32(uint32(x)) - output_uint64(uint64(x)) + if x >= 0: + output_uint32(uint32(x)) + output_uint64(uint64(x)) output_float64(float(x)) def test_conv_from_u32(): @@ -108,7 +109,6 @@ def test_conv_from_u64(): def test_f64toi32(): for x in [ - float(i32_min()) - 1.0, float(i32_min()), float(i32_min()) + 1.0, -1.5, @@ -117,7 +117,6 @@ def test_f64toi32(): 1.5, float(i32_max()) - 1.0, float(i32_max()), - float(i32_max()) + 1.0 ]: output_int32(int32(x)) @@ -138,24 +137,17 @@ def test_f64toi64(): def test_f64tou32(): for x in [ - -1.5, - float(u32_min()) - 1.0, - -0.5, float(u32_min()), 0.5, float(u32_min()) + 1.0, 1.5, float(u32_max()) - 1.0, float(u32_max()), - float(u32_max()) + 1.0 ]: output_uint32(uint32(x)) def test_f64tou64(): for x in [ - -1.5, - float(u64_min()) - 1.0, - -0.5, float(u64_min()), 0.5, float(u64_min()) + 1.0, @@ -181,4 +173,4 @@ def run() -> int32: test_f64tou32() test_f64tou64() - return 0 \ No newline at end of file + return 0