Class: Peruby::Op::AnonSub

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

Overview

Anonymous closure creation.

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(prototype, body) ⇒ AnonSub

Returns a new instance of AnonSub.



50
51
52
53
# File 'lib/peruby/op/call.rb', line 50

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

Instance Method Details

#run(env, context) ⇒ Object



55
56
57
# File 'lib/peruby/op/call.rb', line 55

def run(env, context)
  reference(env, context, @body)
end

#to_callableObject



59
60
61
62
# File 'lib/peruby/op/call.rb', line 59

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