Class: Code::Node::Code
- Inherits:
-
Code::Node
- Object
- Code::Node
- Code::Node::Code
- Defined in:
- lib/code/node/code.rb
Instance Method Summary collapse
- #evaluate(**args) ⇒ Object
-
#initialize(parsed) ⇒ Code
constructor
A new instance of Code.
- #resolve(**args) ⇒ Object
- #to_code ⇒ Object
- #to_raw ⇒ Object
Constructor Details
Instance Method Details
#evaluate(**args) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/code/node/code.rb', line 14 def evaluate(**args) global_control_flow_root = args.fetch(:global_control_flow_root, false) control_flow_scope = args.fetch(:control_flow_scope, nil) statement_args = if global_control_flow_root args.merge(global_control_flow_root: false) else args end last = Object::Nothing.new begin (@statements || []).each do |statement| last = statement.evaluate(**statement_args, object: Object::Global.new) end rescue Error::Retry retry if control_flow_scope == :group raise rescue Error::Break => e return e.code_value if control_flow_scope == :group raise end last rescue Error::ControlFlow => e raise unless global_control_flow_root retry if e.is_a?(Error::Retry) e.code_value end |
#resolve(**args) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/code/node/code.rb', line 49 def resolve(**args) last = Object::Nothing.new (@statements || []).each do |statement| last = statement.resolve(**args, object: Object::Global.new) end last end |
#to_code ⇒ Object
59 60 61 |
# File 'lib/code/node/code.rb', line 59 def to_code @statements.blank? ? Object::Nothing.new : Object::Code.new(self) end |
#to_raw ⇒ Object
63 64 65 |
# File 'lib/code/node/code.rb', line 63 def to_raw @parsed.deep_dup end |