-
Notifications
You must be signed in to change notification settings - Fork 4
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
[Feature] Adds importable memory. #42
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ defmodule Orb.Memory do | |
Work with memory: load, store, declare pages & initial data. | ||
""" | ||
|
||
defstruct name: "", min: 0, exported_name: "memory" | ||
defstruct name: "", min: 0, exported_name: "memory", is_imported?: false | ||
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. There‘s a bug from me where we aren’t using the I think generally it makes sense if you can export xor import, not both. So I’ll have a think about how best to represent that… 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. Suggested resolution? Or needs some thinking? 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. Sorry work has been super busy, I’ll resolve this soon! |
||
|
||
@doc false | ||
def new(page_definitions, constants) | ||
|
@@ -186,7 +186,7 @@ defmodule Orb.Memory do | |
end | ||
|
||
defimpl Orb.ToWat do | ||
def to_wat(%Orb.Memory{min: min}, indent) do | ||
def to_wat(%Orb.Memory{min: min, is_imported?: is_imported?}, indent) when not is_imported? do | ||
[ | ||
indent, | ||
~S{(memory (export "memory")}, | ||
|
@@ -198,6 +198,19 @@ defmodule Orb.Memory do | |
"\n" | ||
] | ||
end | ||
|
||
def to_wat(%Orb.Memory{is_imported?: true, name: name, min: min}, indent) do | ||
[ | ||
indent, | ||
"(memory", | ||
to_string(name), | ||
case min do | ||
nil -> [] | ||
min when min >= 0 -> [" ", to_string(min)] | ||
end, | ||
")", | ||
] | ||
end | ||
end | ||
|
||
defimpl Orb.ToWasm do | ||
|
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.
Curious why
register_memory/3
instead ofmemory/3
?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.
Just seemed like the thing to do, I was frankly pretty tired when I wrote this so perhaps memory/3 would be more appropriate.