Added the .to_s and .strlen methods.

This commit is contained in:
Peter Camilleri 2014-12-03 14:10:20 -05:00
parent 53e0a3774c
commit 730c4ada7c
3 changed files with 22 additions and 0 deletions

View file

@ -35,4 +35,11 @@ class ObjectLibraryTester < MiniTest::Unit::TestCase
foorth_equal('"Foobar" .name', ['String instance'])
end
def test_getting_an_object_as_a_string
foorth_equal("4 .to_s", ['4'])
foorth_equal("Object .to_s", ['Object'])
foorth_equal("VirtualMachine .to_s", ['VirtualMachine'])
end
end

View file

@ -8,6 +8,11 @@ module XfOOrth
Class.create_shared_method('.new', TosSpec, [],
&lambda {|vm| vm.push(self.create_foorth_instance(vm)); })
#Get the class as a string.
# [cls] .to_s ["cls as a string"]
Class.create_shared_method('.to_s', TosSpec, [],
&lambda {|vm| vm.push(self.foorth_name)})
#The .parent_class method. Retrieves the parent class of a class.
# [a_class] .parent_class [parent_class or nil]
Class.create_shared_method('.parent_class', TosSpec, [],

View file

@ -18,6 +18,16 @@ module XfOOrth
Object.create_shared_method('.name', TosSpec, [],
&lambda {|vm| vm.push(self.foorth_name)})
#Get the object as a string.
# [obj] .to_s ["obj as a string"]
Object.create_shared_method('.to_s', TosSpec, [],
&lambda {|vm| vm.push(self.to_s)})
#Get the length of the object as a string.
# [obj] .strlen [n]; the length of the object's to_s string
Object.create_shared_method('.strlen', TosSpec, [],
&lambda {|vm| vm.push(self.to_foorth_s.length)})
# Some boolean operation words.
# [b,a] && [b&a]
Object.create_shared_method('&&', TosSpec, [],