Class: Rlang::Parser::Global
Constant Summary collapse
- @@globals =
[]
Instance Attribute Summary collapse
-
#mutable ⇒ Object
Returns the value of attribute mutable.
-
#name ⇒ Object
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
-
#wtype ⇒ Object
Returns the value of attribute wtype.
Class Method Summary collapse
Instance Method Summary collapse
- #export! ⇒ Object
- #export_name ⇒ Object
- #export_wasm_code ⇒ Object
-
#initialize(name, wtype = WType::DEFAULT, value = 0, mutable = true) ⇒ Global
constructor
A new instance of Global.
- #mutable? ⇒ Boolean
- #wasm_name ⇒ Object
- #wasm_type ⇒ Object
Constructor Details
#initialize(name, wtype = WType::DEFAULT, value = 0, mutable = true) ⇒ Global
Returns a new instance of Global.
15 16 17 18 19 20 21 |
# File 'lib/rlang/parser/global.rb', line 15 def initialize(name, wtype=WType::DEFAULT, value=0, mutable=true) @name = name @wtype = wtype @mutable = mutable @value = value @@globals << self end |
Instance Attribute Details
#mutable ⇒ Object
Returns the value of attribute mutable.
13 14 15 |
# File 'lib/rlang/parser/global.rb', line 13 def mutable @mutable end |
#name ⇒ Object
Returns the value of attribute name.
13 14 15 |
# File 'lib/rlang/parser/global.rb', line 13 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
13 14 15 |
# File 'lib/rlang/parser/global.rb', line 13 def value @value end |
#wtype ⇒ Object
Returns the value of attribute wtype.
13 14 15 |
# File 'lib/rlang/parser/global.rb', line 13 def wtype @wtype end |
Class Method Details
.find(name) ⇒ Object
23 24 25 |
# File 'lib/rlang/parser/global.rb', line 23 def self.find(name) @@globals.find {|g| g.name == name} end |
.reset! ⇒ Object
27 28 29 |
# File 'lib/rlang/parser/global.rb', line 27 def self.reset! @@globals = [] end |
.transpile(depth) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/rlang/parser/global.rb', line 55 def self.transpile(depth) # TODO : we should probably do that in a less "hardcoded" way # Adjust the Heap base address to start after the static DAta # section g_heap = Global.find(:$HEAP) g_heap.value = [DAta.align(8), g_heap.value].max if g_heap # Go generate code now indent = ' ' * depth * 2 output = [] @@globals.each do |g| if g.mutable? output << '(global %{name} (mut %{type}) (%{type}.const %{value}))' \ % {name: g.wasm_name, type: g.wtype.wasm_type, value: g.value} else output << '(global %{name} %{type} (%{type}.const %{value}))' \ % {name: g.wasm_name, type: g.wtype.wasm_type, value: g.value} end end indent + output.join("\n#{indent}") end |
Instance Method Details
#export! ⇒ Object
47 48 49 |
# File 'lib/rlang/parser/global.rb', line 47 def export! Export.new(self) end |
#export_name ⇒ Object
43 44 45 |
# File 'lib/rlang/parser/global.rb', line 43 def export_name @name end |
#export_wasm_code ⇒ Object
51 52 53 |
# File 'lib/rlang/parser/global.rb', line 51 def export_wasm_code '(export "%s" (global %s (mut %s)))' % [self.export_name, self.wasm_name, self.wtype.wasm_type] end |
#mutable? ⇒ Boolean
31 32 33 |
# File 'lib/rlang/parser/global.rb', line 31 def mutable? @mutable end |
#wasm_name ⇒ Object
35 36 37 |
# File 'lib/rlang/parser/global.rb', line 35 def wasm_name @name end |
#wasm_type ⇒ Object
39 40 41 |
# File 'lib/rlang/parser/global.rb', line 39 def wasm_type @wtype.wasm_type end |