Class: Peruby::Op::SubDef

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

Overview

Runtime subroutine definition.

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(name, prototype, body) ⇒ SubDef

Returns a new instance of SubDef.



7
8
9
10
11
# File 'lib/peruby/op/call.rb', line 7

def initialize(name, prototype, body)
  @name = name
  @prototype = prototype
  @body = body
end

Instance Method Details

#run(env, _context) ⇒ Object



13
14
15
# File 'lib/peruby/op/call.rb', line 13

def run(env, _context)
  install(env, @body)
end

#to_callableObject



17
18
19
20
# File 'lib/peruby/op/call.rb', line 17

def to_callable
  body = Compiled.new(@body.to_callable, @body.to_subroutine_callable)
  ->(env, _context) { install(env, body) }
end