From e75aef933d881765d0ffb914b1d8575b9b61aa60 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 1 Jul 2018 14:11:29 +0300 Subject: [PATCH] have to pass constants around now as they are not global anymore --- lib/mom/class_compiler.rb | 2 +- lib/risc/assembler.rb | 5 +++-- lib/risc/collector.rb | 4 ++-- lib/risc/linker.rb | 4 ++-- lib/risc/method_compiler.rb | 5 +++-- 5 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/mom/class_compiler.rb b/lib/mom/class_compiler.rb index 1b185b9c..75d4e9de 100644 --- a/lib/mom/class_compiler.rb +++ b/lib/mom/class_compiler.rb @@ -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 diff --git a/lib/risc/assembler.rb b/lib/risc/assembler.rb index 4c7d0f93..a10705e2 100644 --- a/lib/risc/assembler.rb +++ b/lib/risc/assembler.rb @@ -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 diff --git a/lib/risc/collector.rb b/lib/risc/collector.rb index 2c0d9cfc..40ffd685 100644 --- a/lib/risc/collector.rb +++ b/lib/risc/collector.rb @@ -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 diff --git a/lib/risc/linker.rb b/lib/risc/linker.rb index f8f586bb..8babd81a 100644 --- a/lib/risc/linker.rb +++ b/lib/risc/linker.rb @@ -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 diff --git a/lib/risc/method_compiler.rb b/lib/risc/method_compiler.rb index 3a117129..fbf009e5 100644 --- a/lib/risc/method_compiler.rb +++ b/lib/risc/method_compiler.rb @@ -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)