mirror of
https://github.com/russolsen/rforth
synced 2024-12-27 09:59:00 +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
|
9
|
||||||
|
|
||||||
|
: sq dup * ;
|
||||||
|
|
||||||
|
2 sq
|
||||||
|
.
|
||||||
|
4
|
||||||
|
|
|
@ -51,7 +51,7 @@ class RForth
|
||||||
@stack << b << a << c
|
@stack << b << a << c
|
||||||
end
|
end
|
||||||
|
|
||||||
# quotations
|
# functions
|
||||||
d.word(':') { define_word }
|
d.word(':') { define_word }
|
||||||
|
|
||||||
# math
|
# math
|
||||||
|
@ -72,6 +72,7 @@ class RForth
|
||||||
# aux words
|
# aux words
|
||||||
d.word('.') { @s_out.print( "#{@stack.pop}\n" ) }
|
d.word('.') { @s_out.print( "#{@stack.pop}\n" ) }
|
||||||
d.word('.S') { @s_out.print( "#{@stack}\n" ) }
|
d.word('.S') { @s_out.print( "#{@stack}\n" ) }
|
||||||
|
d.word('.D') { pp @dictionary }
|
||||||
d.word('cr') { @s_out.puts }
|
d.word('cr') { @s_out.puts }
|
||||||
d.word('bye') { exit }
|
d.word('bye') { exit }
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ class RForth
|
||||||
blocks = []
|
blocks = []
|
||||||
while (word = read_word)
|
while (word = read_word)
|
||||||
break if word == ';'
|
break if word == ';'
|
||||||
entry = @dictionary.word(word)
|
entry = @dictionary[word]
|
||||||
raise "no such word: #{word}" unless entry
|
raise "no such word: #{word}" unless entry
|
||||||
if entry[:immediate]
|
if entry[:immediate]
|
||||||
entry[:block].call
|
entry[:block].call
|
||||||
|
@ -93,7 +94,9 @@ class RForth
|
||||||
end
|
end
|
||||||
|
|
||||||
@dictionary.word(name) do
|
@dictionary.word(name) do
|
||||||
blocks.each {|b| b.call}
|
blocks.each do |b|
|
||||||
|
b.call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue