make compiler default to compiling Space.main
This commit is contained in:
parent
ece017fa86
commit
681b53cc4c
@ -2,7 +2,7 @@ require_relative "tree"
|
|||||||
|
|
||||||
module Typed
|
module Typed
|
||||||
|
|
||||||
CompilerModules = [ "assignment" , "basic_values" , "call_site",
|
CompilerModules = [ "assignment" , "basic_values" , "call_site",
|
||||||
"class_statement" , "collections" , "field_def" , "field_access",
|
"class_statement" , "collections" , "field_def" , "field_access",
|
||||||
"function_statement" , "if_statement" , "name_expression" ,
|
"function_statement" , "if_statement" , "name_expression" ,
|
||||||
"operator_expression" , "return_statement", "statement_list",
|
"operator_expression" , "return_statement", "statement_list",
|
||||||
@ -56,10 +56,15 @@ module Typed
|
|||||||
|
|
||||||
def initialize( method = nil )
|
def initialize( method = nil )
|
||||||
@regs = []
|
@regs = []
|
||||||
return unless method
|
if method
|
||||||
@method = method
|
@method = method
|
||||||
@type = method.for_type
|
@type = method.for_type
|
||||||
@current = method.instructions
|
else
|
||||||
|
@type = Parfait::Space.object_space.get_type()
|
||||||
|
@method = @type.get_instance_method( :main )
|
||||||
|
@method = @type.create_instance_method( :main ,{}) unless @method
|
||||||
|
end
|
||||||
|
@current = @method.instructions
|
||||||
end
|
end
|
||||||
attr_reader :type , :method
|
attr_reader :type , :method
|
||||||
|
|
||||||
|
@ -52,10 +52,9 @@ module Typed
|
|||||||
end
|
end
|
||||||
def do_call( type , statement )
|
def do_call( type , statement )
|
||||||
name = statement.name
|
name = statement.name
|
||||||
#puts "type #{type.inpect}"
|
#puts "type #{type.inspect}"
|
||||||
raise "No such class" unless type
|
|
||||||
method = type.get_instance_method(name)
|
method = type.get_instance_method(name)
|
||||||
#puts Register.machine.space.get_class_by_name(:Integer).method_names.to_a
|
#puts type.method_names.to_a
|
||||||
raise "Method not implemented #{type.inspect}.#{name}" unless method
|
raise "Method not implemented #{type.inspect}.#{name}" unless method
|
||||||
Register.issue_call( self , method )
|
Register.issue_call( self , method )
|
||||||
end
|
end
|
||||||
|
@ -5,8 +5,8 @@ class TestCallStatement < MiniTest::Test
|
|||||||
include Statements
|
include Statements
|
||||||
|
|
||||||
def test_call_constant_int
|
def test_call_constant_int
|
||||||
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
|
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
|
||||||
@input = s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:int, 42)))
|
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
|
||||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
GetSlot, GetSlot, Label, FunctionReturn]
|
GetSlot, GetSlot, Label, FunctionReturn]
|
||||||
@ -15,9 +15,9 @@ class TestCallStatement < MiniTest::Test
|
|||||||
|
|
||||||
|
|
||||||
def test_call_constant_string
|
def test_call_constant_string
|
||||||
clean_compile :Word, :putstring,{}, s(:statements, s(:return, s(:int, 1)))
|
clean_compile :Word, :putstr,{}, s(:statements, s(:return, s(:int, 1)))
|
||||||
|
|
||||||
@input =s(:call, s(:name, :putstring), s(:arguments), s(:receiver, s(:string, "Hello")))
|
@input =s(:call, s(:name, :putstr), s(:arguments), s(:receiver, s(:string, "Hello")))
|
||||||
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
|
||||||
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
|
||||||
GetSlot, GetSlot, Label, FunctionReturn]
|
GetSlot, GetSlot, Label, FunctionReturn]
|
||||||
|
Loading…
Reference in New Issue
Block a user