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