Massive smell cleanup done for now.

This commit is contained in:
Peter Camilleri 2016-09-21 15:57:07 -04:00
parent b46ae6258b
commit 998310ece1
5 changed files with 31 additions and 22 deletions

View file

@ -11,9 +11,30 @@ module XfOOrth
#* name - The string to be mapped.
#<br>Returns:
#* The specification that corresponds to the name or nil if none found.
def map(name, allow_defaults=:allow)
def map_with_defaults(name)
if (@symbol = SymbolMap.map(@name = name))
do_map_name(allow_defaults)
do_map_name ||
case @name[0]
when '.'
TosSpec.new(@name, @symbol, [:temp])
when '~'
SelfSpec.new(@name, @symbol, [:temp])
else
spec_error
end
end
end
#Map a name to a specification.
#<br>Parameters:
#* name - The string to be mapped.
#<br>Returns:
#* The specification that corresponds to the name or nil if none found.
def map_without_defaults(name)
if (@symbol = SymbolMap.map(@name = name))
do_map_name
end
end
@ -21,23 +42,13 @@ module XfOOrth
private
#Do a search of dictionaries based on the syntax of the name.
def do_map_name(allow_defaults)
def do_map_name
self[@symbol] ||
do_target_class_map ||
do_target_object_map ||
do_target_vm_map ||
do_object_class_map ||
do_global_map ||
(allow_defaults && case @name[0]
when '.'
TosSpec.new(@name, @symbol, [:temp])
when '~'
SelfSpec.new(@name, @symbol, [:temp])
else
spec_error
end)
do_global_map
end
#Do a search of the Object class for the item.

View file

@ -11,7 +11,7 @@ module XfOOrth
#* token - The token to receive the generated code.
#* word - The text of the word.
def generate_code(token, word)
if (spec = @context.map(word))
if (spec = @context.map_with_defaults(word))
token.add(spec.builds, spec.tags)
elsif (value = word.to_foorth_n)
token.add("vm.push(#{value.foorth_embed}); ", [:numeric])

View file

@ -240,7 +240,7 @@ module XfOOrth
#*type - The class of the method to be created.
#*name - The name of the method to be created.
def self.validate_type(vm, type, name)
if (spec = vm.context.map(name, false))
if (spec = vm.context.map_without_defaults(name))
if spec.class != type
error "F90: Spec type mismatch #{spec.foorth_name} vs #{type.foorth_name}"
end

View file

@ -1,3 +1 @@
lib/fOOrth/compiler/context/map_name.rb -- 1 warning:
[31]:ControlParameter: XfOOrth::Context#do_map_name is controlled by argument allow_defaults [https://github.com/troessner/reek/blob/master/docs/Control-Parameter.md]
1 total warning
0 total warnings

View file

@ -108,7 +108,7 @@ class ContextTester < Minitest::Test
name = 'b'
sym = XfOOrth::SymbolMap.add_entry(name)
context[sym] = XfOOrth::VmSpec.new(name, sym, [])
spec = context.map(name)
spec = context.map_with_defaults(name)
assert(spec.is_a?(XfOOrth::VmSpec))
end
@ -119,7 +119,7 @@ class ContextTester < Minitest::Test
name = '.c'
sym = XfOOrth::SymbolMap.add_entry(name)
mk[sym] = XfOOrth::TosSpec.new(name, sym, [])
spec = context.map(name)
spec = context.map_with_defaults(name)
assert(spec.is_a?(XfOOrth::TosSpec))
end
@ -130,7 +130,7 @@ class ContextTester < Minitest::Test
name = '.d'
sym = XfOOrth::SymbolMap.add_entry(name)
mk[sym] = XfOOrth::TosSpec.new(name, sym, [])
spec = context.map(name)
spec = context.map_with_defaults(name)
assert(spec.is_a?(XfOOrth::TosSpec))
end