add an integer plus
not correctly handling integer objects yet
This commit is contained in:
parent
efcc33f8a1
commit
1956f18faa
@ -86,7 +86,7 @@ module Arm
|
||||
end
|
||||
end
|
||||
|
||||
def translate_OperatorInstruction code
|
||||
def translate_OperatorInstruction( code )
|
||||
left = code.left
|
||||
right = code.right
|
||||
case code.operator.to_s
|
||||
|
@ -150,7 +150,7 @@ module Risc
|
||||
Dictionary: {keys: :List , values: :List } ,
|
||||
CacheEntry: {cached_type: :Type , cached_method: :TypedMethod } ,
|
||||
TypedMethod: {name: :Word, source: :Object, risc_instructions: :Object,
|
||||
cpu_instructions: :Object, binary: :BinaryCode,
|
||||
cpu_instructions: :Object, binary: :BinaryCode,
|
||||
arguments: :Type , for_type: :Type, frame: :Type } ,
|
||||
}
|
||||
end
|
||||
@ -183,7 +183,7 @@ module Risc
|
||||
end
|
||||
|
||||
obj = space.get_class_by_name(:Integer)
|
||||
[ :putint, :mod4, :div10].each do |f| #mod4 is just a forward declaration
|
||||
[ :putint, :mod4, :div10, :+].each do |f| #mod4 is just a forward declaration
|
||||
obj.instance_type.add_method Builtin::Integer.send(f , nil)
|
||||
end
|
||||
end
|
||||
|
@ -15,7 +15,20 @@ module Risc
|
||||
return compiler.method
|
||||
end
|
||||
|
||||
def +( context )
|
||||
source = "plus"
|
||||
compiler = compiler_for(:Integer,:+ ,{other: :int})
|
||||
me , other = self_and_int_arg(compiler,source)
|
||||
# reduce me and other to integers
|
||||
compiler.add_slot_to_reg( source , me , 1 , me)
|
||||
compiler.add_slot_to_reg( source , other , 1 , other)
|
||||
compiler.add_code Risc.op( source , :+ , 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 , me , :message , :return_value)
|
||||
return compiler.method
|
||||
|
||||
end
|
||||
def div10( context )
|
||||
s = "div_10"
|
||||
compiler = compiler_for(:Integer,:div10 ,{})
|
||||
|
@ -20,16 +20,16 @@ module Risc
|
||||
Risc::FunctionCall.new( source , method , register)
|
||||
end
|
||||
|
||||
def self.issue_call( compiler , callee )
|
||||
callee_name = callee.name
|
||||
return_label = Risc.label("_return_label #{callee_name}" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
||||
ret_tmp = compiler.use_reg(:Label)
|
||||
compiler.add_load_constant("#{callee_name} load ret", return_label , ret_tmp)
|
||||
compiler.add_reg_to_slot("#{callee_name} store ret", ret_tmp , :new_message , :return_address)
|
||||
compiler.add_transfer("#{callee_name} move new message", Risc.new_message_reg , Risc.message_reg )
|
||||
compiler.add_function_call( "#{callee_name} call" , callee )
|
||||
compiler.add_code return_label
|
||||
compiler.add_transfer("#{callee_name} remove new message", Risc.message_reg , Risc.new_message_reg )
|
||||
compiler.add_slot_to_reg("#{callee_name} restore message" , :new_message , :caller , :message )
|
||||
end
|
||||
# def self.issue_call( compiler , callee )
|
||||
# callee_name = callee.name
|
||||
# return_label = Risc.label("_return_label #{callee_name}" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )
|
||||
# ret_tmp = compiler.use_reg(:Label)
|
||||
# compiler.add_load_constant("#{callee_name} load ret", return_label , ret_tmp)
|
||||
# compiler.add_reg_to_slot("#{callee_name} store ret", ret_tmp , :new_message , :return_address)
|
||||
# compiler.add_transfer("#{callee_name} move new message", Risc.new_message_reg , Risc.message_reg )
|
||||
# compiler.add_function_call( "#{callee_name} call" , callee )
|
||||
# compiler.add_code return_label
|
||||
# compiler.add_transfer("#{callee_name} remove new message", Risc.message_reg , Risc.new_message_reg )
|
||||
# compiler.add_slot_to_reg("#{callee_name} restore message" , :new_message , :caller , :message )
|
||||
# end
|
||||
end
|
||||
|
@ -27,7 +27,7 @@ class TestSpace < MiniTest::Test
|
||||
|
||||
def test_integer
|
||||
int = Parfait.object_space.get_class_by_name :Integer
|
||||
assert_equal 3, int.instance_type.method_names.get_length
|
||||
assert_equal 4, int.instance_type.method_names.get_length
|
||||
end
|
||||
|
||||
def test_classes_class
|
||||
|
@ -1,29 +1,28 @@
|
||||
require_relative "helper"
|
||||
|
||||
module Risc
|
||||
class PlusTest < MiniTest::Test
|
||||
class InterpreterPlusTest < MiniTest::Test
|
||||
include Ticker
|
||||
|
||||
def setup
|
||||
@string_input = <<HERE
|
||||
class Space
|
||||
int main()
|
||||
return #{2**62 - 1} + 1
|
||||
end
|
||||
end
|
||||
HERE
|
||||
@input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 4611686018427387903), s(:int, 1))))
|
||||
@string_input = as_main("a = 15 ; return 5 + 5")
|
||||
super
|
||||
end
|
||||
|
||||
def pest_add
|
||||
def test_add
|
||||
#show_ticks # get output of what is
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
||||
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
||||
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
|
||||
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
||||
NilClass]
|
||||
check_return 0
|
||||
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||
SlotToReg, RegToSlot, LoadConstant, RegToSlot, FunctionCall,
|
||||
Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
||||
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
||||
SlotToReg]
|
||||
#assert_equal 10 , get_return
|
||||
end
|
||||
|
||||
def pest_overflow
|
||||
|
Loading…
Reference in New Issue
Block a user