Class: Hivemind::UniversalAST::Call

Inherits:
Element
  • Object
show all
Defined in:
lib/hivemind/universal_ast.rb,
lib/hivemind/vm.rb

Instance Method Summary collapse

Methods inherited from Element

fields, #offset

Instance Method Details

#render(depth = 0) ⇒ Object



67
68
69
# File 'lib/hivemind/universal_ast.rb', line 67

def render(depth = 0)
  "#{offset(depth)}Call\n#{@function.render(depth + 1)}\n#{offset(depth + 1)}#{@args.map(&:render).join(' ')}\n"
end

#run(env) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/hivemind/vm.rb', line 120

def run(env)
  if !@function.is_a?(Attribute)
    function = @function.run(env)
    env.current_self.call(function, @args.map { |arg| arg.run(env) }, env)
  elsif @function.label.value != :new
    obj = @function.object.run(env)
    function = obj.klass.dispatch_method(@function.label.value)
    obj.call(function, @args.map { |arg| arg.run(env) }, env)
  else
    obj = @function.object.run(env)
    function == obj.dispatch_method(:init)
    obj.call(function, @args.map { |arg| arg.run(env) }, env)
  end
end