@@ -8,25 +8,15 @@ class CallNode < Base
8
8
children :recvr , :meth , :arglist , :iter
9
9
10
10
def compile
11
- if handled = self . handle_special
12
- push handled
13
- return
14
- end
15
-
16
- mid = mid_to_jsid meth . to_s
11
+ # if we handle this call specially, just do that and return early
12
+ return if self . handle_special
17
13
18
14
compiler . method_calls << meth . to_sym
19
15
20
- # trying to access an lvar in irb mode
21
- if using_irb?
22
- with_temp do |tmp |
23
- lvar = variable ( meth )
24
- call = s ( :call , s ( :self ) , meth . intern , s ( :arglist ) )
25
- push "((#{ tmp } = $opal.irb_vars.#{ lvar } ) == null ? " , expr ( call ) , " : #{ tmp } )"
26
- end
16
+ # if trying to access an lvar in irb mode
17
+ return compile_irb_var if using_irb?
27
18
28
- return
29
- end
19
+ mid = mid_to_jsid meth . to_s
30
20
31
21
splat = arglist [ 1 ..-1 ] . any? { |a | a . first == :splat }
32
22
@@ -60,9 +50,7 @@ def compile
60
50
end
61
51
62
52
if splat
63
- push ".apply("
64
- push ( tmprecv || recv_code )
65
- push ", " , args , ")"
53
+ push ".apply(" , ( tmprecv || recv_code ) , ", " , args , ")"
66
54
elsif tmpfunc
67
55
push ".call(" , args , ")"
68
56
else
@@ -76,6 +64,17 @@ def recv_sexp
76
64
recvr || s ( :self )
77
65
end
78
66
67
+ # Used to generate the code to use this sexp as an ivar var reference
68
+ def compile_irb_var
69
+ with_temp do |tmp |
70
+ lvar = variable ( meth )
71
+ call = s ( :call , s ( :self ) , meth . intern , s ( :arglist ) )
72
+ push "((#{ tmp } = $opal.irb_vars.#{ lvar } ) == null ? " , expr ( call ) , " : #{ tmp } )"
73
+ end
74
+ end
75
+
76
+ # a variable reference in irb mode in top scope might be a var ref,
77
+ # or it might be a method call
79
78
def using_irb?
80
79
@compiler . irb? and scope . top? and arglist == s ( :arglist ) and recvr . nil? and iter . nil?
81
80
end
@@ -84,11 +83,9 @@ def using_irb?
84
83
# this method. If this method returns nil, then the method will continue
85
84
# to be generated by CallNode.
86
85
def handle_special
87
- case meth
88
- when :require then handle_require
89
- when :autoload then handle_autoload
90
- when :block_given? then handle_block_given
91
- when :__method__ , :__callee__ then handle_callee
86
+ if respond_to? "handle_#{ meth } "
87
+ push __send__ ( "handle_#{ meth } " )
88
+ return true
92
89
end
93
90
end
94
91
@@ -106,18 +103,20 @@ def handle_autoload
106
103
end
107
104
end
108
105
109
- def handle_block_given
106
+ def handle_block_given?
110
107
compiler . handle_block_given_call @sexp
111
108
end
112
109
113
- def handle_callee
110
+ def handle___callee__
114
111
if scope . def?
115
112
fragment scope . mid . to_s . inspect
116
113
else
117
114
fragment 'nil'
118
115
end
119
116
end
120
117
118
+ alias handle___method__ handle___callee__
119
+
121
120
class DependencyResolver
122
121
def initialize ( compiler , sexp )
123
122
@compiler = compiler
0 commit comments