rpl.rb/lib/core/list.rb
Gwenhael Le Moine 8c5657db42
big refactoring
2022-02-08 15:45:36 +01:00

31 lines
747 B
Ruby

# frozen_string_literal: true
module Rpl
module Lang
module Core
module_function
# ( … x -- […] ) pack x stacks levels into a list
def to_list( stack, dictionary )
stack, args = Rpl::Lang.stack_extract( stack, [%i[numeric]] )
stack, args = Rpl::Lang.stack_extract( stack, %i[any] * args[0][:value] )
stack << { type: :list,
value: args.reverse }
[stack, dictionary]
end
# ( […] -- … ) unpack list on stack
def unpack_list( stack, dictionary )
stack, args = Rpl::Lang.stack_extract( stack, [%i[list]] )
args[0][:value].each do |elt|
stack << elt
end
[stack, dictionary]
end
end
end
end