diff --git a/ml-proto/src/spec/check.ml b/ml-proto/src/spec/check.ml index 92fe065651..ea184f1db3 100644 --- a/ml-proto/src/spec/check.ml +++ b/ml-proto/src/spec/check.ml @@ -179,14 +179,14 @@ let rec check_expr c ts e = | SetLocal (x, e1) -> check_expr c [local c x] e1; - check_type [] ts e.at + check_type [local c x] ts e.at | LoadGlobal x -> check_type [global c x] ts e.at | StoreGlobal (x, e1) -> check_expr c [global c x] e1; - check_type [] ts e.at + check_type [global c x] ts e.at | Load (memop, e1) -> check_memop memop e.at; @@ -197,7 +197,7 @@ let rec check_expr c ts e = check_memop memop e.at; check_expr c [Int32Type] e1; check_expr c [memop.ty] e2; - check_type [] ts e.at + check_type [memop.ty] ts e.at | Const v -> check_literal c ts v diff --git a/ml-proto/src/spec/eval.ml b/ml-proto/src/spec/eval.ml index 08931c8853..f1ffe59da2 100644 --- a/ml-proto/src/spec/eval.ml +++ b/ml-proto/src/spec/eval.ml @@ -152,7 +152,7 @@ let rec eval_expr c e = | SetLocal (x, e1) -> let v1 = unary (eval_expr c e1) e1.at in local c x := v1; - [] + [v1] | LoadGlobal x -> [!(global c x)] @@ -160,7 +160,7 @@ let rec eval_expr c e = | StoreGlobal (x, e1) -> let v1 = unary (eval_expr c e1) e1.at in global c x := v1; - [] + [v1] | Load ({mem; ty; _}, e1) -> let v1 = unary (eval_expr c e1) e1.at in @@ -172,7 +172,7 @@ let rec eval_expr c e = let v2 = unary (eval_expr c e2) e2.at in (try Memory.store c.modul.memory (Memory.address_of_value v1) mem v2 with exn -> memory_error e.at exn); - [] + [v2] | Const v -> [v.it] diff --git a/ml-proto/test/globals.wasm b/ml-proto/test/globals.wasm new file mode 100644 index 0000000000..ced0e645f7 --- /dev/null +++ b/ml-proto/test/globals.wasm @@ -0,0 +1,44 @@ +(module + (global $rx0 i32) + (global $rx1 i32) + + (func $gx0 (load_global $rx0)) + (func $sx0 (param i32) (store_global $rx0 (get_local 0))) + + (func $gx1 (load_global $rx1)) + (func $sx1 (param i32) (store_global $rx1 (get_local 0))) + + (func $storeandload (param i32) + (call $sx0 (get_local 0)) + (call $gx0)) + + (func $lssg (param i32) (result i32) + (local $l1 i32) + (local $l2 i32) + + (set_local $l1 (set_local $l2 (get_local 0)))) + + (func $gssg (param i32) (result i32) + (store_global $rx0 (store_global $rx1 (get_local 0)))) + + (export "gx0" $gx0) + (export "sx0" $sx0) + + (export "gx1" $gx1) + (export "sx1" $sx1) + + (export "localsetsetget" $lssg) + (export "globalsetsetget" $gssg) + + (export "storeandload" $storeandload) +) + +(assert_eq (invoke "storeandload" (i32.const 25)) (i32.const 25)) +(assert_eq (invoke "sx0" (i32.const 10)) (i32.const 10)) +(assert_eq (invoke "gx0") (i32.const 10)) + +(assert_eq (invoke "sx1" (i32.const 12)) (i32.const 12)) +(assert_eq (invoke "gx1") (i32.const 12)) +(assert_eq (invoke "gx0") (i32.const 10)) +(assert_eq (invoke "localsetsetget" (i32.const 13)) (i32.const 13)) +(assert_eq (invoke "globalsetsetget" (i32.const 14)) (i32.const 14)) diff --git a/ml-proto/test/memory_store_return.wasm b/ml-proto/test/memory_store_return.wasm new file mode 100644 index 0000000000..488081094a --- /dev/null +++ b/ml-proto/test/memory_store_return.wasm @@ -0,0 +1,11 @@ +(module + (memory 1024) + + (func $store-i32 (param $v i32) (result i32) + (i32.store/i32 (i32.const 4) (get_local $v))) + + (export "store-i32" $store-i32)) + +(assert_eq (invoke "store-i32" (i32.const 42)) (i32.const 42)) + +