From 1eb65258c557a085e74e1318b189eae65e06af34 Mon Sep 17 00:00:00 2001 From: fogus Date: Thu, 9 Sep 2010 12:31:38 -0400 Subject: [PATCH] Fixed a bug in the way that function existing words were being looked up during a function definition. --- README.md | 5 +++++ src/rforth.rb | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c273870..09b1497 100644 --- a/README.md +++ b/README.md @@ -11,3 +11,8 @@ A simple Forth interpreter in Ruby (1.9). . 9 + : sq dup * ; + + 2 sq + . + 4 diff --git a/src/rforth.rb b/src/rforth.rb index 6957eda..4fbb619 100644 --- a/src/rforth.rb +++ b/src/rforth.rb @@ -51,7 +51,7 @@ class RForth @stack << b << a << c end - # quotations + # functions d.word(':') { define_word } # math @@ -72,6 +72,7 @@ class RForth # aux words d.word('.') { @s_out.print( "#{@stack.pop}\n" ) } d.word('.S') { @s_out.print( "#{@stack}\n" ) } + d.word('.D') { pp @dictionary } d.word('cr') { @s_out.puts } d.word('bye') { exit } @@ -83,7 +84,7 @@ class RForth blocks = [] while (word = read_word) break if word == ';' - entry = @dictionary.word(word) + entry = @dictionary[word] raise "no such word: #{word}" unless entry if entry[:immediate] entry[:block].call @@ -93,7 +94,9 @@ class RForth end @dictionary.word(name) do - blocks.each {|b| b.call} + blocks.each do |b| + b.call + end end end