Code up and tested. Docs next!

This commit is contained in:
Peter Camilleri 2016-08-24 13:39:57 -04:00
parent 3ed61c2efe
commit c29f668e40
2 changed files with 13 additions and 5 deletions

View file

@ -228,6 +228,12 @@ class CompileLibraryTester < Minitest::Test
foorth_raises("'~ : foo ; ") foorth_raises("'~ : foo ; ")
foorth_raises("'~ !: foo ; ") foorth_raises("'~ !: foo ; ")
foorth_equal("Integer .: .riff self swap - ; 10 5 .riff", [-5])
foorth_equal("Integer '* .: .diff self swap - ; 10 5 .diff", [5])
foorth_equal("Integer .: minus self swap - ; 10 5 minus", [5])
foorth_equal("Integer '. .: rinus self swap - ; 10 5 rinus", [-5])
end end
end end

View file

@ -74,7 +74,7 @@ module XfOOrth
error "F13: The target of .: must be a class" unless target.is_a?(Class) error "F13: The target of .: must be a class" unless target.is_a?(Class)
name = vm.parser.get_word() name = vm.parser.get_word()
type = XfOOrth.name_to_type(name) type = XfOOrth.name_to_type(name, get_cast)
XfOOrth.validate_type(vm, type, name) XfOOrth.validate_type(vm, type, name)
XfOOrth.validate_string_method(type, target, name) XfOOrth.validate_string_method(type, target, name)
@ -132,7 +132,7 @@ module XfOOrth
if execute_mode? if execute_mode?
target = vm.pop target = vm.pop
name = vm.parser.get_word() name = vm.parser.get_word()
type = XfOOrth.name_to_type(name) type = XfOOrth.name_to_type(name, get_cast)
XfOOrth.validate_type(vm, type, name) XfOOrth.validate_type(vm, type, name)
XfOOrth.validate_string_method(type, target.class, name) XfOOrth.validate_string_method(type, target.class, name)
@ -212,8 +212,8 @@ module XfOOrth
#*name - The name of the method to be created. #*name - The name of the method to be created.
#<Returns> #<Returns>
#* The class of the spec to be used for this method. #* The class of the spec to be used for this method.
def self.name_to_type(name) def self.name_to_type(name, cast_spec=nil)
case name[0] normal_spec = case name[0]
when '.' when '.'
TosSpec TosSpec
@ -226,6 +226,8 @@ module XfOOrth
else else
NosSpec NosSpec
end end
cast_spec || normal_spec
end end
#Compare the new method's spec against the specs of other methods of the #Compare the new method's spec against the specs of other methods of the
@ -236,7 +238,7 @@ module XfOOrth
#*type - The class of the method to be created. #*type - The class of the method to be created.
#*name - The name of the method to be created. #*name - The name of the method to be created.
def self.validate_type(vm, type, name) def self.validate_type(vm, type, name)
if (spec = vm.context.map(name)) if (spec = vm.context.map(name, false))
if spec.class != type if spec.class != type
error "F90: Spec type mismatch #{spec.foorth_name} vs #{type.foorth_name}" error "F90: Spec type mismatch #{spec.foorth_name} vs #{type.foorth_name}"
end end