Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Factor reference tests for the proposal to avoid confusion #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions test/core/globals.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
Expand Down
5 changes: 5 additions & 0 deletions test/core/globals_proposed.wast
Original file line number Diff line number Diff line change
@@ -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)))
33 changes: 0 additions & 33 deletions test/core/linking.wast
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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

Expand Down
48 changes: 48 additions & 0 deletions test/core/linking_proposed.wast
Original file line number Diff line number Diff line change
@@ -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"
)