Class: NScript::CallNode
- Inherits:
-
Node
- Object
- Node
- NScript::CallNode
show all
- Defined in:
- lib/nscript/parser/nodes.rb
Constant Summary
Constants inherited
from Node
Node::TAB
Instance Method Summary
collapse
Methods inherited from Node
#children, children, #compile, #compile_closure, #contains?, #idt, statement, #statement?, statement_only, #statement_only?, top_sensitive, #top_sensitive?, #unwrap, #write
Constructor Details
#initialize(variable, arguments = []) ⇒ CallNode
Returns a new instance of CallNode.
203
204
205
206
|
# File 'lib/nscript/parser/nodes.rb', line 203
def initialize(variable, arguments=[])
@variable, @arguments = variable, arguments
@prefix = ''
end
|
Instance Method Details
#<<(argument) ⇒ Object
213
214
215
216
|
# File 'lib/nscript/parser/nodes.rb', line 213
def <<(argument)
@arguments << argument
self
end
|
#compile_node(o) ⇒ Object
218
219
220
221
222
223
|
# File 'lib/nscript/parser/nodes.rb', line 218
def compile_node(o)
return write(compile_splat(o)) if @arguments.any? {|a| a.is_a?(SplatNode) }
args = @arguments.map{|a| a.compile(o) }.join(', ')
return write(compile_super(args, o)) if @variable == 'super'
write("#{@prefix}#{@variable.compile(o)}(#{args})")
end
|
#compile_reference(o) ⇒ Object
245
246
247
248
249
|
# File 'lib/nscript/parser/nodes.rb', line 245
def compile_reference(o)
reference = o[:scope].free_variable
call = ParentheticalNode.new(AssignNode.new(reference, self))
return call, reference
end
|
#compile_splat(o) ⇒ Object
234
235
236
237
238
239
240
241
242
243
|
# File 'lib/nscript/parser/nodes.rb', line 234
def compile_splat(o)
meth = @variable.compile(o)
obj = @variable.source || 'this'
args = @arguments.map do |arg|
code = arg.compile(o)
code = arg.is_a?(SplatNode) ? code : "[#{code}]"
arg.equal?(@arguments.first) ? code : ".concat(#{code})"
end
"#{@prefix}#{meth}.apply(#{obj}, #{args.join('')})"
end
|
#compile_super(args, o) ⇒ Object
225
226
227
228
229
230
231
232
|
# File 'lib/nscript/parser/nodes.rb', line 225
def compile_super(args, o)
methname = o[:scope].function.name
arg_part = args.empty? ? '' : ", #{args}"
meth = o[:scope].function.proto ?
"#{o[:scope].function.proto}.__superClass__.#{methname}" :
"#{methname}.__superClass__.constructor"
"#{meth}.call(this#{arg_part})"
end
|
#new_instance ⇒ Object
208
209
210
211
|
# File 'lib/nscript/parser/nodes.rb', line 208
def new_instance
@prefix = "new "
self
end
|