From 15b570f5cf6ce5effc2fe3e73e6e9a99321acf93 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 18 Oct 2015 19:27:02 +0300 Subject: [PATCH] removing passes (before arm) collector becomes a function minimizer unused --- lib/interpreter/interpreter.rb | 1 + lib/virtual.rb | 4 ---- lib/virtual/{passes => }/collector.rb | 8 ++++---- lib/virtual/machine.rb | 14 ++++++-------- lib/virtual/{passes => }/minimizer.rb | 2 +- test/elf/test_hello.rb | 1 + test/interpreter/test_add.rb | 4 ++-- test/interpreter/test_puti.rb | 5 ++--- test/interpreter/test_puts.rb | 4 ++-- 9 files changed, 19 insertions(+), 24 deletions(-) rename lib/virtual/{passes => }/collector.rb (89%) rename lib/virtual/{passes => }/minimizer.rb (93%) diff --git a/lib/interpreter/interpreter.rb b/lib/interpreter/interpreter.rb index fb6cf5ab..794afea7 100644 --- a/lib/interpreter/interpreter.rb +++ b/lib/interpreter/interpreter.rb @@ -74,6 +74,7 @@ module Interpreter def tick return unless @instruction @clock += 1 + #puts @instruction name = @instruction.class.name.split("::").last fetch = send "execute_#{name}" return unless fetch diff --git a/lib/virtual.rb b/lib/virtual.rb index 2f35d9c5..4a0f7acd 100644 --- a/lib/virtual.rb +++ b/lib/virtual.rb @@ -6,11 +6,7 @@ require "virtual/padding" require "virtual/parfait_adapter" require "phisol/compiler" -require "virtual/instruction" require "virtual/method_source" -# the passes _are_ order dependant -require "virtual/passes/minimizer" -require "virtual/passes/collector" class Fixnum diff --git a/lib/virtual/passes/collector.rb b/lib/virtual/collector.rb similarity index 89% rename from lib/virtual/passes/collector.rb rename to lib/virtual/collector.rb index 0014a0ea..845e03fa 100644 --- a/lib/virtual/passes/collector.rb +++ b/lib/virtual/collector.rb @@ -1,10 +1,10 @@ module Virtual # collect anything that is in the space but and reachable from init - class Collector - def run + module Collector + def collect # init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__" - Virtual.machine.objects.clear + self.objects.clear keep Parfait::Space.object_space , 0 end @@ -12,7 +12,7 @@ module Virtual return if object.nil? #puts "adding #{' ' * depth}:#{object.class}" #puts "ADD #{object.first.class}, #{object.last.class}" if object.is_a? Array - return unless Virtual.machine.add_object object + return unless self.add_object object return unless object.respond_to? :has_layout? if( object.is_a? Parfait::Method) object.source.constants.each{|c| diff --git a/lib/virtual/machine.rb b/lib/virtual/machine.rb index 8584c84b..cfb8d559 100644 --- a/lib/virtual/machine.rb +++ b/lib/virtual/machine.rb @@ -1,5 +1,5 @@ require 'parslet/convenience' - +require_relative "collector" module Virtual # The Virtual Machine is a object based virtual machine in which ruby is implemented. # @@ -35,12 +35,11 @@ module Virtual # The "machine" is not part of the run-time (Parfait) class Machine - - FIRST_PASS = "Register::CallImplementation" + include Collector def initialize @parser = Parser::Salama.new - @passes = [ FIRST_PASS ] + @passes = [ ] @objects = {} @booted = false end @@ -51,8 +50,6 @@ module Virtual # runs housekeeping Minimizer and Collector # Has to be called before run_after def run_before stop_at - Minimizer.new.run - Collector.new.run @blocks = [@init] @space.classes.values.each do |c| c.instance_methods.each do |f| @@ -85,8 +82,9 @@ module Virtual # as before, run all passes that are registered # (but now finer control with before/after versions) def run_passes - run_before FIRST_PASS - run_after FIRST_PASS + return if @passes.empty? + run_before @passes.first + run_after @passes.first end # Objects are data and get assembled after functions diff --git a/lib/virtual/passes/minimizer.rb b/lib/virtual/minimizer.rb similarity index 93% rename from lib/virtual/passes/minimizer.rb rename to lib/virtual/minimizer.rb index 422f722e..6ce4be37 100644 --- a/lib/virtual/passes/minimizer.rb +++ b/lib/virtual/minimizer.rb @@ -25,7 +25,7 @@ module Virtual @gonners.delete function function.source.blocks.each do |block| block.codes.each do |code| - keep code.method if code.is_a? Virtual::MethodCall + keep code.method if code.is_a? Register::FunctionCall end end end diff --git a/test/elf/test_hello.rb b/test/elf/test_hello.rb index 35f0adbf..60e4c566 100644 --- a/test/elf/test_hello.rb +++ b/test/elf/test_hello.rb @@ -9,6 +9,7 @@ class HelloTest < MiniTest::Test statements = machine.parse_and_compile @string_input output_at = "Register::CallImplementation" #{}"Register::CallImplementation" + machine.collect machine.run_before output_at #puts Sof.write(machine.space) machine.run_after output_at diff --git a/test/interpreter/test_add.rb b/test/interpreter/test_add.rb index b0dddcda..02167652 100644 --- a/test/interpreter/test_add.rb +++ b/test/interpreter/test_add.rb @@ -5,7 +5,7 @@ class AddTest < MiniTest::Test include Ticker def setup - Virtual.machine.boot + machine = Virtual.machine.boot code = s(:class, :Object, s(:derives, nil), s(:statements, @@ -19,7 +19,7 @@ class AddTest < MiniTest::Test s(:int, 7))))))) Phisol::Compiler.compile( code ) - Virtual.machine.run_before "Register::CallImplementation" + machine.collect @interpreter = Interpreter::Interpreter.new @interpreter.start Virtual.machine.init end diff --git a/test/interpreter/test_puti.rb b/test/interpreter/test_puti.rb index cd59a2ab..1e1367f0 100644 --- a/test/interpreter/test_puti.rb +++ b/test/interpreter/test_puti.rb @@ -48,15 +48,14 @@ class Object end end HERE - Virtual.machine.boot + machine = Virtual.machine.boot syntax = Parser::Salama.new.parse_with_debug(@string_input) parts = Parser::Transform.new.apply(syntax) #puts parts.inspect Phisol::Compiler.compile( parts ) - + machine.collect # statements = Virtual.machine.boot.parse_and_compile @string_input # Phisol::Compiler.compile( statements , Virtual.machine.space.get_main ) - Virtual.machine.run_before "Register::CallImplementation" @interpreter = Interpreter::Interpreter.new @interpreter.start Virtual.machine.init #show_ticks # get output of what is diff --git a/test/interpreter/test_puts.rb b/test/interpreter/test_puts.rb index 9af6eb65..71ba5d0f 100644 --- a/test/interpreter/test_puts.rb +++ b/test/interpreter/test_puts.rb @@ -4,7 +4,7 @@ class TestPuts < MiniTest::Test include AST::Sexp include Ticker def setup - Virtual.machine.boot + machine = Virtual.machine.boot code = s(:class, :Object, s(:derives, nil), s(:statements, @@ -19,7 +19,7 @@ class TestPuts < MiniTest::Test s(:string, "Hello again"))))))) Phisol::Compiler.compile( code ) - Virtual.machine.run_before "Register::CallImplementation" + machine.collect @interpreter = Interpreter::Interpreter.new @interpreter.start Virtual.machine.init end