From 8e514ab66af94c937957a05bb09a8b995b07e4be Mon Sep 17 00:00:00 2001 From: Lars T Hansen Date: Mon, 9 Apr 2018 13:11:29 +0200 Subject: [PATCH] Factor reference tests for the proposal to avoid confusion --- test/core/globals.wast | 22 ++++++++++++--- test/core/globals_proposed.wast | 5 ++++ test/core/linking.wast | 33 ----------------------- test/core/linking_proposed.wast | 48 +++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 test/core/globals_proposed.wast create mode 100644 test/core/linking_proposed.wast diff --git a/test/core/globals.wast b/test/core/globals.wast index fd27b06..4dcc2c6 100644 --- a/test/core/globals.wast +++ b/test/core/globals.wast @@ -51,9 +51,25 @@ "global is immutable" ) -;; mutable globals can be exported -(module (global (mut f32) (f32.const 0)) (export "a" (global 0))) -(module (global (export "a") (mut f32) (f32.const 0))) +;;(assert_invalid +;; (module (import "m" "a" (global (mut i32)))) +;; "mutable globals cannot be imported" +;;) +;; +;;(assert_invalid +;; (module (global (import "m" "a") (mut i32))) +;; "mutable globals cannot be imported" +;;) +;; +;;(assert_invalid +;; (module (global (mut f32) (f32.const 0)) (export "a" (global 0))) +;; "mutable globals cannot be exported" +;;) +;; +;;(assert_invalid +;; (module (global (export "a") (mut f32) (f32.const 0))) +;; "mutable globals cannot be exported" +;;) (assert_invalid (module (global f32 (f32.neg (f32.const 0)))) diff --git a/test/core/globals_proposed.wast b/test/core/globals_proposed.wast new file mode 100644 index 0000000..43c9bad --- /dev/null +++ b/test/core/globals_proposed.wast @@ -0,0 +1,5 @@ +;; Test exportable mutable globals + +;; mutable globals can be exported +(module (global (mut f32) (f32.const 0)) (export "a" (global 0))) +(module (global (export "a") (mut f32) (f32.const 0))) diff --git a/test/core/linking.wast b/test/core/linking.wast index a68bdc0..73fbb93 100644 --- a/test/core/linking.wast +++ b/test/core/linking.wast @@ -39,29 +39,16 @@ (module $Mg (global $glob (export "glob") i32 (i32.const 42)) (func (export "get") (result i32) (get_global $glob)) - - ;; export mutable globals - (global $mut_glob (export "mut_glob") (mut i32) (i32.const 142)) - (func (export "get_mut") (result i32) (get_global $mut_glob)) - (func (export "set_mut") (param i32) (set_global $mut_glob (get_local 0))) ) (register "Mg" $Mg) (module $Ng (global $x (import "Mg" "glob") i32) - (global $mut_glob (import "Mg" "mut_glob") (mut i32)) (func $f (import "Mg" "get") (result i32)) - (func $get_mut (import "Mg" "get_mut") (result i32)) - (func $set_mut (import "Mg" "set_mut") (param i32)) - (export "Mg.glob" (global $x)) (export "Mg.get" (func $f)) (global $glob (export "glob") i32 (i32.const 43)) (func (export "get") (result i32) (get_global $glob)) - - (export "Mg.mut_glob" (global $mut_glob)) - (export "Mg.get_mut" (func $get_mut)) - (export "Mg.set_mut" (func $set_mut)) ) (assert_return (get $Mg "glob") (i32.const 42)) @@ -71,26 +58,6 @@ (assert_return (invoke $Ng "Mg.get") (i32.const 42)) (assert_return (invoke $Ng "get") (i32.const 43)) -(assert_return (get $Mg "mut_glob") (i32.const 142)) -(assert_return (get $Ng "Mg.mut_glob") (i32.const 142)) -(assert_return (invoke $Mg "get_mut") (i32.const 142)) -(assert_return (invoke $Ng "Mg.get_mut") (i32.const 142)) - -(assert_return (invoke $Mg "set_mut" (i32.const 241))) -(assert_return (get $Mg "mut_glob") (i32.const 241)) -(assert_return (get $Ng "Mg.mut_glob") (i32.const 241)) -(assert_return (invoke $Mg "get_mut") (i32.const 241)) -(assert_return (invoke $Ng "Mg.get_mut") (i32.const 241)) - - -(assert_unlinkable - (module (import "Mg" "mut_glob" (global i32))) - "incompatible import type" -) -(assert_unlinkable - (module (import "Mg" "glob" (global (mut i32)))) - "incompatible import type" -) ;; Tables diff --git a/test/core/linking_proposed.wast b/test/core/linking_proposed.wast new file mode 100644 index 0000000..bb1ea5d --- /dev/null +++ b/test/core/linking_proposed.wast @@ -0,0 +1,48 @@ +(module $Mg + (global $glob (export "glob") i32 (i32.const 42)) + (func (export "get") (result i32) (get_global $glob)) + + ;; export mutable globals + (global $mut_glob (export "mut_glob") (mut i32) (i32.const 142)) + (func (export "get_mut") (result i32) (get_global $mut_glob)) + (func (export "set_mut") (param i32) (set_global $mut_glob (get_local 0))) +) +(register "Mg" $Mg) + +(module $Ng + (global $x (import "Mg" "glob") i32) + (global $mut_glob (import "Mg" "mut_glob") (mut i32)) + (func $f (import "Mg" "get") (result i32)) + (func $get_mut (import "Mg" "get_mut") (result i32)) + (func $set_mut (import "Mg" "set_mut") (param i32)) + + (export "Mg.glob" (global $x)) + (export "Mg.get" (func $f)) + (global $glob (export "glob") i32 (i32.const 43)) + (func (export "get") (result i32) (get_global $glob)) + + (export "Mg.mut_glob" (global $mut_glob)) + (export "Mg.get_mut" (func $get_mut)) + (export "Mg.set_mut" (func $set_mut)) +) + +(assert_return (get $Mg "mut_glob") (i32.const 142)) +(assert_return (get $Ng "Mg.mut_glob") (i32.const 142)) +(assert_return (invoke $Mg "get_mut") (i32.const 142)) +(assert_return (invoke $Ng "Mg.get_mut") (i32.const 142)) + +(assert_return (invoke $Mg "set_mut" (i32.const 241))) +(assert_return (get $Mg "mut_glob") (i32.const 241)) +(assert_return (get $Ng "Mg.mut_glob") (i32.const 241)) +(assert_return (invoke $Mg "get_mut") (i32.const 241)) +(assert_return (invoke $Ng "Mg.get_mut") (i32.const 241)) + + +(assert_unlinkable + (module (import "Mg" "mut_glob" (global i32))) + "incompatible import type" +) +(assert_unlinkable + (module (import "Mg" "glob" (global (mut i32)))) + "incompatible import type" +)