Added swap. Fixed my bug introduced in . (popping instead of peaking)

This commit is contained in:
fogus 2010-09-09 10:58:34 -04:00
parent 60a1d68fb0
commit b583b7f05b

View file

@ -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) }