2021-12-07 16:51:33 +01:00
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2022-02-11 15:46:47 +01:00
|
|
|
|
module RplLang
|
2022-02-25 15:43:48 +01:00
|
|
|
|
module Words
|
2022-02-11 15:46:47 +01:00
|
|
|
|
module Store
|
2022-02-26 18:53:39 +01:00
|
|
|
|
include Types
|
|
|
|
|
|
2022-02-11 15:46:47 +01:00
|
|
|
|
def populate_dictionary
|
|
|
|
|
super
|
|
|
|
|
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category = 'Store'
|
|
|
|
|
|
2022-02-11 15:46:47 +01:00
|
|
|
|
@dictionary.add_word( ['▶', 'sto'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( content name -- ) store to variable',
|
|
|
|
|
proc do
|
2022-02-26 18:53:39 +01:00
|
|
|
|
args = stack_extract( [[RplName], :any] )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
|
@dictionary.add_var( args[0].value,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
args[1] )
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['rcl'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( name -- … ) push content of variable name onto stack',
|
|
|
|
|
proc do
|
2022-02-26 18:53:39 +01:00
|
|
|
|
args = stack_extract( [[RplName]] )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
|
content = @dictionary.lookup( args[0].value )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
|
|
|
|
@stack << content unless content.nil?
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['purge'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( name -- ) delete variable',
|
|
|
|
|
proc do
|
2022-02-26 18:53:39 +01:00
|
|
|
|
args = stack_extract( [[RplName]] )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
2022-02-26 18:53:39 +01:00
|
|
|
|
@dictionary.remove_var( args[0].value )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['vars'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( -- […] ) list variables',
|
|
|
|
|
proc do
|
2022-08-31 09:57:10 +02:00
|
|
|
|
@stack << Types.new_object( RplList, (@dictionary.vars.keys + @dictionary.local_vars_layers.reduce([]) { |memo, layer| memo + layer.keys })
|
|
|
|
|
.map { |name| Types.new_object( RplName, name ) } )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['clusr'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( -- ) delete all variables',
|
|
|
|
|
proc do
|
|
|
|
|
@dictionary.remove_all_vars
|
|
|
|
|
end )
|
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sto+'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( a n -- ) add content to variable\'s value',
|
2022-03-01 21:53:43 +01:00
|
|
|
|
Types.new_object( RplProgram, '« swap over rcl + swap sto »' ) )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sto-'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( a n -- ) subtract content to variable\'s value',
|
2022-03-01 21:53:43 +01:00
|
|
|
|
Types.new_object( RplProgram, '« swap over rcl swap - swap sto »' ) )
|
2021-12-08 12:46:57 +01:00
|
|
|
|
|
2022-02-11 15:46:47 +01:00
|
|
|
|
@dictionary.add_word( ['sto×', 'sto*'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( a n -- ) multiply content of variable\'s value',
|
2022-03-01 21:53:43 +01:00
|
|
|
|
Types.new_object( RplProgram, '« swap over rcl * swap sto »' ) )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sto÷', 'sto/'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( a n -- ) divide content of variable\'s value',
|
2022-03-01 21:53:43 +01:00
|
|
|
|
Types.new_object( RplProgram, '« swap over rcl swap / swap sto »' ) )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sneg'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( a n -- ) negate content of variable\'s value',
|
2022-02-28 11:40:47 +01:00
|
|
|
|
Types.new_object( RplProgram, '« dup rcl chs swap sto »' ) )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
|
|
|
|
|
@dictionary.add_word( ['sinv'],
|
2022-08-31 09:57:10 +02:00
|
|
|
|
category,
|
2022-02-11 15:46:47 +01:00
|
|
|
|
'( a n -- ) invert content of variable\'s value',
|
2022-02-28 11:40:47 +01:00
|
|
|
|
Types.new_object( RplProgram, '« dup rcl inv swap sto »' ) )
|
2022-02-11 15:46:47 +01:00
|
|
|
|
end
|
2021-12-07 16:51:33 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|