make compiler default to compiling Space.main

This commit is contained in:
Torsten Ruger 2016-12-17 00:17:35 +02:00
parent ece017fa86
commit 681b53cc4c
3 changed files with 16 additions and 12 deletions

View File

@ -2,7 +2,7 @@ require_relative "tree"
module Typed
CompilerModules = [ "assignment" , "basic_values" , "call_site",
CompilerModules = [ "assignment" , "basic_values" , "call_site",
"class_statement" , "collections" , "field_def" , "field_access",
"function_statement" , "if_statement" , "name_expression" ,
"operator_expression" , "return_statement", "statement_list",
@ -56,10 +56,15 @@ module Typed
def initialize( method = nil )
@regs = []
return unless method
@method = method
@type = method.for_type
@current = method.instructions
if method
@method = method
@type = method.for_type
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
attr_reader :type , :method

View File

@ -52,10 +52,9 @@ module Typed
end
def do_call( type , statement )
name = statement.name
#puts "type #{type.inpect}"
raise "No such class" unless type
#puts "type #{type.inspect}"
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
Register.issue_call( self , method )
end

View File

@ -5,8 +5,8 @@ class TestCallStatement < MiniTest::Test
include Statements
def test_call_constant_int
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:int, 42)))
clean_compile :Integer, :puti, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:call, s(:name, :puti), s(:arguments), s(:receiver, s(:int, 42)))
@expect = [Label, GetSlot, LoadConstant, SetSlot, LoadConstant, SetSlot, LoadConstant ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn]
@ -15,9 +15,9 @@ class TestCallStatement < MiniTest::Test
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 ,
SetSlot, LoadConstant, SetSlot, RegisterTransfer, FunctionCall, Label, RegisterTransfer ,
GetSlot, GetSlot, Label, FunctionReturn]