class Opal::Nodes::Closure
This module takes care of providing information about the closure stack that we have for the nodes during compile time. This is not a typical node.
Also, while loops are not closures per se, this module also takes a note about them.
Then we can use this information for control flow like generating breaks, nexts, returns.
Constants
- ANY
- NONE
Attributes
catchers[RW]
node[RW]
parent[RW]
throwers[RW]
type[RW]
Public Class Methods
add_type(name, value)
click to toggle source
# File lib/opal/nodes/closure.rb, line 19 def self.add_type(name, value) const_set(name, value) @types[name] = value end
new(node, type, parent)
click to toggle source
# File lib/opal/nodes/closure.rb, line 46 def initialize(node, type, parent) @node, @type, @parent = node, type, parent @catchers = [] @throwers = {} end
type_inspect(type)
click to toggle source
# File lib/opal/nodes/closure.rb, line 24 def self.type_inspect(type) @types.reject do |_name, value| (type & value) == 0 end.map(&:first).join("|") end
Public Instance Methods
inspect()
click to toggle source
# File lib/opal/nodes/closure.rb, line 66 def inspect "#<Closure #{Closure.type_inspect(type)} #{@node.class}>" end
is?(type)
click to toggle source
# File lib/opal/nodes/closure.rb, line 62 def is?(type) (@type & type) != 0 end
register_catcher(type = :return)
click to toggle source
# File lib/opal/nodes/closure.rb, line 52 def register_catcher(type = :return) @catchers << type unless @catchers.include? type "$t_#{type}" end
register_thrower(type, id)
click to toggle source
# File lib/opal/nodes/closure.rb, line 58 def register_thrower(type, id) @throwers[type] = id end