fix constant propagation through the layers
so they can end up in the binary
This commit is contained in:
parent
63dfee0978
commit
bb1d1495db
@ -6,6 +6,11 @@ module Mom
|
||||
@method_compilers = Risc::Builtin.boot_functions + compilers
|
||||
end
|
||||
|
||||
# collects constants from all compilers into one array
|
||||
def constants
|
||||
@method_compilers.inject([]){|sum ,comp| sum + comp.constants }
|
||||
end
|
||||
|
||||
# Translate code to whatever cpu is specified.
|
||||
# Currently only :arm and :interpret
|
||||
#
|
||||
@ -15,7 +20,7 @@ module Mom
|
||||
platform_sym = platform_sym.to_s.capitalize
|
||||
platform = Risc::Platform.for(platform_sym)
|
||||
assemblers = translate_methods( platform.translator )
|
||||
Risc::Linker.new(platform , assemblers)
|
||||
Risc::Linker.new(platform , assemblers , constants)
|
||||
end
|
||||
|
||||
# go through all methods and translate them to cpu, given the translator
|
||||
@ -35,7 +40,7 @@ module Mom
|
||||
cpu_instructions << cpu if cpu
|
||||
nekst = nekst.next
|
||||
end
|
||||
Risc::Assembler.new(compiler.method , cpu_instructions , compiler.constants)
|
||||
Risc::Assembler.new(compiler.method , cpu_instructions )
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -1,10 +1,10 @@
|
||||
module Risc
|
||||
class Assembler
|
||||
attr_reader :method , :instructions , :constants
|
||||
def initialize( method , instructions, constants)
|
||||
attr_reader :method , :instructions
|
||||
|
||||
def initialize( method , instructions)
|
||||
@method = method
|
||||
@instructions = instructions
|
||||
@constants = constants
|
||||
total = instructions.total_byte_length / 4 + 1
|
||||
method.binary.extend_to( total )
|
||||
end
|
||||
|
@ -13,7 +13,7 @@ module Risc
|
||||
include Util::Logging
|
||||
log_level :info
|
||||
|
||||
def initialize(platform , assemblers)
|
||||
def initialize(platform , assemblers , constants)
|
||||
if(platform.is_a?(Symbol))
|
||||
platform = platform.to_s.capitalize
|
||||
platform = Risc::Platform.for(platform)
|
||||
@ -21,7 +21,7 @@ module Risc
|
||||
raise "Platform must be platform, not #{platform.class}" unless platform.is_a?(Platform)
|
||||
@platform = platform
|
||||
@assemblers = assemblers
|
||||
@constants = []
|
||||
@constants = constants
|
||||
@cpu_init = cpu_init_init
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,7 @@ module Mom
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
@comp = compile_mom( "class Test ; def main(); return 1; end; end;")
|
||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
||||
end
|
||||
|
||||
def test_class
|
||||
@ -15,6 +15,12 @@ module Mom
|
||||
def test_compilers
|
||||
assert_equal 24 , @comp.method_compilers.length
|
||||
end
|
||||
def test_returns_constants
|
||||
assert_equal Array , @comp.constants.class
|
||||
end
|
||||
def test_has_constant
|
||||
assert_equal "Hi" , @comp.constants.first.to_string
|
||||
end
|
||||
def test_has_translate
|
||||
assert @comp.translate(:interpreter)
|
||||
end
|
||||
|
@ -6,13 +6,22 @@ module Mom
|
||||
|
||||
def setup
|
||||
Parfait.boot!
|
||||
@comp = compile_mom( "class Test ; def main(); return 1; end; end;")
|
||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
||||
@linker = @comp.translate(:interpreter)
|
||||
end
|
||||
|
||||
def test_translate_class
|
||||
assert_equal Risc::Linker , @linker.class
|
||||
end
|
||||
def test_linker_has_constants
|
||||
assert_equal Array , @linker.constants.class
|
||||
end
|
||||
def test_linker_constants_not_empty
|
||||
assert !@linker.constants.empty?
|
||||
end
|
||||
def test_linker_constants_contains_hi
|
||||
assert @linker.constants.include?("Hi")
|
||||
end
|
||||
def test_translate_platform
|
||||
assert_kind_of Risc::Platform , @linker.platform
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user