2021-12-16 15:21:23 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
module Lang
|
|
|
|
module Core
|
|
|
|
module_function
|
2021-12-16 15:21:23 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
# ( … x -- […] ) pack x stacks levels into a list
|
|
|
|
def to_list
|
|
|
|
args = stack_extract( [%i[numeric]] )
|
|
|
|
args = stack_extract( %i[any] * args[0][:value] )
|
2021-12-16 15:21:23 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
@stack << { type: :list,
|
|
|
|
value: args.reverse }
|
|
|
|
end
|
2021-12-16 15:21:23 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
# ( […] -- … ) unpack list on stack
|
|
|
|
def unpack_list
|
|
|
|
args = stack_extract( [%i[list]] )
|
2021-12-16 15:21:23 +01:00
|
|
|
|
2022-02-10 14:50:59 +01:00
|
|
|
args[0][:value].each do |elt|
|
|
|
|
@stack << elt
|
2021-12-16 15:21:23 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|