8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/rpl/words/store.rb', line 8
def populate_dictionary
super
category = 'Store'
@dictionary.add_word!( ['▶', 'sto'],
category,
'( content name -- ) store to variable',
proc do
args = ( [[RplName], :any] )
@dictionary.add_var!( args[0].value,
args[1] )
end )
@dictionary.add_word!( ['rcl'],
category,
'( name -- … ) push content of variable name onto stack',
proc do
args = ( [[RplName]] )
content = @dictionary.lookup( args[0].value )
@stack << content unless content.nil?
end )
@dictionary.add_word!( ['purge'],
category,
'( name -- ) delete variable',
proc do
args = ( [[RplName]] )
@dictionary.remove_var!( args[0].value )
end )
@dictionary.add_word!( ['vars'],
category,
'( -- […] ) list variables',
proc do
@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 ) } )
end )
@dictionary.add_word!( ['clusr'],
category,
'( -- ) delete all variables',
proc do
@dictionary.remove_all_vars!
end )
@dictionary.add_word!( ['sto+'],
category,
'( a n -- ) add content to variable\'s value',
Types.new_object( RplProgram, '« swap over rcl + swap sto »' ) )
@dictionary.add_word!( ['sto-'],
category,
'( a n -- ) subtract content to variable\'s value',
Types.new_object( RplProgram, '« swap over rcl swap - swap sto »' ) )
@dictionary.add_word!( ['sto×', 'sto*'],
category,
'( a n -- ) multiply content of variable\'s value',
Types.new_object( RplProgram, '« swap over rcl * swap sto »' ) )
@dictionary.add_word!( ['sto÷', 'sto/'],
category,
'( a n -- ) divide content of variable\'s value',
Types.new_object( RplProgram, '« swap over rcl swap / swap sto »' ) )
@dictionary.add_word!( ['sneg'],
category,
'( a n -- ) negate content of variable\'s value',
Types.new_object( RplProgram, '« dup rcl chs swap sto »' ) )
@dictionary.add_word!( ['sinv'],
category,
'( a n -- ) invert content of variable\'s value',
Types.new_object( RplProgram, '« dup rcl inv swap sto »' ) )
end
|