From 4725b81270c976191ed32d361b88a1e87b0e42ba Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 31 Mar 2018 20:21:27 +0300 Subject: [PATCH] get those integers crated and used --- lib/parfait/integer.rb | 4 ++-- lib/parfait/space.rb | 3 ++- lib/risc/boot.rb | 4 ++-- lib/risc/builtin/integer.rb | 6 +++--- lib/risc/method_compiler.rb | 12 ++++++++++++ test/parfait/test_space.rb | 11 +++++++++++ test/risc/interpreter/test_plus.rb | 9 +++++---- 7 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 4a9d50d2..2a4c6421 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -12,9 +12,9 @@ module Parfait def initialize(value , next_i = nil) super() @value = value - @next_i = next_i + @next_integer = next_i end - attr_reader :next_i, :value + attr_reader :next_integer, :value def self.integer_index 3 # 1 type, 2 next_i diff --git a/lib/parfait/space.rb b/lib/parfait/space.rb index 6c881823..55beb9ee 100644 --- a/lib/parfait/space.rb +++ b/lib/parfait/space.rb @@ -35,6 +35,7 @@ module Parfait @classes = classes @types = Dictionary.new message = Message.new(nil) + 100.times { @next_integer = Integer.new(0,@next_integer) } 50.times do @first_message = Message.new message #puts "INIT caller #{message.object_id} to #{@first_message.object_id}" @@ -49,7 +50,7 @@ module Parfait @nil_object = Parfait::NilClass.new end - attr_reader :classes , :first_message , :first_integer + attr_reader :classes , :first_message , :next_integer attr_reader :true_object , :false_object , :nil_object def each_type diff --git a/lib/risc/boot.rb b/lib/risc/boot.rb index 8838ad07..c574ecb7 100644 --- a/lib/risc/boot.rb +++ b/lib/risc/boot.rb @@ -129,7 +129,7 @@ module Risc Message: { next_message: :Message, receiver: :Object, frame: :NamedList , return_address: :Integer, return_value: :Integer, caller: :Message , name: :Word , arguments: :NamedList }, - Integer: {next_i: :Integer}, + Integer: {next_integer: :Integer}, DataObject: {}, Data4: {}, Data8: {}, @@ -140,7 +140,7 @@ module Risc Kernel: {}, #fix, kernel is a class, but should be a module BinaryCode: {next: :BinaryCode} , Space: {classes: :Dictionary , types: :Dictionary , - first_message: :Message , first_integer: :Integer , + first_message: :Message , next_integer: :Integer , true_object: :TrueClass, false_object: :FalseClass , nil_object: :NilClass}, NamedList: {}, diff --git a/lib/risc/builtin/integer.rb b/lib/risc/builtin/integer.rb index a1e966e3..19061535 100644 --- a/lib/risc/builtin/integer.rb +++ b/lib/risc/builtin/integer.rb @@ -23,9 +23,9 @@ module Risc compiler.add_slot_to_reg( source + "2" , me , Parfait::Integer.integer_index , me) compiler.add_slot_to_reg( source + "3", other , Parfait::Integer.integer_index , other) compiler.add_code Risc.op( source + "4", :+ , me , other) - #TODO must get an Integer and put the value there then return the integer (object not value) - # and put it back into the return value - compiler.add_reg_to_slot( source + "5" , me , :message , :return_value) + compiler.add_new_int(other) + compiler.add_reg_to_slot( source + "5" , me , other , Parfait::Integer.integer_index) + compiler.add_reg_to_slot( source + "5" , other , :message , :return_value) return compiler.method end diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 2205f72b..77a6abe2 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -132,6 +132,18 @@ module Risc @regs.clear end + # grab an integer from space and stick it in the register. + def add_new_int( register ) + source = "add_new_int " + space = use_reg(:Space) + int = use_reg(:Integer) + space_i = Risc.resolve_to_index(:Space, :next_integer) + add_load_constant( source + "space" , Parfait.object_space , space ) + add_slot_to_reg( source + "next_i1" , space , space_i , register) + add_slot_to_reg( source + "next_i2" , register , Risc.resolve_to_index(:Integer, :next_integer) , int) + add_reg_to_slot( source + "store link" , int , space , space_i ) + # store 2nd next_i to spce next_i + end def add_constant(const) Risc.machine.add_constant(const) end diff --git a/test/parfait/test_space.rb b/test/parfait/test_space.rb index 45c63ea6..7911a857 100644 --- a/test/parfait/test_space.rb +++ b/test/parfait/test_space.rb @@ -22,6 +22,17 @@ class TestSpace < MiniTest::Test assert @space.false_object , "No lies" assert @space.nil_object , "No nothing" end + def test_integer_first + assert @space.next_integer + end + def test_integer_20 + int = @space.next_integer + 20.times do + assert int + assert_equal Parfait::Integer , int.class + int = int.next_integer + end + end def test_methods_booted word = @space.get_class_by_name(:Word).instance_type assert_equal 4 , word.method_names.get_length diff --git a/test/risc/interpreter/test_plus.rb b/test/risc/interpreter/test_plus.rb index 230756c2..5f76a7a9 100644 --- a/test/risc/interpreter/test_plus.rb +++ b/test/risc/interpreter/test_plus.rb @@ -9,7 +9,7 @@ module Risc super end - def est_add + def test_add #show_ticks # get output of what is check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, @@ -23,10 +23,11 @@ module Risc LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label, SlotToReg, SlotToReg, SlotToReg, SlotToReg, - SlotToReg, OperatorInstruction, RegToSlot, Label, NilClass] - assert_equal 10 , get_return + SlotToReg, OperatorInstruction, LoadConstant, SlotToReg, SlotToReg, + RegToSlot, RegToSlot, RegToSlot, Label, NilClass] + assert_equal Parfait::Integer , get_return.class +# assert_equal 10 , get_return.value end - def test_load_5 lod = ticks( 46 ) assert_equal LoadConstant , lod.class