|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
# ==============================================================================
#
# RubyFORTH -- Copyright (C) 2007-8, Marc Simpson (GPL).
#
# Vocabularies -- composed of Forth and Compiler wordlists.
#
# ==============================================================================
require 'stack.rb'
# --[ Vocabulary Class ]--------------------------------------------------------
class Vocabulary < Array
def initialize(name)
@vocab_name = name
super()
self[0] = {} ; self[1] = {}
self
end
def to_s
"vocab{" + @vocab_name + "}"
end
end
# --[ Vocabulary Storage ]------------------------------------------------------
$vocabularies = Stack.new(16)
# --[ Core words ]--------------------------------------------------------------
def current_vocab ; $vocabularies.tos ; end
def vocabulary_order ; $vocabularies.contents ; end
def push_vocab(v) ; $vocabularies.push(v) ; end
def pop_vocab ; $vocabularies.pop ; end
# Search for 'name' in all vocabularies, with the specified wordlist index.
#
def find_word(name, wordlist_type)
found_xt = nil
0.upto($vocabularies.depth()-1) do |i|
vocab = $vocabularies.nth(i)
wid = vocab[wordlist_type]
found_xt = wid[name]
break if found_xt
end
found_xt
end
def find_xt(xt, wordlist_type)
found_name = nil
0.upto($vocabularies.depth()-1) do |i|
vocab = $vocabularies.nth(i)
wid = vocab[wordlist_type]
found_name = wid.index(xt)
break if found_name
end
found_name
end
def forth_words ; current_vocab[0] ; end
def compiler_words ; current_vocab[1] ; end
def forth_word(name) ; find_word(name, 0) ; end
def compiler_word(name) ; find_word(name, 1) ; end
def forth_header(xt) ; find_xt(xt, 0) ; end
def compiler_header(xt) ; find_xt(xt, 1) ; end
# ------------------------------------------------------------------------------