2021-12-07 16:51:33 +01:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-02-11 15:46:47 +01:00
|
|
|
|
module RplLang
|
2022-02-10 14:50:59 +01:00
|
|
|
|
module Core
|
2022-02-11 15:46:47 +01:00
|
|
|
|
module Store
|
|
|
|
|
def populate_dictionary
|
|
|
|
|
super
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['▶', 'sto'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( content name -- ) store to variable',
|
|
|
|
|
proc do
|
|
|
|
|
args = stack_extract( [%i[name], :any] )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_var( args[0][:value],
|
|
|
|
|
args[1] )
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['rcl'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( name -- … ) push content of variable name onto stack',
|
|
|
|
|
proc do
|
|
|
|
|
args = stack_extract( [%i[name]] )
|
|
|
|
|
|
|
|
|
|
content = @dictionary.lookup( args[0][:value] )
|
|
|
|
|
|
|
|
|
|
@stack << content unless content.nil?
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['purge'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( name -- ) delete variable',
|
|
|
|
|
proc do
|
|
|
|
|
args = stack_extract( [%i[name]] )
|
|
|
|
|
|
|
|
|
|
@dictionary.remove_var( args[0][:value] )
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['vars'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( -- […] ) list variables',
|
|
|
|
|
proc do
|
|
|
|
|
@stack << { type: :list,
|
|
|
|
|
value: (@dictionary.vars.keys + @dictionary.local_vars_layers.reduce([]) { |memo, layer| memo + layer.keys }).map { |name| { type: :name, value: name } } }
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['clusr'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( -- ) delete all variables',
|
|
|
|
|
proc do
|
|
|
|
|
@dictionary.remove_all_vars
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sto+'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( a n -- ) add content to variable\'s value',
|
|
|
|
|
proc do
|
|
|
|
|
run( '
|
2022-01-20 11:56:38 +01:00
|
|
|
|
dup type "name" ==
|
|
|
|
|
« swap »
|
|
|
|
|
ift
|
2022-02-08 15:45:36 +01:00
|
|
|
|
over rcl + swap sto' )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sto-'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( a n -- ) subtract content to variable\'s value',
|
|
|
|
|
proc do
|
|
|
|
|
run( '
|
2022-01-20 11:56:38 +01:00
|
|
|
|
dup type "name" ==
|
|
|
|
|
« swap »
|
|
|
|
|
ift
|
2022-02-08 15:45:36 +01:00
|
|
|
|
over rcl swap - swap sto' )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end )
|
2021-12-08 12:46:57 +01:00
|
|
|
|
|
2022-02-11 15:46:47 +01:00
|
|
|
|
@dictionary.add_word( ['sto×', 'sto*'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( a n -- ) multiply content of variable\'s value',
|
|
|
|
|
proc do
|
|
|
|
|
run( '
|
2022-01-20 11:56:38 +01:00
|
|
|
|
dup type "name" ==
|
|
|
|
|
« swap »
|
|
|
|
|
ift
|
2022-02-08 15:45:36 +01:00
|
|
|
|
over rcl * swap sto' )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sto÷', 'sto/'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( a n -- ) divide content of variable\'s value',
|
|
|
|
|
proc do
|
|
|
|
|
run( '
|
2022-01-20 11:56:38 +01:00
|
|
|
|
dup type "name" ==
|
|
|
|
|
« swap »
|
|
|
|
|
ift
|
2022-02-08 15:45:36 +01:00
|
|
|
|
over rcl swap / swap sto' )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sneg'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( a n -- ) negate content of variable\'s value',
|
|
|
|
|
proc do
|
|
|
|
|
run( 'dup rcl chs swap sto' )
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sinv'],
|
|
|
|
|
'Store',
|
|
|
|
|
'( a n -- ) invert content of variable\'s value',
|
|
|
|
|
proc do
|
|
|
|
|
run( 'dup rcl inv swap sto' )
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['↴', 'lsto'],
|
|
|
|
|
'Program',
|
|
|
|
|
'( content name -- ) store to local variable',
|
|
|
|
|
proc do
|
|
|
|
|
args = stack_extract( [%i[name], :any] )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_local_var( args[0][:value],
|
|
|
|
|
args[1] )
|
|
|
|
|
end )
|
|
|
|
|
end
|
2021-12-07 16:51:33 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|