replace add_new_int in most builtins
in integer and word mainly, replaced with allocate_int (tests pending as syscalls are undone)
This commit is contained in:
parent
bbb7dbef75
commit
a8d1f070f1
@ -22,9 +22,6 @@
|
|||||||
module Parfait
|
module Parfait
|
||||||
class DataObject < Object
|
class DataObject < Object
|
||||||
|
|
||||||
def self.integer_index
|
|
||||||
type_length
|
|
||||||
end
|
|
||||||
def self.type_length
|
def self.type_length
|
||||||
raise "called #{self}"
|
raise "called #{self}"
|
||||||
end
|
end
|
||||||
|
@ -22,6 +22,11 @@ module Parfait
|
|||||||
def self.type_length
|
def self.type_length
|
||||||
2 # 0 type, 1 next_i
|
2 # 0 type, 1 next_i
|
||||||
end
|
end
|
||||||
|
# index at which the next integer reference is. Used in risc reneration
|
||||||
|
def self.next_index
|
||||||
|
1
|
||||||
|
end
|
||||||
|
# index at which the actual integer is. Used in risc reneration
|
||||||
def self.integer_index
|
def self.integer_index
|
||||||
type_length
|
type_length
|
||||||
end
|
end
|
||||||
|
@ -1,25 +1,28 @@
|
|||||||
module Risc
|
module Risc
|
||||||
module Builtin
|
module Builtin
|
||||||
# integer related kernel functions
|
# integer related kernel functions
|
||||||
# all these functions (return the functione they implement) assume interger input
|
# all these functions (return the function they implement) assume interger input
|
||||||
|
# Also the returned integer object has to be passed in to avoid having to allocate it.
|
||||||
#
|
#
|
||||||
# This means they will have to be renamed at some point and wrapped
|
# This means the methods will have to be renamed at some point and wrapped
|
||||||
module Integer
|
module Integer
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
include CompileHelper
|
include CompileHelper
|
||||||
|
|
||||||
# div by 4, ie shift two left
|
# div by 4, ie shift right by 2
|
||||||
# Mostly created for testing at this point, as it is short
|
# Mostly created for testing at this point, as it is short
|
||||||
# return new int with result
|
# return new int with result
|
||||||
def div4(context)
|
def div4(context)
|
||||||
compiler = compiler_for(:Integer,:div4 ,{})
|
compiler = compiler_for(:Integer,:div4 ,{})
|
||||||
compiler.builder(compiler.source).build do
|
builder = compiler.builder(compiler.source)
|
||||||
integer! << message[:receiver]
|
integer_tmp = builder.allocate_int
|
||||||
integer.reduce_int
|
builder.build do
|
||||||
integer_reg! << 2
|
integer_self! << message[:receiver]
|
||||||
integer.op :>> , integer_reg
|
integer_self.reduce_int
|
||||||
add_new_int("div4", integer , integer_reg)
|
integer_1! << 2
|
||||||
message[:return_value] << integer_reg
|
integer_self.op :>> , integer_1
|
||||||
|
integer_tmp[Parfait::Integer.integer_index] << integer_self
|
||||||
|
message[:return_value] << integer_tmp
|
||||||
end
|
end
|
||||||
compiler.add_mom( Mom::ReturnSequence.new)
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler
|
return compiler
|
||||||
@ -49,13 +52,13 @@ module Risc
|
|||||||
# - load true or false object into return, depending on check
|
# - load true or false object into return, depending on check
|
||||||
# - return
|
# - return
|
||||||
def comparison( operator )
|
def comparison( operator )
|
||||||
compiler = compiler_for(:Integer, operator ,{other: :Integer})
|
compiler = compiler_for(:Integer, operator ,{other: :Integer })
|
||||||
builder = compiler.builder(compiler.source)
|
builder = compiler.builder(compiler.source)
|
||||||
builder.build do
|
builder.build do
|
||||||
integer! << message[:receiver]
|
integer! << message[:receiver]
|
||||||
integer_reg! << message[:arguments]
|
|
||||||
integer_reg << integer_reg[ 1]
|
|
||||||
integer.reduce_int
|
integer.reduce_int
|
||||||
|
integer_reg! << message[:arguments]
|
||||||
|
integer_reg << integer_reg[Parfait::NamedList.type_length + 0] #"other" is at index 0
|
||||||
integer_reg.reduce_int
|
integer_reg.reduce_int
|
||||||
swap_names(:integer , :integer_reg) if(operator.to_s.start_with?('<') )
|
swap_names(:integer , :integer_reg) if(operator.to_s.start_with?('<') )
|
||||||
integer.op :- , integer_reg
|
integer.op :- , integer_reg
|
||||||
@ -86,17 +89,18 @@ module Risc
|
|||||||
# - gets a new integer and stores the result
|
# - gets a new integer and stores the result
|
||||||
# - returns the new int
|
# - returns the new int
|
||||||
def operator_method( op_sym )
|
def operator_method( op_sym )
|
||||||
compiler = compiler_for(:Integer, op_sym ,{other: :Integer})
|
compiler = compiler_for(:Integer, op_sym ,{other: :Integer })
|
||||||
builder = compiler.builder(compiler.source)
|
builder = compiler.builder(compiler.source)
|
||||||
|
integer_tmp = builder.allocate_int
|
||||||
builder.build do
|
builder.build do
|
||||||
integer! << message[:receiver]
|
integer! << message[:receiver]
|
||||||
integer_reg! << message[:arguments]
|
|
||||||
integer_reg << integer_reg[ 1]
|
|
||||||
integer.reduce_int
|
integer.reduce_int
|
||||||
|
integer_reg! << message[:arguments]
|
||||||
|
integer_reg << integer_reg[Parfait::NamedList.type_length + 0] #"other" is at index 0
|
||||||
integer_reg.reduce_int
|
integer_reg.reduce_int
|
||||||
integer.op op_sym , integer_reg
|
integer.op op_sym , integer_reg
|
||||||
add_new_int op_sym.to_s , integer , integer_reg
|
integer_tmp[Parfait::Integer.integer_index] << integer
|
||||||
message[:return_value] << integer_reg
|
message[:return_value] << integer_tmp
|
||||||
end
|
end
|
||||||
compiler.add_mom( Mom::ReturnSequence.new)
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler
|
return compiler
|
||||||
@ -114,56 +118,57 @@ module Risc
|
|||||||
s = "div_10 "
|
s = "div_10 "
|
||||||
compiler = compiler_for(:Integer,:div10 ,{})
|
compiler = compiler_for(:Integer,:div10 ,{})
|
||||||
builder = compiler.builder(compiler.source)
|
builder = compiler.builder(compiler.source)
|
||||||
|
integer_tmp = builder.allocate_int
|
||||||
builder.build do
|
builder.build do
|
||||||
integer_self! << message[:receiver]
|
integer_self! << message[:receiver]
|
||||||
integer_self.reduce_int
|
integer_self.reduce_int
|
||||||
integer_tmp! << integer_self
|
integer_1! << integer_self
|
||||||
integer_reg! << integer_self
|
integer_reg! << integer_self
|
||||||
|
|
||||||
integer_const! << 1
|
integer_const! << 1
|
||||||
integer_tmp.op :>> , integer_const
|
integer_1.op :>> , integer_const
|
||||||
|
|
||||||
integer_const << 2
|
integer_const << 2
|
||||||
integer_reg.op :>> , integer_const
|
integer_reg.op :>> , integer_const
|
||||||
integer_reg.op :+ , integer_tmp
|
integer_reg.op :+ , integer_1
|
||||||
|
|
||||||
integer_const << 4
|
integer_const << 4
|
||||||
integer_tmp << integer_reg
|
integer_1 << integer_reg
|
||||||
integer_reg.op :>> , integer_tmp
|
integer_reg.op :>> , integer_1
|
||||||
|
|
||||||
integer_reg.op :+ , integer_tmp
|
integer_reg.op :+ , integer_1
|
||||||
|
|
||||||
integer_const << 8
|
integer_const << 8
|
||||||
integer_tmp << integer_reg
|
integer_1 << integer_reg
|
||||||
integer_tmp.op :>> , integer_const
|
integer_1.op :>> , integer_const
|
||||||
|
|
||||||
integer_reg.op :+ , integer_tmp
|
integer_reg.op :+ , integer_1
|
||||||
|
|
||||||
integer_const << 16
|
integer_const << 16
|
||||||
integer_tmp << integer_reg
|
integer_1 << integer_reg
|
||||||
integer_tmp.op :>> , integer_const
|
integer_1.op :>> , integer_const
|
||||||
|
|
||||||
integer_reg.op :+ , integer_tmp
|
integer_reg.op :+ , integer_1
|
||||||
|
|
||||||
integer_const << 3
|
integer_const << 3
|
||||||
integer_reg.op :>> , integer_const
|
integer_reg.op :>> , integer_const
|
||||||
|
|
||||||
integer_const << 10
|
integer_const << 10
|
||||||
integer_tmp << integer_reg
|
integer_1 << integer_reg
|
||||||
integer_tmp.op :* , integer_const
|
integer_1.op :* , integer_const
|
||||||
|
|
||||||
integer_self.op :- , integer_tmp
|
integer_self.op :- , integer_1
|
||||||
integer_tmp << integer_self
|
integer_1 << integer_self
|
||||||
|
|
||||||
integer_const << 6
|
integer_const << 6
|
||||||
integer_tmp.op :+ , integer_const
|
integer_1.op :+ , integer_const
|
||||||
|
|
||||||
integer_const << 4
|
integer_const << 4
|
||||||
integer_tmp.op :>> , integer_const
|
integer_1.op :>> , integer_const
|
||||||
|
|
||||||
integer_reg.op :+ , integer_tmp
|
integer_reg.op :+ , integer_1
|
||||||
|
|
||||||
add_new_int(s,integer_reg , integer_tmp)
|
integer_tmp[Parfait::Integer.integer_index] << integer_reg
|
||||||
message[:return_value] << integer_tmp
|
message[:return_value] << integer_tmp
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ module Risc
|
|||||||
compiler.builder(compiler.source).build do
|
compiler.builder(compiler.source).build do
|
||||||
object! << message[:receiver]
|
object! << message[:receiver]
|
||||||
integer! << message[:arguments]
|
integer! << message[:arguments]
|
||||||
integer << integer[1]
|
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
|
||||||
integer.reduce_int
|
integer.reduce_int
|
||||||
object << object[integer]
|
object << object[integer]
|
||||||
message[:return_value] << object
|
message[:return_value] << object
|
||||||
@ -23,12 +23,12 @@ module Risc
|
|||||||
# self[index] = val basically. Index is the first arg , value the second
|
# self[index] = val basically. Index is the first arg , value the second
|
||||||
# return the value passed in
|
# return the value passed in
|
||||||
def set_internal_word( context )
|
def set_internal_word( context )
|
||||||
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, :value => :Object} )
|
compiler = compiler_for(:Object , :set_internal_word , {at: :Integer, value: :Object} )
|
||||||
compiler.builder(compiler.source).build do
|
compiler.builder(compiler.source).build do
|
||||||
object! << message[:receiver]
|
object! << message[:receiver]
|
||||||
integer! << message[:arguments]
|
integer! << message[:arguments]
|
||||||
object_reg! << integer[ 2]
|
object_reg! << integer[Parfait::NamedList.type_length + 1] #"value" is at index 1
|
||||||
integer << integer[1]
|
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
|
||||||
integer.reduce_int
|
integer.reduce_int
|
||||||
object[integer] << object_reg
|
object[integer] << object_reg
|
||||||
message[:return_value] << object_reg
|
message[:return_value] << object_reg
|
||||||
@ -125,7 +125,7 @@ module Risc
|
|||||||
|
|
||||||
# restore the message that we save in r8
|
# restore the message that we save in r8
|
||||||
# get a new int and save the c return into it
|
# get a new int and save the c return into it
|
||||||
# tht int gets retured, ie is the return_value of the message
|
# the int gets retured, ie is the return_value of the message
|
||||||
def restore_message(builder)
|
def restore_message(builder)
|
||||||
r8 = RegisterValue.new( :r8 , :Message)
|
r8 = RegisterValue.new( :r8 , :Message)
|
||||||
int = builder.compiler.use_reg(:Integer)
|
int = builder.compiler.use_reg(:Integer)
|
||||||
|
@ -24,37 +24,39 @@ module Risc
|
|||||||
|
|
||||||
# self[index] basically. Index is the first arg > 0
|
# self[index] basically. Index is the first arg > 0
|
||||||
# return a word sized new int, in return_value
|
# return a word sized new int, in return_value
|
||||||
|
#
|
||||||
|
# Note: no index (or type) checking. Method should be internal and check before.
|
||||||
|
# Which means the returned integer could be passed in, instead of allocated.
|
||||||
def get_internal_byte( context)
|
def get_internal_byte( context)
|
||||||
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
compiler = compiler_for(:Word , :get_internal_byte , {at: :Integer})
|
||||||
compiler.builder(compiler.source).build do
|
builder = compiler.builder(compiler.source)
|
||||||
|
integer_tmp = builder.allocate_int
|
||||||
|
builder.build do
|
||||||
object! << message[:receiver]
|
object! << message[:receiver]
|
||||||
integer! << message[:arguments]
|
integer! << message[:arguments]
|
||||||
integer << integer[1]
|
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
|
||||||
integer.reduce_int
|
integer.reduce_int
|
||||||
object <= object[integer]
|
object <= object[integer]
|
||||||
add_new_int("get_internal_byte", object , integer)
|
integer_tmp[Parfait::Integer.integer_index] << object
|
||||||
message[:return_value] << integer
|
message[:return_value] << integer_tmp
|
||||||
end
|
end
|
||||||
compiler.add_mom( Mom::ReturnSequence.new)
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler
|
return compiler
|
||||||
end
|
end
|
||||||
|
|
||||||
# self[index] = val basically. Index is the first arg ( >0),
|
# self[index] = val basically. Index is the first arg ( >0 , unchecked),
|
||||||
# value the second
|
# value the second, which is also returned
|
||||||
# return value
|
|
||||||
def set_internal_byte( context )
|
def set_internal_byte( context )
|
||||||
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , :value => :Integer} )
|
compiler = compiler_for(:Word, :set_internal_byte , {at: :Integer , value: :Integer} )
|
||||||
compiler.builder(compiler.source).build do
|
compiler.builder(compiler.source).build do
|
||||||
word! << message[:receiver]
|
word! << message[:receiver]
|
||||||
integer! << message[:arguments]
|
integer! << message[:arguments]
|
||||||
integer << integer[1]
|
integer_reg! << integer[Parfait::NamedList.type_length + 1] #"value" is at index 1
|
||||||
integer_reg! << message[:arguments]
|
message[:return_value] << integer_reg
|
||||||
integer_obj! << integer_reg[2]
|
integer << integer[Parfait::NamedList.type_length + 0] #"at" is at index 0
|
||||||
integer_reg << integer_reg[2]
|
|
||||||
integer.reduce_int
|
integer.reduce_int
|
||||||
integer_reg.reduce_int
|
integer_reg.reduce_int
|
||||||
word[integer] <= integer_reg
|
word[integer] <= integer_reg
|
||||||
message[:return_value] << integer_obj
|
|
||||||
end
|
end
|
||||||
compiler.add_mom( Mom::ReturnSequence.new)
|
compiler.add_mom( Mom::ReturnSequence.new)
|
||||||
return compiler
|
return compiler
|
||||||
|
@ -7,7 +7,12 @@ module Parfait
|
|||||||
super
|
super
|
||||||
@int = Integer.new(10)
|
@int = Integer.new(10)
|
||||||
end
|
end
|
||||||
|
def test_index
|
||||||
|
assert_equal 2 , Integer.integer_index
|
||||||
|
end
|
||||||
|
def test_next_index
|
||||||
|
assert_equal 1 , Integer.next_index
|
||||||
|
end
|
||||||
def test_class
|
def test_class
|
||||||
assert_equal :Integer, @int.get_type.object_class.name
|
assert_equal :Integer, @int.get_type.object_class.name
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user