mirror of
https://github.com/russolsen/rforth
synced 2024-12-26 09:58:27 +01:00
Added swap. Fixed my bug introduced in . (popping instead of peaking)
This commit is contained in:
parent
60a1d68fb0
commit
b583b7f05b
1 changed files with 6 additions and 1 deletions
|
@ -31,8 +31,13 @@ class RForth
|
||||||
d = Dictionary.new
|
d = Dictionary.new
|
||||||
d.word('dup') { @stack << @stack.last }
|
d.word('dup') { @stack << @stack.last }
|
||||||
d.word('drop') { @stack.pop }
|
d.word('drop') { @stack.pop }
|
||||||
|
d.word('swap') do
|
||||||
|
a = @stack.pop
|
||||||
|
b = @stack.pop
|
||||||
|
@stack << a << b
|
||||||
|
end
|
||||||
d.word(':') { define_word }
|
d.word(':') { define_word }
|
||||||
d.word('.') { @s_out.print( "#{@stack.pop}\n" ) }
|
d.word('.') { @s_out.print( "#{@stack.last}\n" ) }
|
||||||
d.word('cr') { @s_out.puts }
|
d.word('cr') { @s_out.puts }
|
||||||
d.word('+') { @stack << (@stack.pop + @stack.pop) }
|
d.word('+') { @stack << (@stack.pop + @stack.pop) }
|
||||||
d.word('*') { @stack << (@stack.pop * @stack.pop) }
|
d.word('*') { @stack << (@stack.pop * @stack.pop) }
|
||||||
|
|
Loading…
Reference in a new issue