Skip to content

Commit

Permalink
Add example with multi-module table imports/exports.
Browse files Browse the repository at this point in the history
  • Loading branch information
axel22 committed Dec 13, 2019
1 parent 19865d6 commit 9c209c7
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
int 68
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,52 @@
;;
(module
(type (;0;) (func (result i32)))
(import "table-registry" "functiontable" (table (;0;) 10 10))
(type (;1;) (func (param i32) (result i32)))
(import "man-in-the-middle" "functiontable" (table (;0;) 6 6 funcref))
(func (export "_main") (type 0)
(local i32)
;; Multiply 1 by 2.
i32.const 0
i32.const 1
call_indirect
local.set 0

;; Multiply by 3.
i32.const 1
local.get 0
call_indirect
local.set 0

;; Multiply by 4.
i32.const 2
local.get 0
call_indirect
local.set 0

;; Add 1.
;; Now we have 25.
i32.const 3
local.get 0
call_indirect
local.set 0

;; Indirectly call multiplication by 3.
;; Now we have 75.
i32.const 4
local.get 0
call_indirect
local.set 0

;; Subtract 7.
;; Result should be 68.
i32.const 4
local.get 0
call_indirect
)
(func (type 1)
local.get 0
i32.const 7
i32.sub
)
(elem (;0;) (i32.const 5) 1)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
;;
;; Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
;; DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
;;
;; The Universal Permissive License (UPL), Version 1.0
;;
;; Subject to the condition set forth below, permission is hereby granted to any
;; person obtaining a copy of this software, associated documentation and/or
;; data (collectively the "Software"), free of charge and under any and all
;; copyright rights in the Software, and any and all patent rights owned or
;; freely licensable by each licensor hereunder covering either (i) the
;; unmodified Software as contributed to or provided by such licensor, or (ii)
;; the Larger Works (as defined below), to deal in both
;;
;; (a) the Software, and
;;
;; (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
;; one is included with the Software each a "Larger Work" to which the Software
;; is contributed by such licensors),
;;
;; without restriction, including without limitation the rights to copy, create
;; derivative works of, display, perform, and distribute the Software and make,
;; use, sell, offer for sale, import, export, have made, and have sold the
;; Software and the Larger Work(s), and to sublicense the foregoing rights on
;; either these or other terms.
;;
;; This license is subject to the following condition:
;;
;; The above copyright notice and either this complete permission notice or at a
;; minimum a reference to the UPL must be included in all copies or substantial
;; portions of the Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
;; SOFTWARE.
;;
(module
(type (;0;) (func (param i32) (result i32)))
(import "table-registry" "functiontable" (table (;0;) 6 6 funcref))
(func (type 0)
local.get 0
i32.const 1
i32.add
)
(func (type 0)
i32.const 1
local.get 0
call_indirect
)
(export "functiontable" (table 0))
(elem (;0;) (i32.const 3) 0 1)
)
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@
;; SOFTWARE.
;;
(module
(table 10 10 funcref)
(type (;0;) (func (param i32) (result i32)))
(table 6 6 funcref)
(func (type 0)
local.get 0
i32.const 2
i32.mul
)
(func (type 0)
local.get 0
i32.const 3
i32.mul
)
(func (type 0)
local.get 0
i32.const 4
i32.mul
)
(export "functiontable" (table 0))
(elem (;0;) (i32.const 0) 0 1 2)
)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import_export_memory/main;man-in-the-middle
import_export_functions/main;friend;man-in-the-middle
import_export_table/main;table-registry
import_export_table/main;man-in-the-middle;table-registry

0 comments on commit 9c209c7

Please sign in to comment.