diff --git a/lib/parfait/layout.rb b/lib/parfait/layout.rb index 6e75555a..738fe3fc 100644 --- a/lib/parfait/layout.rb +++ b/lib/parfait/layout.rb @@ -33,7 +33,7 @@ module Parfait def initialize( object_class ) super() - add_instance_variable :layout + add_instance_variable :layout ,:Layout self.object_class = object_class end @@ -47,30 +47,40 @@ module Parfait # # TODO , later we would need to COPY the layout to keep the old constant # but now we are concerned with booting, ie getting a working structure - def add_instance_variable name + def add_instance_variable name , type + raise "Name shouldn't be nil" unless name + raise "Type shouldn't be nil" unless type self.push(name) + self.push(type) self.get_length end def instance_names names = List.new + name = true each do |item| - names.push item + names.push(item) if name + name = ! name end names end def instance_length - self.get_length + self.get_length / 2 + end + + alias :super_index :index_of + def index_of(name) + raise "Use variable_index instead" end # index of the variable when using internal_object_get # (internal_object_get is 1 based and 1 is always the layout) def variable_index name - has = index_of(name) + has = super_index(name) return nil unless has raise "internal error #{name}:#{has}" if has < 1 - has + 1 + has / 2 end def inspect diff --git a/lib/register/boot.rb b/lib/register/boot.rb index 26fa9af1..a1477ad6 100644 --- a/lib/register/boot.rb +++ b/lib/register/boot.rb @@ -93,8 +93,8 @@ module Register # helper to create a Layout, name is the parfait name, ie :Layout def layout_for( name , ivars ) l = Parfait::Layout.allocate.fake_init - l.add_instance_variable :layout - ivars.each {|n| l.add_instance_variable n } + l.add_instance_variable :layout , :Layout + ivars.each {|n,t| l.add_instance_variable( n , t) } l end @@ -112,23 +112,26 @@ module Register # unfortuantely that constant condenses every detail about the system, class names # and all instance variable names. Really have to find a better way def layout_names - { :Word => [:char_length] , - :List => [:indexed_length] , + { :Word => {:char_length => :Integer} , + :List => {:indexed_length => :Integer} , # Assumtion is that name is the last of message - :Message => [ :next_message , :receiver , :frame , :return_address , - :return_value, :caller , :name , :indexed_length ], - :MetaClass => [:me], - :Integer => [], - :Object => [], - :Kernel => [], #fix, kernel is a class, but should be a module - :BinaryCode => [], - :Space => [:classes , :first_message ], - :Frame => [:next_frame , :indexed_length], - :Layout => [:object_class,:instance_methods,:indexed_length] , - :Class => [:object_layout , :name , :instance_methods , :super_class_name ], - :Dictionary => [:keys , :values ] , - :Method => [:name , :source , :instructions , :binary ,:arguments , :for_class, :locals ] , - :Variable => [:type , :name , :value ] + :Message => { :next_message => :Message, :receiver => :Object, :frame => :Frame , + :return_address => :Integer, :return_value => :Integer, + :caller => :Message , :name => :Word , :indexed_length => :Integer }, + :MetaClass => {:me => :Class}, + :Integer => {}, + :Object => {}, + :Kernel => {}, #fix, kernel is a class, but should be a module + :BinaryCode => {}, + :Space => {:classes => :Dictionary , :first_message => :Message}, + :Frame => {:next_frame => :Frame, :indexed_length => :Integer}, + :Layout => {:object_class => :Class, :instance_methods => :List , :indexed_length => :Integer} , + :Class => {:object_layout => :Layout, :name => :Word, :instance_methods => :List, + :super_class_name => :Word}, + :Dictionary => {:keys => :List , :values => :List } , + :Method => {:name => :Word, :source => :Object, :instructions => :Object, :binary => :Object, + :arguments => :List , :for_class => :Class, :locals => :List } , + :Variable => {:type => :Class, :name => :Word , :value => :Object} } end diff --git a/lib/soml/compiler/class_field.rb b/lib/soml/compiler/class_field.rb index 9cf6566f..4caba918 100644 --- a/lib/soml/compiler/class_field.rb +++ b/lib/soml/compiler/class_field.rb @@ -10,7 +10,7 @@ module Soml index = for_class.object_layout.variable_index(name) #raise "class field already defined:#{name} for class #{for_class.name}" if index #puts "Define field #{name} on class #{for_class.name}" - index = for_class.object_layout.add_instance_variable( name ) #TODO need typing + index = for_class.object_layout.add_instance_variable( name , type ) # not sure how to run class code yet. later raise "value #{value}" if value diff --git a/lib/soml/compiler/if_statement.rb b/lib/soml/compiler/if_statement.rb index 3a08cdf2..17a1e17f 100644 --- a/lib/soml/compiler/if_statement.rb +++ b/lib/soml/compiler/if_statement.rb @@ -12,14 +12,14 @@ module Soml process(condition) branch_class = Object.const_get "Register::Is#{branch_type.capitalize}" - true_block = Register::Label.new(statement, "if_true") + true_block = Register::Label.new(if_true, "if_true") add_code branch_class.new( condition , true_block ) # compile the false block reset_regs process_all(if_false) if if_false merge = Register::Label.new(statement , "if_merge") - add_code Register::Branch.new(statement, merge ) + add_code Register::Branch.new(if_false, merge ) # compile the true block add_code true_block diff --git a/test/compiler/expressions/test_field_access.rb b/test/compiler/expressions/test_field_access.rb index 1236d691..3f7e9199 100644 --- a/test/compiler/expressions/test_field_access.rb +++ b/test/compiler/expressions/test_field_access.rb @@ -17,7 +17,7 @@ HERE end def test_field - Register.machine.space.get_class_by_name(:Object).object_layout.add_instance_variable(:bro) + Register.machine.space.get_class_by_name(:Object).object_layout.add_instance_variable(:bro,:Object) @root = :field_access @string_input = <