reworking method and block assembly for new aproach
This commit is contained in:
parent
90e5b4584a
commit
d33077c2b1
@ -19,7 +19,7 @@ module Virtual
|
||||
@codes = []
|
||||
end
|
||||
|
||||
attr_reader :name , :codes , :method
|
||||
attr_reader :name , :codes , :method , :position
|
||||
attr_accessor :branch
|
||||
|
||||
def reachable ret = []
|
||||
@ -48,6 +48,17 @@ module Virtual
|
||||
codes.dup.reverse.find{ |c| c.is_a? StackInstruction }
|
||||
end
|
||||
|
||||
# position is what another block uses to jump to. this is determined by the assembler
|
||||
# the assembler allso assembles and assumes a linear instruction sequence
|
||||
# Note: this will have to change for plocks and maybe anyway. back to oo, no more visitors
|
||||
def set_position at
|
||||
@position = at
|
||||
end
|
||||
|
||||
def length
|
||||
@codes.inject(0){|count , instruction| count += instruction.length }
|
||||
end
|
||||
|
||||
private
|
||||
# helper for determining reachable blocks
|
||||
def add_next ret
|
||||
|
@ -162,32 +162,17 @@ module Virtual
|
||||
# to the current block
|
||||
# also symbols are supported and wrapped as register usages (for bare metal programming)
|
||||
def method_missing(meth, *args, &block)
|
||||
add_code RegisterMachine.instance.send(meth , *args)
|
||||
add_code Register::RegisterMachine.instance.send(meth , *args)
|
||||
end
|
||||
|
||||
# following id the Code interface
|
||||
|
||||
# to link we link the entry and then any blocks. The entry links the straight line
|
||||
def link_at address , context
|
||||
super #just sets the position
|
||||
@entry.link_at address , context
|
||||
# position of the function is the position of the entry block, is where we call
|
||||
def set_position at
|
||||
@blocks.each do |block|
|
||||
blocks.set_position at
|
||||
at = at + block.length
|
||||
end
|
||||
end
|
||||
|
||||
# position of the function is the position of the entry block
|
||||
def position
|
||||
@entry.position
|
||||
end
|
||||
|
||||
# length of a function is the entry block length (includes the straight line behind it)
|
||||
# plus any out of line blocks that have been added
|
||||
def length
|
||||
@entry.length
|
||||
end
|
||||
|
||||
# assembling assembles the entry (straight line/ no branch line) + any additional branches
|
||||
def assemble io
|
||||
@entry.assemble(io)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user