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
|
# File 'lib/rpl/words/branch.rb', line 8
def populate_dictionary
super
@dictionary.add_word( ['ift'],
'Branch',
'( t pt -- … ) eval pt or not based on the value of boolean t',
Types.new_object( RplProgram, '« « nop » ifte »' ) )
@dictionary.add_word( ['ifte'],
'Branch',
'( t pt pf -- … ) eval pt or pf based on the value of boolean t',
proc do
args = ( [:any, :any, [RplBoolean]] )
run( args[ args[2].value ? 1 : 0 ].value )
end )
@dictionary.add_word( ['times'],
'Branch',
'( p n -- … ) eval p n times while pushing counter on stack before',
proc do
args = ( [[RplNumeric], :any] )
args[0].value.to_i.times do |counter|
@stack << Types.new_object( RplNumeric, counter )
run( args[1].value )
end
end )
@dictionary.add_word( ['loop'],
'Branch',
'( p n1 n2 -- … ) eval p looping from n1 to n2 while pushing counter on stack before',
proc do
args = ( [[RplNumeric], [RplNumeric], :any] )
((args[1].value.to_i)..(args[0].value.to_i)).each do |counter|
@stack << Types.new_object( RplNumeric, counter )
run( args[2].value )
end
end )
end
|