Class: Peruby::Op::ArrayLiteral

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

Overview

Anonymous array reference.

Instance Method Summary collapse

Methods inherited from Base

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

Constructor Details

#initialize(items) ⇒ ArrayLiteral

Returns a new instance of ArrayLiteral.



76
77
78
# File 'lib/peruby/op/list.rb', line 76

def initialize(items)
  @items = items
end

Instance Method Details

#run(env, context) ⇒ Object



80
81
82
83
84
# File 'lib/peruby/op/list.rb', line 80

def run(env, context)
  cells = @items.flat_map { |item| item.run(env, :list) }.map(&:copy)
  value = Ref.new(PerlArray.new(cells))
  context == :list ? [Scalar.new(value)] : value
end