diff --git a/lib/fOOrth/compiler/console.rb b/lib/fOOrth/compiler/console.rb
index e77ffe6..fc86132 100644
--- a/lib/fOOrth/compiler/console.rb
+++ b/lib/fOOrth/compiler/console.rb
@@ -8,7 +8,6 @@ module XfOOrth
#for fOOrth commands and source code. The readline facility is used to enable
#editing and command history and retrieval.
class Console
- include Readline
include ReadPoint
#Initialize a new console command source.
@@ -25,7 +24,7 @@ module XfOOrth
#
Returns
#* The next character of user input as a string.
def get
- read { puts; readline(prompt, true).rstrip }
+ read { puts; Readline.readline(prompt, true).rstrip }
end
#Has the scanning of the text reached the end of input?
diff --git a/lib/fOOrth/core.rb b/lib/fOOrth/core.rb
index e66d506..b68b41c 100644
--- a/lib/fOOrth/core.rb
+++ b/lib/fOOrth/core.rb
@@ -1,9 +1,11 @@
# coding: utf-8
require_relative 'compiler/word_specs'
+
require_relative 'core/object'
require_relative 'core/class'
require_relative 'core/virtual_machine'
+require_relative 'core/proxy'
#* core.rb - The fOOrth language OO core.
module XfOOrth
@@ -62,9 +64,9 @@ module XfOOrth
#Predefine the default implementation of the init method. All classes
#inherit this simple method.
name = '.init'
- sym = SymbolMap.add_entry(name, :init)
+ sym = SymbolMap.add_entry(name, :foorth_init)
spec = MethodWordSpec.new(name, sym, [], &lambda {|vm| })
- @object_class.add_shared_method(:init, spec)
+ @object_class.add_shared_method(:foorth_init, spec)
#The Class class is a child of the Object class.
@object_class.children['Class'] = @class_class
diff --git a/lib/fOOrth/core/class.rb b/lib/fOOrth/core/class.rb
index 94f0aad..243db7d 100644
--- a/lib/fOOrth/core/class.rb
+++ b/lib/fOOrth/core/class.rb
@@ -80,7 +80,7 @@ module XfOOrth
#* vm - The current fOOrth virtual machine.
def create_foorth_instance(vm)
obj = @instance_template.new
- obj.init(vm)
+ obj.foorth_init(vm)
obj
end
diff --git a/lib/fOOrth/core/proxy.rb b/lib/fOOrth/core/proxy.rb
new file mode 100644
index 0000000..3e5b040
--- /dev/null
+++ b/lib/fOOrth/core/proxy.rb
@@ -0,0 +1,38 @@
+# coding: utf-8
+
+#require_relative 'exclusive'
+require_relative 'shared_cache'
+require_relative 'method_missing'
+require_relative 'shared'
+
+#* core/proxy.rb - A module to allow existing Ruby classes to serve as fOOrth
+# classes as well. This is done via a proxy mechanism.
+module XfOOrth
+
+ #Wrap a proxy around an existing Ruby class so that it acts as a fOOrth class.
+ #
Parameters:
+ #* target_class - The Ruby class to be wrapped.
+ #* foorth_parent - The fOOrth class that serves as parent.
+ #* exclusives - Are exclusive methods to be allowed?
+ #
Returns:
+ #* The newly created proxy class.
+ def self.create_proxy(target_class, foorth_parent, exclusives=false)
+ target_class.define_singleton_method(:foorth_parent) {foorth_parent}
+ target_class.define_singleton_method(:foorth_class) {XfOOrth.class_class}
+ target_class.define_singleton_method(:shared) {@shared ||= {}}
+
+ target_class.send(:define_method, :foorth_class,
+ &lambda {target_class})
+
+ target_class.send(:define_method, :name,
+ &lambda {"#{foorth_class.name} instance <#{@name}>."})
+
+ target_class.extend(SharedCache)
+ target_class.extend(Shared)
+ target_class.send(:include, MethodMissing)
+
+ target_class
+ end
+
+
+end
diff --git a/sire.rb b/sire.rb
index 4da5d00..aeb393a 100644
--- a/sire.rb
+++ b/sire.rb
@@ -4,7 +4,7 @@
require 'readline'
require 'pp'
-include Readline
+
class Object
#Generate the class lineage of the object.
@@ -24,6 +24,24 @@ class Object
end
end
+module Foobar
+ def hello
+ puts 'Hello!'
+ self
+ end
+
+ Fixnum.send(:include, self)
+end
+
+module Bluebar
+ def ahoy
+ puts 'Ahoy!'
+ self
+ end
+
+ Fixnum.extend(self)
+end
+
class SIRE
#Set up the interactive session.
def initialize
@@ -45,7 +63,7 @@ class SIRE
def run_sire
until @done
begin
- line = readline('SIRE>', true)
+ line = Readline.readline('SIRE>', true)
@running = true
result = eval line
@running = false
diff --git a/tests/symbol_map_tests.rb b/tests/symbol_map_tests.rb
index a2b20b9..c2a9bc6 100644
--- a/tests/symbol_map_tests.rb
+++ b/tests/symbol_map_tests.rb
@@ -41,8 +41,8 @@ class SymbolMapTester < MiniTest::Unit::TestCase
#Test the special mappings facility
def test_special_mappings
- assert_equal(XfOOrth::SymbolMap.map('.init'), :init)
- assert_equal(XfOOrth::SymbolMap.unmap(:init), ['.init'])
+ assert_equal(XfOOrth::SymbolMap.map('.init'), :foorth_init)
+ assert_equal(XfOOrth::SymbolMap.unmap(:foorth_init), ['.init'])
assert_raises(XfOOrth::XfOOrthError) do
XfOOrth::SymbolMap.add_entry('.init', :evil_method)