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