have to pass constants around now
as they are not global anymore
This commit is contained in:
parent
e10092a4be
commit
e75aef933d
@ -36,7 +36,7 @@ module Mom
|
|||||||
cpu_instructions << cpu if cpu
|
cpu_instructions << cpu if cpu
|
||||||
nekst = nekst.next
|
nekst = nekst.next
|
||||||
end
|
end
|
||||||
Risc::Assembler.new(compiler.method , cpu_instructions)
|
Risc::Assembler.new(compiler.method , cpu_instructions , compiler.constants)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
module Risc
|
module Risc
|
||||||
class Assembler
|
class Assembler
|
||||||
attr_reader :method , :instructions
|
attr_reader :method , :instructions , :constants
|
||||||
def initialize( method , instructions)
|
def initialize( method , instructions, constants)
|
||||||
@method = method
|
@method = method
|
||||||
@instructions = instructions
|
@instructions = instructions
|
||||||
|
@constants = constants
|
||||||
total = instructions.total_byte_length / 4 + 1
|
total = instructions.total_byte_length / 4 + 1
|
||||||
method.binary.extend_to( total )
|
method.binary.extend_to( total )
|
||||||
end
|
end
|
||||||
|
@ -4,9 +4,9 @@ module Risc
|
|||||||
#
|
#
|
||||||
# The place we collect in is the position map in Position class
|
# The place we collect in is the position map in Position class
|
||||||
module Collector
|
module Collector
|
||||||
def self.collect_space
|
def self.collect_space(linker)
|
||||||
keep Parfait.object_space , 0
|
keep Parfait.object_space , 0
|
||||||
Risc.machine.constants.each {|obj| keep(obj,0)}
|
linker.constants.each {|obj| keep(obj,0)}
|
||||||
Position.positions
|
Position.positions
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ module Risc
|
|||||||
# machine keeps a list of all objects and their positions.
|
# machine keeps a list of all objects and their positions.
|
||||||
# this is lazily created with a collector
|
# this is lazily created with a collector
|
||||||
def object_positions
|
def object_positions
|
||||||
Collector.collect_space if Position.positions.length < 2 #one is the label
|
Collector.collect_space(self) if Position.positions.length < 2 #one is the label
|
||||||
Position.positions
|
Position.positions
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
# module method to reset, and init
|
# module method to reset, and init
|
||||||
def self.boot
|
def self.boot!
|
||||||
Position.clear_positions
|
Position.clear_positions
|
||||||
Builtin.boot_functions
|
Builtin.boot_functions
|
||||||
end
|
end
|
||||||
|
@ -18,8 +18,9 @@ module Risc
|
|||||||
@risc_instructions = Risc.label(name, name)
|
@risc_instructions = Risc.label(name, name)
|
||||||
@risc_instructions << Risc.label( name, "unreachable")
|
@risc_instructions << Risc.label( name, "unreachable")
|
||||||
@current = @risc_instructions
|
@current = @risc_instructions
|
||||||
|
@constants = []
|
||||||
end
|
end
|
||||||
attr_reader :method , :risc_instructions
|
attr_reader :method , :risc_instructions , :constants
|
||||||
|
|
||||||
# helper method for builtin mainly
|
# helper method for builtin mainly
|
||||||
# the class_name is a symbol, which is resolved to the instance_type of that class
|
# the class_name is a symbol, which is resolved to the instance_type of that class
|
||||||
@ -61,7 +62,7 @@ module Risc
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_constant(const)
|
def add_constant(const)
|
||||||
Risc.machine.add_constant(const)
|
@constants << const
|
||||||
end
|
end
|
||||||
|
|
||||||
# add a risc instruction after the current (insertion point)
|
# add a risc instruction after the current (insertion point)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user