get those integers crated and used

This commit is contained in:
Torsten Ruger 2018-03-31 20:21:27 +03:00
parent 5b92b6b785
commit 4725b81270
7 changed files with 37 additions and 12 deletions

View File

@ -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

View File

@ -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

View File

@ -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: {},

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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