-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for functions with shared implementations (#1)
- Loading branch information
Showing
4 changed files
with
39 additions
and
2 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,6 @@ | ||
(module | ||
(type (;0;) (func (result i32))) | ||
(func (;0;) (type 0) (result i32) | ||
i32.const 65536) | ||
(export "constant_1" (func 0)) | ||
(export "constant_2" (func 0))) |
24 changes: 24 additions & 0 deletions
24
Tests/WasmInterpreterTests/Wasm Modules/ConstantModule.swift
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,24 @@ | ||
import Foundation | ||
import WasmInterpreter | ||
|
||
public struct ConstantModule { | ||
private let _vm: WasmInterpreter | ||
|
||
init() throws { | ||
_vm = try WasmInterpreter(module: ConstantModule.wasm) | ||
} | ||
|
||
func constant1() throws -> Int { | ||
return Int(try _vm.call("constant_1") as Int32) | ||
} | ||
|
||
func constant2() throws -> Int { | ||
return Int(try _vm.call("constant_2") as Int32) | ||
} | ||
|
||
// `wat2wasm -o >(base64) Tests/WasmInterpreterTests/Resources/constant.wat | pbcopy` | ||
private static var wasm: [UInt8] { | ||
let base64 = "AGFzbQEAAAABBQFgAAF/AwIBAAcbAgpjb25zdGFudF8xAAAKY29uc3RhbnRfMgAACggBBgBBgIAECw==" | ||
return Array<UInt8>(Data(base64Encoded: base64)!) | ||
} | ||
} |
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