-
Notifications
You must be signed in to change notification settings - Fork 451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement has_feature. #120
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
99088eb
Implement has_feature.
sunfishcode c38d5d1
Add an always-supported feature, and a test for it.
sunfishcode 98ad7ed
Replace the type_hostop_type with a tuple of func_type and bool.
sunfishcode 7dcef04
Remove redundant parens.
sunfishcode f4ec3f3
Rename a mem to mem_opt because it's an option type now.
sunfishcode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1 +1,7 @@ | ||
let page_size = 4096L | ||
|
||
let has_feature = fun str -> match str with | ||
(* We always support this feature :-). *) | ||
| "wasm" -> true | ||
(* If we don't recognize a feature name, we don't support the feature. *) | ||
| _ -> false |
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
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
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 |
---|---|---|
|
@@ -14,7 +14,10 @@ let error = Error.error | |
|
||
type value = Values.value | ||
type import = value list -> value option | ||
type host_params = {page_size : Memory.size} | ||
type host_params = { | ||
page_size : Memory.size; | ||
has_feature : string -> bool | ||
} | ||
|
||
module ExportMap = Map.Make(String) | ||
type export_map = func ExportMap.t | ||
|
@@ -247,7 +250,7 @@ let rec eval_expr (c : config) (e : expr) = | |
|
||
| Host (hostop, es) -> | ||
let vs = List.map (eval_expr c) es in | ||
let mem = some_memory c e.at in | ||
let mem = c.instance.memory in | ||
eval_hostop c.instance.host mem hostop vs e.at | ||
|
||
and eval_expr_opt c = function | ||
|
@@ -277,17 +280,20 @@ and coerce et vo = | |
|
||
(* Host operators *) | ||
|
||
and eval_hostop host mem hostop vs at = | ||
and eval_hostop host mem_opt hostop vs at = | ||
match hostop, vs with | ||
| PageSize, [] -> | ||
let mem = some mem_opt at in | ||
assert (I64.lt_u host.page_size (Int64.of_int32 Int32.max_int)); | ||
Some (Int32 (Int64.to_int32 host.page_size)) | ||
|
||
| MemorySize, [] -> | ||
let mem = some mem_opt at in | ||
assert (I64.lt_u (Memory.size mem) (Int64.of_int32 Int32.max_int)); | ||
Some (Int32 (Int64.to_int32 (Memory.size mem))) | ||
|
||
| GrowMemory, [v] -> | ||
let mem = some mem_opt at in | ||
let delta = mem_size v at in | ||
if I64.rem_u delta host.page_size <> 0L then | ||
error at "runtime: grow_memory operand not multiple of page_size"; | ||
|
@@ -298,6 +304,9 @@ and eval_hostop host mem hostop vs at = | |
Memory.grow mem delta; | ||
None; | ||
|
||
| HasFeature str, [] -> | ||
Some (Int32 (if (host.has_feature str) then 1l else 0l)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: redundant parens |
||
|
||
| _, _ -> | ||
error at "runtime: invalid invocation of host operator" | ||
|
||
|
@@ -327,4 +336,3 @@ let invoke instance name vs = | |
assert (List.length vs = List.length (func_type instance f).ins); | ||
eval_func instance f vs | ||
with Stack_overflow -> callstack_exhaustion no_region | ||
|
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
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,12 @@ | ||
(module | ||
(func $has_wasm (result i32) | ||
(has_feature "wasm")) | ||
(export "has_wasm" $has_wasm) | ||
|
||
(func $has_simd128 (result i32) | ||
(has_feature "simd128")) | ||
(export "has_simd128" $has_simd128) | ||
) | ||
|
||
(assert_return (invoke "has_wasm") (i32.const 1)) | ||
(assert_return (invoke "has_simd128") (i32.const 0)) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of introducing another variant of function type for a singular use, can't
type_hostop
just return a pairfunc_type * bool
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That works.