-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dedicated to const, which makes it easier to work with and transform. I’ll remove the old paths through Orb.Instruction next
- Loading branch information
1 parent
8a84ed6
commit f6acec2
Showing
2 changed files
with
21 additions
and
6 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,19 @@ | ||
defmodule Orb.Instruction.Const do | ||
@moduledoc false | ||
defstruct [:push_type, :value] | ||
|
||
def new(push_type, value) when push_type in ~w(i32 i64 f32 f64)a do | ||
%__MODULE__{push_type: push_type, value: value} | ||
end | ||
|
||
defimpl Orb.ToWat do | ||
def to_wat(%Orb.Instruction.Const{push_type: push_type, value: value}, indent) do | ||
[ | ||
indent, | ||
["(", Atom.to_string(push_type), ".const "], | ||
to_string(value), | ||
")" | ||
] | ||
end | ||
end | ||
end |