From 681b53cc4c3f06856768dee41422c463423e7db8 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 17 Dec 2016 00:17:35 +0200 Subject: [PATCH] make compiler default to compiling Space.main --- lib/typed/compiler.rb | 15 ++++++++++----- lib/typed/compiler/call_site.rb | 5 ++--- test/typed/statements/test_call.rb | 8 ++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/lib/typed/compiler.rb b/lib/typed/compiler.rb index 1bdff9d4..fd6f7fde 100644 --- a/lib/typed/compiler.rb +++ b/lib/typed/compiler.rb @@ -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 diff --git a/lib/typed/compiler/call_site.rb b/lib/typed/compiler/call_site.rb index 51ed0674..464d6ae3 100644 --- a/lib/typed/compiler/call_site.rb +++ b/lib/typed/compiler/call_site.rb @@ -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 diff --git a/test/typed/statements/test_call.rb b/test/typed/statements/test_call.rb index eafd3c5e..8c3624cb 100644 --- a/test/typed/statements/test_call.rb +++ b/test/typed/statements/test_call.rb @@ -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]