removing passes (before arm)

collector becomes a function
minimizer unused
This commit is contained in:
Torsten Ruger 2015-10-18 19:27:02 +03:00
parent fa4949fc80
commit 15b570f5cf
9 changed files with 19 additions and 24 deletions

View File

@ -74,6 +74,7 @@ module Interpreter
def tick def tick
return unless @instruction return unless @instruction
@clock += 1 @clock += 1
#puts @instruction
name = @instruction.class.name.split("::").last name = @instruction.class.name.split("::").last
fetch = send "execute_#{name}" fetch = send "execute_#{name}"
return unless fetch return unless fetch

View File

@ -6,11 +6,7 @@ require "virtual/padding"
require "virtual/parfait_adapter" require "virtual/parfait_adapter"
require "phisol/compiler" require "phisol/compiler"
require "virtual/instruction"
require "virtual/method_source" require "virtual/method_source"
# the passes _are_ order dependant
require "virtual/passes/minimizer"
require "virtual/passes/collector"
class Fixnum class Fixnum

View File

@ -1,10 +1,10 @@
module Virtual module Virtual
# collect anything that is in the space but and reachable from init # collect anything that is in the space but and reachable from init
class Collector module Collector
def run def collect
# init= Parfait::Space.object_space.get_class_by_name("Kernel").get_instance_method "__init__" # 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 keep Parfait::Space.object_space , 0
end end
@ -12,7 +12,7 @@ module Virtual
return if object.nil? return if object.nil?
#puts "adding #{' ' * depth}:#{object.class}" #puts "adding #{' ' * depth}:#{object.class}"
#puts "ADD #{object.first.class}, #{object.last.class}" if object.is_a? Array #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? return unless object.respond_to? :has_layout?
if( object.is_a? Parfait::Method) if( object.is_a? Parfait::Method)
object.source.constants.each{|c| object.source.constants.each{|c|

View File

@ -1,5 +1,5 @@
require 'parslet/convenience' require 'parslet/convenience'
require_relative "collector"
module Virtual module Virtual
# The Virtual Machine is a object based virtual machine in which ruby is implemented. # 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) # The "machine" is not part of the run-time (Parfait)
class Machine class Machine
include Collector
FIRST_PASS = "Register::CallImplementation"
def initialize def initialize
@parser = Parser::Salama.new @parser = Parser::Salama.new
@passes = [ FIRST_PASS ] @passes = [ ]
@objects = {} @objects = {}
@booted = false @booted = false
end end
@ -51,8 +50,6 @@ module Virtual
# runs housekeeping Minimizer and Collector # runs housekeeping Minimizer and Collector
# Has to be called before run_after # Has to be called before run_after
def run_before stop_at def run_before stop_at
Minimizer.new.run
Collector.new.run
@blocks = [@init] @blocks = [@init]
@space.classes.values.each do |c| @space.classes.values.each do |c|
c.instance_methods.each do |f| c.instance_methods.each do |f|
@ -85,8 +82,9 @@ module Virtual
# as before, run all passes that are registered # as before, run all passes that are registered
# (but now finer control with before/after versions) # (but now finer control with before/after versions)
def run_passes def run_passes
run_before FIRST_PASS return if @passes.empty?
run_after FIRST_PASS run_before @passes.first
run_after @passes.first
end end
# Objects are data and get assembled after functions # Objects are data and get assembled after functions

View File

@ -25,7 +25,7 @@ module Virtual
@gonners.delete function @gonners.delete function
function.source.blocks.each do |block| function.source.blocks.each do |block|
block.codes.each do |code| 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 end
end end

View File

@ -9,6 +9,7 @@ class HelloTest < MiniTest::Test
statements = machine.parse_and_compile @string_input statements = machine.parse_and_compile @string_input
output_at = "Register::CallImplementation" output_at = "Register::CallImplementation"
#{}"Register::CallImplementation" #{}"Register::CallImplementation"
machine.collect
machine.run_before output_at machine.run_before output_at
#puts Sof.write(machine.space) #puts Sof.write(machine.space)
machine.run_after output_at machine.run_after output_at

View File

@ -5,7 +5,7 @@ class AddTest < MiniTest::Test
include Ticker include Ticker
def setup def setup
Virtual.machine.boot machine = Virtual.machine.boot
code = s(:class, :Object, code = s(:class, :Object,
s(:derives, nil), s(:derives, nil),
s(:statements, s(:statements,
@ -19,7 +19,7 @@ class AddTest < MiniTest::Test
s(:int, 7))))))) s(:int, 7)))))))
Phisol::Compiler.compile( code ) Phisol::Compiler.compile( code )
Virtual.machine.run_before "Register::CallImplementation" machine.collect
@interpreter = Interpreter::Interpreter.new @interpreter = Interpreter::Interpreter.new
@interpreter.start Virtual.machine.init @interpreter.start Virtual.machine.init
end end

View File

@ -48,15 +48,14 @@ class Object
end end
end end
HERE HERE
Virtual.machine.boot machine = Virtual.machine.boot
syntax = Parser::Salama.new.parse_with_debug(@string_input) syntax = Parser::Salama.new.parse_with_debug(@string_input)
parts = Parser::Transform.new.apply(syntax) parts = Parser::Transform.new.apply(syntax)
#puts parts.inspect #puts parts.inspect
Phisol::Compiler.compile( parts ) Phisol::Compiler.compile( parts )
machine.collect
# statements = Virtual.machine.boot.parse_and_compile @string_input # statements = Virtual.machine.boot.parse_and_compile @string_input
# Phisol::Compiler.compile( statements , Virtual.machine.space.get_main ) # Phisol::Compiler.compile( statements , Virtual.machine.space.get_main )
Virtual.machine.run_before "Register::CallImplementation"
@interpreter = Interpreter::Interpreter.new @interpreter = Interpreter::Interpreter.new
@interpreter.start Virtual.machine.init @interpreter.start Virtual.machine.init
#show_ticks # get output of what is #show_ticks # get output of what is

View File

@ -4,7 +4,7 @@ class TestPuts < MiniTest::Test
include AST::Sexp include AST::Sexp
include Ticker include Ticker
def setup def setup
Virtual.machine.boot machine = Virtual.machine.boot
code = s(:class, :Object, code = s(:class, :Object,
s(:derives, nil), s(:derives, nil),
s(:statements, s(:statements,
@ -19,7 +19,7 @@ class TestPuts < MiniTest::Test
s(:string, "Hello again"))))))) s(:string, "Hello again")))))))
Phisol::Compiler.compile( code ) Phisol::Compiler.compile( code )
Virtual.machine.run_before "Register::CallImplementation" machine.collect
@interpreter = Interpreter::Interpreter.new @interpreter = Interpreter::Interpreter.new
@interpreter.start Virtual.machine.init @interpreter.start Virtual.machine.init
end end