positioning code by setting first method code

codes will initial (and on reset) propagate the whole chain
This commit is contained in:
Torsten Ruger
2018-05-13 15:28:10 +03:00
parent 7ad36380c2
commit 39902401b9
8 changed files with 88 additions and 32 deletions

View File

@ -5,6 +5,9 @@ module Risc
#
# We want to keep all code for a method continous, so we propagate Positions
#
# At the end of the list the propagation spills into the next methods
# binary and so on
#
class CodePosition < ObjectPosition
attr_reader :code , :method
@ -13,13 +16,17 @@ module Risc
super(pos,code)
@code = code
@method = method
raise "Method nil" unless method
end
def init(at)
next_pos = at + code.padded_length
if code.next
Position.set(code.next , next_pos, method)
else
Position.set(method , next_pos)
next_meth = next_method
return unless next_meth
Position.set( next_meth.binary , next_pos , next_meth)
Position.set( next_meth.cpu_instructions, next_pos + 12 , next_meth.binary)
end
end
def reset_to(pos)
@ -27,6 +34,24 @@ module Risc
#puts "Reset (#{changed}) #{instruction}"
init(pos)
end
def next_method
next_m = @method.next_method
return next_m if next_m
#puts "Type now #{@method.for_type.name}"
type = next_type(@method.for_type)
if type
#puts "Position for #{type.name}"
return type.methods
else
return nil
end
end
def next_type(type)
nekst = Parfait.object_space.types.next_value(type)
return nil unless nekst
return nekst if nekst.methods
return next_type(nekst)
end
end
end
end