Class: Opal::Nodes::Closure

Inherits:
Object
  • Object
show all
Defined in:
opal/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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, type, parent) ⇒ Closure

Returns a new instance of Closure.



46
47
48
49
50
# File 'opal/lib/opal/nodes/closure.rb', line 46

def initialize(node, type, parent)
  @node, @type, @parent = node, type, parent
  @catchers = []
  @throwers = {}
end

Instance Attribute Details

#catchersObject

Returns the value of attribute catchers.



70
71
72
# File 'opal/lib/opal/nodes/closure.rb', line 70

def catchers
  @catchers
end

#nodeObject

Returns the value of attribute node.



70
71
72
# File 'opal/lib/opal/nodes/closure.rb', line 70

def node
  @node
end

#parentObject

Returns the value of attribute parent.



70
71
72
# File 'opal/lib/opal/nodes/closure.rb', line 70

def parent
  @parent
end

#throwersObject

Returns the value of attribute throwers.



70
71
72
# File 'opal/lib/opal/nodes/closure.rb', line 70

def throwers
  @throwers
end

#typeObject

Returns the value of attribute type.



70
71
72
# File 'opal/lib/opal/nodes/closure.rb', line 70

def type
  @type
end

Class Method Details

.add_type(name, value) ⇒ Object



19
20
21
22
# File 'opal/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 'opal/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

#inspectObject



66
67
68
# File 'opal/lib/opal/nodes/closure.rb', line 66

def inspect
  "#<Closure #{Closure.type_inspect(type)} #{@node.class}>"
end

#is?(type) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'opal/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 'opal/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 'opal/lib/opal/nodes/closure.rb', line 58

def register_thrower(type, id)
  @throwers[type] = id
end