2021-12-16 15:21:23 +01:00
|
|
|
# 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 )
|
2022-02-08 15:45:36 +01:00
|
|
|
stack, args = Rpl::Lang.stack_extract( stack, [%i[numeric]] )
|
|
|
|
stack, args = Rpl::Lang.stack_extract( stack, %i[any] * args[0][:value] )
|
2021-12-16 15:21:23 +01:00
|
|
|
|
|
|
|
stack << { type: :list,
|
|
|
|
value: args.reverse }
|
|
|
|
|
|
|
|
[stack, dictionary]
|
|
|
|
end
|
|
|
|
|
|
|
|
# ( […] -- … ) unpack list on stack
|
|
|
|
def unpack_list( stack, dictionary )
|
2022-02-08 15:45:36 +01:00
|
|
|
stack, args = Rpl::Lang.stack_extract( stack, [%i[list]] )
|
2021-12-16 15:21:23 +01:00
|
|
|
|
|
|
|
args[0][:value].each do |elt|
|
|
|
|
stack << elt
|
|
|
|
end
|
|
|
|
|
|
|
|
[stack, dictionary]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|