misc
This commit is contained in:
parent
5670f07eac
commit
4d0773ebae
@ -3,14 +3,14 @@ module Register
|
||||
# the register machine has at least 8 registers, named r0-r5 , :lr and :pc (for historical reasons)
|
||||
# we can load and store their contents and
|
||||
# access (get/set) memory at a constant offset from a register
|
||||
# while the vm works with objects, the register machine has registers,
|
||||
# while the vm works with objects, the register machine has registers,
|
||||
# but we keep the names for better understanding, r4/5 are temporary/scratch
|
||||
# there is no direct memory access, only through registers
|
||||
# constants can/must be loaded into registers before use
|
||||
class Instruction
|
||||
|
||||
# returns an array of registers (RegisterReferences) that this instruction uses.
|
||||
# ie for r1 = r2 + r3
|
||||
# ie for r1 = r2 + r3
|
||||
# which in assembler is add r1 , r2 , r3
|
||||
# it would return [r2,r3]
|
||||
# for pushes the list may be longer, whereas for a jump empty
|
||||
@ -18,7 +18,7 @@ module Register
|
||||
raise "abstract called for #{self.class}"
|
||||
end
|
||||
# returns an array of registers (RegisterReferences) that this instruction assigns to.
|
||||
# ie for r1 = r2 + r3
|
||||
# ie for r1 = r2 + r3
|
||||
# which in assembler is add r1 , r2 , r3
|
||||
# it would return [r1]
|
||||
# for most instruction this is one, but comparisons and jumps 0 , and pop's as long as 16
|
||||
@ -32,7 +32,7 @@ module Register
|
||||
RegisterReference.new(reg)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
require_relative "instructions/set_slot"
|
||||
|
@ -7,7 +7,7 @@ module Virtual
|
||||
|
||||
# Blocks form a graph, which is managed by the method
|
||||
|
||||
class Block
|
||||
class Block
|
||||
|
||||
def initialize(name , method )
|
||||
super()
|
||||
@ -52,11 +52,16 @@ module Virtual
|
||||
|
||||
# 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
|
||||
# Note: this will have to change for plocks and maybe anyway.
|
||||
def set_position at
|
||||
@position = at
|
||||
@codes.each do |code|
|
||||
code.set_position( at)
|
||||
begin
|
||||
code.set_position( at)
|
||||
rescue => e
|
||||
puts "BLOCK #{self}"
|
||||
raise e
|
||||
end
|
||||
raise code.inspect unless code.mem_length
|
||||
at += code.mem_length
|
||||
end
|
||||
@ -66,6 +71,10 @@ module Virtual
|
||||
@codes.inject(0){|count , instruction| count += instruction.mem_length }
|
||||
end
|
||||
|
||||
def to_s
|
||||
Sof::Writer.write(self)
|
||||
end
|
||||
|
||||
private
|
||||
# helper for determining reachable blocks
|
||||
def add_next ret
|
||||
|
@ -31,7 +31,7 @@ module Virtual
|
||||
# return the main function (the top level) into which code is compiled
|
||||
# this just create a "main" with create_method , see there
|
||||
def self.main
|
||||
self.create_method( "Object" , "main" , [] )
|
||||
self.create_method( "Kernel" , "main" , [] )
|
||||
end
|
||||
|
||||
# create method does two things
|
||||
|
@ -73,7 +73,6 @@ module Virtual
|
||||
def self.compile_string expression , method
|
||||
value = Virtual.new_word(expression.string)
|
||||
to = Return.new(Reference , value)
|
||||
Machine.instance.space.add_object value
|
||||
method.info.add_code Set.new( to , value )
|
||||
to
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user