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