create return address as own class to hold return addresses

to distinguish from integer, which does not need adjusting
This commit is contained in:
Torsten Ruger
2018-05-30 23:49:01 +03:00
parent e86ca5ae9d
commit e39e96f646
9 changed files with 60 additions and 11 deletions

View File

@ -49,6 +49,13 @@ module Parfait
# :>, :>=, :<, :<=, :between?
end
# Marker class. Same functionality as Integer
# (ie carrying an int, the return address)
#
# But the integer (address) needs to be adjusted by load address.
class ReturnAddress < Integer
end
# adding other base classes in here for now:
class FalseClass < Data4
#FIXME: this is "just" for compilation

View File

@ -118,8 +118,8 @@ module Risc
# superclasses other than default object
def super_class_names
{ Data4: :DataObject , Data8: :DataObject ,Data16: :DataObject ,
BinaryCode: :Data16 , Integer: :Data4, Word: :Data8 ,
Object: :BasicObject , List: :Data16}
BinaryCode: :Data16 , Integer: :Data4 , Word: :Data8 ,
Object: :BasicObject , List: :Data16 , ReturnAddress: :Integer}
end
# the function really just returns a constant (just avoiding the constant)
@ -132,6 +132,7 @@ module Risc
return_address: :Integer, return_value: :Object,
caller: :Message , name: :Word , arguments: :NamedList },
Integer: {next_integer: :Integer},
ReturnAddress: {next_integer: :Integer},
DataObject: {},
Data4: {},
Data8: {},

View File

@ -66,8 +66,7 @@ module Risc
# if none was given
def self.label( source , name , position = nil , nekst = nil)
unless position
position = Parfait.object_space.get_integer
Risc.machine.add_constant(position)
position = Risc.machine.get_address
end
Label.new( source , name , position, nekst )
end

View File

@ -20,6 +20,7 @@ module Risc
@booted = false
@risc_init = nil
@constants = []
@next_address = nil
end
attr_reader :constants , :cpu_init
attr_reader :booted , :translated
@ -61,6 +62,17 @@ module Risc
@constants << const
end
# hand out a return address for use as constant the address is added
def get_address
10.times do # 10 for whole pages
@next_address = Parfait::ReturnAddress.new(0,@next_address)
add_constant( @next_address )
end unless @next_address
addr = @next_address
@next_address = @next_address.next_integer
addr
end
# To create binaries, objects (and labels) need to have a position
# (so objects can be loaded and branches know where to jump)
#

View File

@ -148,8 +148,8 @@ module Risc
def write_integer( int )
write_ref_for( int.get_type )
write_ref_for( int.next_integer )
@stream.write_signed_int_32( int.value )
@stream.write_signed_int_32( 0 )
write_ref_for( int.value )
write_ref_for( 0 )
log.debug "Integer witten stream 0x#{@stream.length.to_s(16)}"
end