propagate constants from block_compiler up
up to method_compiler, where they are collected by mom_compiler (and included in binary)
This commit is contained in:
parent
81cc109d1e
commit
4b4528abb2
@ -10,6 +10,11 @@ module Risc
|
|||||||
super(method)
|
super(method)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
#include block_compilers constants
|
||||||
|
def constants
|
||||||
|
block_compilers.inject(@constants.dup){|all, compiler| all += compiler.constants}
|
||||||
|
end
|
||||||
|
|
||||||
def source_name
|
def source_name
|
||||||
"#{@callable.self_type.name}.#{@callable.name}"
|
"#{@callable.self_type.name}.#{@callable.name}"
|
||||||
end
|
end
|
||||||
@ -106,12 +111,6 @@ module Risc
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# add a constant (which get created during compilation and need to be linked)
|
|
||||||
def add_constant(const)
|
|
||||||
raise "Must be Parfait #{const}" unless const.is_a?(Parfait::Object)
|
|
||||||
@constants << const
|
|
||||||
end
|
|
||||||
|
|
||||||
# add a risc instruction after the current (insertion point)
|
# add a risc instruction after the current (insertion point)
|
||||||
# the added instruction will become the new insertion point
|
# the added instruction will become the new insertion point
|
||||||
def add_code( instruction )
|
def add_code( instruction )
|
||||||
|
@ -6,7 +6,7 @@ module Mom
|
|||||||
|
|
||||||
def setup
|
def setup
|
||||||
Parfait.boot!
|
Parfait.boot!
|
||||||
@comp = compile_mom( "class Test ; def main(); return 'Hi'; end; end;")
|
@comp = compile_mom( "class Test ; def main(); main{return 'Ho'};return 'Hi'; end; end;")
|
||||||
@linker = @comp.translate(:interpreter)
|
@linker = @comp.translate(:interpreter)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -22,6 +22,9 @@ module Mom
|
|||||||
def test_linker_constants_contains_hi
|
def test_linker_constants_contains_hi
|
||||||
assert @linker.constants.include?("Hi")
|
assert @linker.constants.include?("Hi")
|
||||||
end
|
end
|
||||||
|
def test_linker_constants_contains_ho
|
||||||
|
assert @linker.constants.include?("Ho")
|
||||||
|
end
|
||||||
def test_translate_platform
|
def test_translate_platform
|
||||||
assert_kind_of Risc::Platform , @linker.platform
|
assert_kind_of Risc::Platform , @linker.platform
|
||||||
end
|
end
|
||||||
|
@ -64,14 +64,21 @@ module Risc
|
|||||||
assert_equal 1 , method.frame_type.variable_index(:local)
|
assert_equal 1 , method.frame_type.variable_index(:local)
|
||||||
assert_equal 2 , method.frame_type.variable_index(:a)
|
assert_equal 2 , method.frame_type.variable_index(:a)
|
||||||
end
|
end
|
||||||
def test_has_constant
|
def constant_setup(input)
|
||||||
input = in_Test("def meth; return 'Hi';end")
|
mom = RubyX::RubyXCompiler.new(in_Test(input)).ruby_to_mom
|
||||||
mom = RubyX::RubyXCompiler.new(input).ruby_to_mom
|
|
||||||
assert_equal Mom::MomCompiler , mom.class
|
assert_equal Mom::MomCompiler , mom.class
|
||||||
compiler = mom.method_compilers.first
|
compiler = mom.method_compilers.first
|
||||||
assert_equal MethodCompiler , compiler.class
|
assert_equal MethodCompiler , compiler.class
|
||||||
|
compiler
|
||||||
|
end
|
||||||
|
def test_has_method_constant
|
||||||
|
compiler = constant_setup("def meth; return 'Hi';end")
|
||||||
assert compiler.constants.include?("Hi")
|
assert compiler.constants.include?("Hi")
|
||||||
end
|
end
|
||||||
|
def test_has_block_constant
|
||||||
|
compiler = constant_setup("def meth; meth{return 'Ho'};return 'Hi';end")
|
||||||
|
assert compiler.constants.include?("Ho")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user