Class: Peruby::Op::CodeCall

Inherits:
Base
  • Object
show all
Defined in:
lib/peruby/op/call.rb

Overview

Invocation through a code reference.

Instance Method Summary collapse

Methods inherited from Base

#argument_cells, #local_slot, #lvalue, #run_subroutine, #to_callable, #warning_directive?

Constructor Details

#initialize(receiver, arguments, inherit: false) ⇒ CodeCall

Returns a new instance of CodeCall.



117
118
119
120
121
# File 'lib/peruby/op/call.rb', line 117

def initialize(receiver, arguments, inherit: false)
  @receiver = receiver
  @arguments = arguments
  @inherit = inherit
end

Instance Method Details

#run(env, context) ⇒ Object

Raises:



123
124
125
126
127
128
129
130
# File 'lib/peruby/op/call.rb', line 123

def run(env, context)
  code = @receiver.run(env, :scalar)
  code = code.target if code.is_a?(Ref) && code.kind == 'CODE'
  raise PerlError, 'Not a CODE reference' unless code.is_a?(Code)

  arguments = @inherit ? env.fetch(:array, '_').cells.dup : @arguments.argument_cells(env)
  env.runtime.call(code, arguments, context)
end