extend type inference for dsl
and finally test it
This commit is contained in:
parent
308996bf8e
commit
c9d8f750e5
@ -50,13 +50,20 @@ module Risc
|
|||||||
# infer the type from a symbol. In the simplest case the sybbol is the class name
|
# infer the type from a symbol. In the simplest case the sybbol is the class name
|
||||||
# But in building sometimes variations are needed, so next_message or caller work
|
# But in building sometimes variations are needed, so next_message or caller work
|
||||||
# too (and return Message)
|
# too (and return Message)
|
||||||
|
# A general "_reg" or "_obj" at the end of the name will be removed
|
||||||
# An error is raised if the symbol/object can not be inferred
|
# An error is raised if the symbol/object can not be inferred
|
||||||
def infer_type( name )
|
def infer_type( name )
|
||||||
name = :word if name == :name
|
as_string = name.to_s
|
||||||
name = :message if name == :next_message
|
parts = as_string.split("_")
|
||||||
name = :message if name == :caller
|
if(parts.last == "reg" or parts.last == "obj")
|
||||||
name = :named_list if name == :arguments
|
parts.pop
|
||||||
sym = name.to_s.camelise.to_sym
|
as_string = parts.join("_")
|
||||||
|
end
|
||||||
|
as_string = "word" if as_string == "name"
|
||||||
|
as_string = "message" if as_string == "next_message"
|
||||||
|
as_string = "message" if as_string == "caller"
|
||||||
|
as_string = "named_list" if as_string == "arguments"
|
||||||
|
sym = as_string.camelise.to_sym
|
||||||
clazz = Parfait.object_space.get_class_by_name(sym)
|
clazz = Parfait.object_space.get_class_by_name(sym)
|
||||||
raise "Not implemented/found object #{name}:#{sym}" unless clazz
|
raise "Not implemented/found object #{name}:#{sym}" unless clazz
|
||||||
return clazz.instance_type
|
return clazz.instance_type
|
||||||
|
@ -98,20 +98,4 @@ module Risc
|
|||||||
assert_equal :Space , op.left.type.class_name
|
assert_equal :Space , op.left.type.class_name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
class TestCompilerBuilder < MiniTest::Test
|
|
||||||
|
|
||||||
def setup
|
|
||||||
Parfait.boot!
|
|
||||||
Risc.boot!
|
|
||||||
@init = Parfait.object_space.get_init
|
|
||||||
@compiler = Risc::MethodCompiler.new( @init )
|
|
||||||
@builder = @compiler.compiler_builder(@init)
|
|
||||||
end
|
|
||||||
def test_inserts_built
|
|
||||||
r1 = RegisterValue.new(:r1 , :Space)
|
|
||||||
@builder.build{ space << r1 }
|
|
||||||
assert_equal Transfer , @compiler.risc_instructions.next.class
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
20
test/risc/test_builder1.rb
Normal file
20
test/risc/test_builder1.rb
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
require_relative "../helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestCompilerBuilder < MiniTest::Test
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Parfait.boot!
|
||||||
|
Risc.boot!
|
||||||
|
@init = Parfait.object_space.get_init
|
||||||
|
@compiler = Risc::MethodCompiler.new( @init )
|
||||||
|
@builder = @compiler.compiler_builder(@init)
|
||||||
|
end
|
||||||
|
def test_inserts_built
|
||||||
|
r1 = RegisterValue.new(:r1 , :Space)
|
||||||
|
@builder.build{ space << r1 }
|
||||||
|
assert_equal Transfer , @compiler.risc_instructions.next.class
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
39
test/risc/test_builder2.rb
Normal file
39
test/risc/test_builder2.rb
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
require_relative "../helper"
|
||||||
|
|
||||||
|
module Risc
|
||||||
|
class TestBuilderInfer < MiniTest::Test
|
||||||
|
|
||||||
|
def setup
|
||||||
|
Parfait.boot!
|
||||||
|
Risc.boot!
|
||||||
|
@init = Parfait.object_space.get_init
|
||||||
|
@compiler = Risc::MethodCompiler.new( @init )
|
||||||
|
@builder = @compiler.compiler_builder(@init)
|
||||||
|
end
|
||||||
|
def test_list
|
||||||
|
assert_equal :List , @builder.infer_type(:list).class_name
|
||||||
|
end
|
||||||
|
def test_name
|
||||||
|
assert_equal :Word , @builder.infer_type(:name).class_name
|
||||||
|
end
|
||||||
|
def test_word
|
||||||
|
assert_equal :Word , @builder.infer_type(:word).class_name
|
||||||
|
end
|
||||||
|
def test_caller
|
||||||
|
assert_equal :Message , @builder.infer_type(:caller).class_name
|
||||||
|
end
|
||||||
|
def test_caller_reg
|
||||||
|
assert_equal :Message , @builder.infer_type(:caller_reg).class_name
|
||||||
|
end
|
||||||
|
def test_caller_obj
|
||||||
|
assert_equal :Message , @builder.infer_type(:caller_obj).class_name
|
||||||
|
end
|
||||||
|
def test_message
|
||||||
|
assert_equal :Message , @builder.infer_type(:message).class_name
|
||||||
|
end
|
||||||
|
def test_next_message
|
||||||
|
assert_equal :Message , @builder.infer_type(:next_message).class_name
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user