Class: Opal::Rewriters::ReturnableLogic

Inherits:
Base
  • Object
show all
Defined in:
opal/lib/opal/rewriters/returnable_logic.rb

Constant Summary

Constants inherited from Base

Base::DUMMY_LOCATION

Instance Attribute Summary

Attributes inherited from Base

#current_node

Instance Method Summary collapse

Methods inherited from Base

#append_to_body, #begin_with_stmts, #error, #prepend_to_body, #process, #s, s, #stmts_of

Instance Method Details

#next_tmpObject


8
9
10
11
12
# File 'opal/lib/opal/rewriters/returnable_logic.rb', line 8

def next_tmp
  @counter ||= 0
  @counter += 1
  "$ret_or_#{@counter}"
end

#on_and(node) ⇒ Object


25
26
27
28
29
30
# File 'opal/lib/opal/rewriters/returnable_logic.rb', line 25

def on_and(node)
  lhs, rhs = *node.children
  lhs_tmp = next_tmp

  node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), process(rhs), s(:js_tmp, lhs_tmp)])
end

#on_or(node) ⇒ Object


18
19
20
21
22
23
# File 'opal/lib/opal/rewriters/returnable_logic.rb', line 18

def on_or(node)
  lhs, rhs = *node.children
  lhs_tmp = next_tmp

  node.updated(:if, [s(:lvasgn, lhs_tmp, process(lhs)), s(:js_tmp, lhs_tmp), process(rhs)])
end

#reset_tmp_counter!Object


14
15
16
# File 'opal/lib/opal/rewriters/returnable_logic.rb', line 14

def reset_tmp_counter!
  @counter = nil
end