-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Record exported function param types Require type converting Variant to Wasm value * Validate argument count * Record import function return types * Separate import tests * Type inference tests * Fix test dummy import leaking Godot object * Exported function argument count test
- Loading branch information
1 parent
5900422
commit 3cc7506
Showing
9 changed files
with
168 additions
and
89 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,81 @@ | ||
extends GodotWasmTestSuite | ||
|
||
func test_imports(): | ||
var imports = { "functions": { | ||
"import.import_int": dummy_import(), | ||
"import.import_float": dummy_import(), | ||
} } | ||
load_wasm("import", imports) | ||
expect_empty() | ||
|
||
func test_invalid_imports(): | ||
var wasm = Wasm.new() | ||
var buffer = read_file("import") | ||
var error = wasm.compile(buffer) | ||
expect_eq(error, OK) | ||
# Missing import | ||
var imports = {} | ||
error = wasm.instantiate(imports) | ||
expect_eq(error, ERR_CANT_CREATE) | ||
expect_error("Missing import function import.import_(int|float)") | ||
# Invalid import | ||
imports = { "functions": { | ||
"import.import_int": [], | ||
"import.import_float": dummy_import(), | ||
} } | ||
error = wasm.instantiate(imports) | ||
expect_eq(error, ERR_CANT_CREATE) | ||
expect_error("Invalid import function import.import_int") | ||
# Invalid import target | ||
imports = { "functions": { | ||
"import.import_int": [0, "dummy"], | ||
"import.import_float": dummy_import(), | ||
} } | ||
error = wasm.instantiate(imports) | ||
expect_eq(error, ERR_CANT_CREATE) | ||
expect_error("Invalid import target import.import_int") | ||
# Invalid import method | ||
imports = { "functions": { | ||
"import.import_int": [self, 0], | ||
"import.import_float": dummy_import(), | ||
} } | ||
error = wasm.instantiate(imports) | ||
expect_eq(error, ERR_CANT_CREATE) | ||
expect_error("Invalid import method import.import_int") | ||
|
||
func test_callback_function(): | ||
var imports = { "functions": { | ||
"import.import_int": dummy_import(), | ||
"import.import_float": dummy_import(), | ||
} } | ||
var wasm = load_wasm("import", imports) | ||
wasm.function("callback", []) | ||
expect_log("Dummy import -123") | ||
expect_log("Dummy import -12.34") | ||
|
||
func test_inspect(): | ||
# Import module post-instantiation | ||
var imports = { "functions": { | ||
"import.import_int": dummy_import(), | ||
"import.import_float": dummy_import(), | ||
} } | ||
var wasm = load_wasm("import", imports) | ||
var inspect = wasm.inspect() | ||
var expected = { | ||
"import_functions": { | ||
"import.import_float": [[TYPE_FLOAT], []], | ||
"import.import_int": [[TYPE_INT], []], | ||
}, | ||
"export_globals": {}, | ||
"export_functions": { | ||
"_initialize": [[], []], | ||
"callback": [[], []], | ||
}, | ||
"memory": { | ||
"min": 0, | ||
"max": PAGES_MAX, | ||
"current": 0, | ||
} | ||
} | ||
expect_eq(inspect, expected) | ||
expect_empty() |
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,13 @@ | ||
extends GodotWasmTestSuite | ||
|
||
func test_param_types(): | ||
var wasm = load_wasm("inference", { "functions": { | ||
"inference.echo_i32": dummy_import(), | ||
"inference.echo_i64": dummy_import(), | ||
"inference.echo_f32": dummy_import(), | ||
"inference.echo_f64": dummy_import(), | ||
} }) | ||
expect_eq(wasm.function("add_i32", [3, -1]), 2) | ||
expect_eq(wasm.function("add_i64", [3, -1]), 2) | ||
expect_approx(wasm.function("add_f32", [3.5, -1.2]), 2.3) | ||
expect_approx(wasm.function("add_f64", [3.5, -1.2]), 2.3) |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
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