From 60a1d68fb071bc5a239f1076225da650614c40d6 Mon Sep 17 00:00:00 2001 From: fogus Date: Thu, 9 Sep 2010 09:06:08 -0400 Subject: [PATCH] Added two essential words: dup and drop --- src/rforth.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/rforth.rb b/src/rforth.rb index 4423a16..2071f02 100644 --- a/src/rforth.rb +++ b/src/rforth.rb @@ -29,11 +29,13 @@ class RForth def initial_dictionary d = Dictionary.new - d.word(':') { define_word } - d.word('.'){ @s_out.print( @stack.pop ) } - d.word('cr') { @s_out.puts } - d.word('+') { @stack << (@stack.pop + @stack.pop) } - d.word('*') { @stack << (@stack.pop * @stack.pop) } + d.word('dup') { @stack << @stack.last } + d.word('drop') { @stack.pop } + d.word(':') { define_word } + d.word('.') { @s_out.print( "#{@stack.pop}\n" ) } + d.word('cr') { @s_out.puts } + d.word('+') { @stack << (@stack.pop + @stack.pop) } + d.word('*') { @stack << (@stack.pop * @stack.pop) } d.word('-') do a = @stack.pop b = @stack.pop @@ -113,7 +115,7 @@ class RForth end def is_space?( ch ) - /\W/ =~ ch + /\W/ =~ ch.chr end def run