Added two essential words: dup and drop

This commit is contained in:
fogus 2010-09-09 09:06:08 -04:00
parent 8ef30fbc11
commit 60a1d68fb0

View file

@ -29,11 +29,13 @@ class RForth
def initial_dictionary def initial_dictionary
d = Dictionary.new d = Dictionary.new
d.word(':') { define_word } d.word('dup') { @stack << @stack.last }
d.word('.'){ @s_out.print( @stack.pop ) } d.word('drop') { @stack.pop }
d.word('cr') { @s_out.puts } d.word(':') { define_word }
d.word('+') { @stack << (@stack.pop + @stack.pop) } d.word('.') { @s_out.print( "#{@stack.pop}\n" ) }
d.word('*') { @stack << (@stack.pop * @stack.pop) } d.word('cr') { @s_out.puts }
d.word('+') { @stack << (@stack.pop + @stack.pop) }
d.word('*') { @stack << (@stack.pop * @stack.pop) }
d.word('-') do d.word('-') do
a = @stack.pop a = @stack.pop
b = @stack.pop b = @stack.pop
@ -113,7 +115,7 @@ class RForth
end end
def is_space?( ch ) def is_space?( ch )
/\W/ =~ ch /\W/ =~ ch.chr
end end
def run def run