Class: Opal::Nodes::CallNode

Inherits:
Base
  • Object
show all
Defined in:
opal/lib/opal/nodes/call.rb

Direct Known Subclasses

BaseSuperNode, CSendNode, JsCallNode

Defined Under Namespace

Classes: DependencyResolver

Constant Summary collapse

SPECIALS =
{}
OPERATORS =

Operators that get optimized by compiler

{ :+ => :plus, :- => :minus, :* => :times, :/ => :divide,
:< => :lt, :<= => :le, :> => :gt, :>= => :ge }.freeze

Instance Attribute Summary collapse

Attributes inherited from Base

#compiler, #sexp, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#add_gvar, #add_ivar, #add_local, #add_temp, children, #children, #class_variable_owner, #class_variable_owner_nesting_level, #comments, #compile_to_fragments, #error, #expr, #expr?, #expr_or_nil, #fragment, handle, handlers, #has_rescue_else?, #helper, #in_ensure, #in_ensure?, #in_resbody, #in_resbody?, #in_rescue, #in_while?, #process, #push, #recv, #recv?, #s, #scope, #source_location, #stmt, #stmt?, #top_scope, truthy_optimize?, #unshift, #while_loop, #with_temp, #wrap

Methods included from Helpers

#conditional_send, #current_indent, #empty_line, #indent, #js_falsy, #js_truthy, #js_truthy_optimize, #line, #mid_to_jsid, #property, #valid_name?

Constructor Details

#initializeCallNode

Returns a new instance of CallNode.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'opal/lib/opal/nodes/call.rb', line 26

def initialize(*)
  super
  @recvr, @meth, *args = *@sexp

  *rest, last_arg = *args

  if last_arg && %i[iter block_pass].include?(last_arg.type)
    @iter = last_arg
    args = rest
  else
    @iter = nil
  end

  @arglist = s(:arglist, *args)
end

Instance Attribute Details

#arglistObject (readonly)

Returns the value of attribute arglist.



13
14
15
# File 'opal/lib/opal/nodes/call.rb', line 13

def arglist
  @arglist
end

#iterObject (readonly)

Returns the value of attribute iter.



13
14
15
# File 'opal/lib/opal/nodes/call.rb', line 13

def iter
  @iter
end

#methObject (readonly)

Returns the value of attribute meth.



13
14
15
# File 'opal/lib/opal/nodes/call.rb', line 13

def meth
  @meth
end

#recvrObject (readonly)

Returns the value of attribute recvr.



13
14
15
# File 'opal/lib/opal/nodes/call.rb', line 13

def recvr
  @recvr
end

Class Method Details

.add_special(name, options = {}, &handler) ⇒ Object



21
22
23
24
# File 'opal/lib/opal/nodes/call.rb', line 21

def self.add_special(name, options = {}, &handler)
  SPECIALS[name] = options
  define_method("handle_#{name}", &handler)
end

Instance Method Details

#compileObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'opal/lib/opal/nodes/call.rb', line 42

def compile
  # handle some methods specially
  # some special methods need to skip compilation, so we pass the default as a block
  handle_special do
    compiler.method_calls << meth.to_sym if record_method?

    # if trying to access an lvar in eval or irb mode
    return compile_eval_var if using_eval?

    # if trying to access an lvar in irb mode
    return compile_irb_var if using_irb?

    default_compile
  end
end