-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
(module | ||
;; javascript increment function | ||
(import "js" "increment" (func $js_increment (result i32))) | ||
;; javascript decrement function | ||
(import "js" "decrement" (func $js_decrement (result i32))) | ||
|
||
(table $tbl (export "tbl") 4 anyfunc) ;; exported table with 4 functions | ||
|
||
(global $i (mut i32) (i32.const 0)) | ||
|
||
(func $increment (export "increment") (result i32) | ||
(global.set $i (i32.add (global.get $i) (i32.const 1))) ;; $i++ | ||
global.get $i | ||
) | ||
|
||
(func $decrement (export "decrement") (result i32) | ||
(global.set $i (i32.sub (global.get $i) (i32.const 1))) ;; $i-- | ||
global.get $i | ||
) | ||
|
||
;; populate the table | ||
;; the first parameter is the starting index we want to update. | ||
(elem (i32.const 0) $js_increment $js_decrement $increment $decrement) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
(module | ||
(import "js" "tbl" (table $tbl 4 anyfunc)) | ||
;; import increment function | ||
(import "js" "increment" (func $increment (result i32))) | ||
;; import decrement function | ||
(import "js" "decrement" (func $decrement (result i32))) | ||
|
||
;; import wasm_increment function | ||
(import "js" "wasm_increment" (func $wasm_increment (result i32))) | ||
;; import wasm_decrement function | ||
(import "js" "wasm_decrement" (func $wasm_decrement (result i32))) | ||
|
||
;; table function type definitions all i32 and take no parameters | ||
(type $returns_i32 (func (result i32))) |