Class: Opal::Nodes::Closure
- Inherits:
-
Object
- Object
- Opal::Nodes::Closure
- Defined in:
- lib/opal/nodes/closure.rb
Overview
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.
Defined Under Namespace
Modules: CompilerSupport, NodeSupport
Constant Summary collapse
- NONE =
0
- ANY =
0xffffffff
Instance Attribute Summary collapse
-
#catchers ⇒ Object
Returns the value of attribute catchers.
-
#node ⇒ Object
Returns the value of attribute node.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#throwers ⇒ Object
Returns the value of attribute throwers.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(node, type, parent) ⇒ Closure
constructor
A new instance of Closure.
- #inspect ⇒ Object
- #is?(type) ⇒ Boolean
- #register_catcher(type = :return) ⇒ Object
- #register_thrower(type, id) ⇒ Object
Constructor Details
#initialize(node, type, parent) ⇒ Closure
Returns a new instance of Closure.
46 47 48 49 50 |
# File 'lib/opal/nodes/closure.rb', line 46 def initialize(node, type, parent) @node, @type, @parent = node, type, parent @catchers = [] @throwers = {} end |
Instance Attribute Details
#catchers ⇒ Object
Returns the value of attribute catchers.
70 71 72 |
# File 'lib/opal/nodes/closure.rb', line 70 def catchers @catchers end |
#node ⇒ Object
Returns the value of attribute node.
70 71 72 |
# File 'lib/opal/nodes/closure.rb', line 70 def node @node end |
#parent ⇒ Object
Returns the value of attribute parent.
70 71 72 |
# File 'lib/opal/nodes/closure.rb', line 70 def parent @parent end |
#throwers ⇒ Object
Returns the value of attribute throwers.
70 71 72 |
# File 'lib/opal/nodes/closure.rb', line 70 def throwers @throwers end |
#type ⇒ Object
Returns the value of attribute type.
70 71 72 |
# File 'lib/opal/nodes/closure.rb', line 70 def type @type end |
Class Method Details
.add_type(name, value) ⇒ Object
19 20 21 22 |
# File 'lib/opal/nodes/closure.rb', line 19 def self.add_type(name, value) const_set(name, value) @types[name] = value end |
.type_inspect(type) ⇒ Object
24 25 26 27 28 |
# 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 |
Instance Method Details
#inspect ⇒ Object
66 67 68 |
# File 'lib/opal/nodes/closure.rb', line 66 def inspect "#<Closure #{Closure.type_inspect(type)} #{@node.class}>" end |
#is?(type) ⇒ Boolean
62 63 64 |
# File 'lib/opal/nodes/closure.rb', line 62 def is?(type) (@type & type) != 0 end |
#register_catcher(type = :return) ⇒ Object
52 53 54 55 56 |
# 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) ⇒ Object
58 59 60 |
# File 'lib/opal/nodes/closure.rb', line 58 def register_thrower(type, id) @throwers[type] = id end |