mirror of
https://github.com/russolsen/rforth
synced 2024-12-26 09:58:27 +01:00
Fixed a bug in the way that function existing words were being looked up during a function definition.
This commit is contained in:
parent
90eb787162
commit
1eb65258c5
2 changed files with 11 additions and 3 deletions
|
@ -11,3 +11,8 @@ A simple Forth interpreter in Ruby (1.9).
|
|||
.
|
||||
9
|
||||
|
||||
: sq dup * ;
|
||||
|
||||
2 sq
|
||||
.
|
||||
4
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue