move machine to module level

makes for shorter, more concise, access
also remove one more bug possibility
(reinitiation)
This commit is contained in:
Torsten Ruger 2015-06-01 08:40:17 +03:00
parent 336e6c18de
commit 5726d2c181
21 changed files with 35 additions and 30 deletions

View File

@ -15,5 +15,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::CallImplementation" Virtual.machine.add_pass "Arm::CallImplementation"
end end

View File

@ -10,5 +10,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::ConstantImplementation" Virtual.machine.add_pass "Arm::ConstantImplementation"
end end

View File

@ -9,5 +9,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::GetImplementation" Virtual.machine.add_pass "Arm::GetImplementation"
end end

View File

@ -11,5 +11,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::MainImplementation" Virtual.machine.add_pass "Arm::MainImplementation"
end end

View File

@ -9,5 +9,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::ReturnImplementation" Virtual.machine.add_pass "Arm::ReturnImplementation"
end end

View File

@ -15,5 +15,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::SaveImplementation" Virtual.machine.add_pass "Arm::SaveImplementation"
end end

View File

@ -9,5 +9,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::SetImplementation" Virtual.machine.add_pass "Arm::SetImplementation"
end end

View File

@ -9,5 +9,5 @@ module Arm
end end
end end
end end
Virtual::Machine.instance.add_pass "Arm::TransferImplementation" Virtual.machine.add_pass "Arm::TransferImplementation"
end end

View File

@ -8,7 +8,7 @@ module Builtin
function = Virtual::CompiledMethodInfo.create_method(:Kernel,:__init__ , []) function = Virtual::CompiledMethodInfo.create_method(:Kernel,:__init__ , [])
# puts "INIT LAYOUT #{function.get_layout.get_layout}" # puts "INIT LAYOUT #{function.get_layout.get_layout}"
function.info.return_type = Virtual::Integer function.info.return_type = Virtual::Integer
main = Virtual::Machine.instance.space.get_main main = Virtual.machine.space.get_main
me = Virtual::Self.new(Virtual::Reference) me = Virtual::Self.new(Virtual::Reference)
code = Virtual::Set.new(Virtual::Self.new(me.type), me) code = Virtual::Set.new(Virtual::Self.new(me.type), me)
function.info.add_code(code) function.info.add_code(code)

View File

@ -23,7 +23,7 @@ module Builtin
var_name = get_function.args.first var_name = get_function.args.first
return_to = get_function.return_type return_to = get_function.return_type
index_function = ::Virtual::Machine.instance.space.get_class_by_name(:Object).resolve_method(:index_of) index_function = ::Virtual.machine.space.get_class_by_name(:Object).resolve_method(:index_of)
# get_function.push( [me] ) # get_function.push( [me] )
# index = get_function.call( index_function ) # index = get_function.call( index_function )

View File

@ -23,5 +23,5 @@ module Register
end end
end end
end end
Virtual::Machine.instance.add_pass "Register::CallImplementation" Virtual.machine.add_pass "Register::CallImplementation"
end end

View File

@ -18,5 +18,5 @@ module Register
end end
end end
end end
Virtual::Machine.instance.add_pass "Register::ReturnImplementation" Virtual.machine.add_pass "Register::ReturnImplementation"
end end

View File

@ -42,5 +42,5 @@ module Register
end end
end end
end end
Virtual::Machine.instance.add_pass "Register::SetImplementation" Virtual.machine.add_pass "Register::SetImplementation"
end end

View File

@ -37,7 +37,7 @@ module Virtual
def self.create_method( class_name , method_name , args) def self.create_method( class_name , method_name , args)
raise "uups #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol raise "uups #{class_name}.#{class_name.class}" unless class_name.is_a? Symbol
raise "uups #{method_name}.#{method_name.class}" unless class_name.is_a? Symbol raise "uups #{method_name}.#{method_name.class}" unless class_name.is_a? Symbol
clazz = Machine.instance.space.get_class_by_name class_name clazz = Virtual.machine.space.get_class_by_name class_name
raise "No such class #{class_name}" unless clazz raise "No such class #{class_name}" unless clazz
method = clazz.create_instance_method( method_name , Virtual.new_list(args)) method = clazz.create_instance_method( method_name , Virtual.new_list(args))
method.info = CompiledMethodInfo.new method.info = CompiledMethodInfo.new

View File

@ -39,6 +39,7 @@ module Virtual
@parser = Parser::Salama.new @parser = Parser::Salama.new
@passes = [ "Virtual::SendImplementation" ] @passes = [ "Virtual::SendImplementation" ]
@objects = [] @objects = []
@booted = false
end end
attr_reader :passes , :space , :class_mappings , :init , :objects attr_reader :passes , :space , :class_mappings , :init , :objects
@ -91,20 +92,17 @@ module Virtual
end end
def self.boot def self.boot
me = self.instance me = Virtual.machine
# boot is a verb here. this is a somewhat tricky process which is in it's own file, boot.rb # boot is a verb here. this is a somewhat tricky process which is in it's own file, boot.rb
raise "already booted" if @booted
me.boot_parfait! me.boot_parfait!
me me
end end
def self.instance
@instance ||= Machine.new
end
# for testing, make sure no old artefacts hang around # for testing, make sure no old artefacts hang around
#maybe should be moved to test dir #maybe should be moved to test dir
def self.reboot def self.reboot
@instance = nil raise "redo"
self.boot
end end
def compile_main bytes def compile_main bytes
syntax = @parser.parse_with_debug(bytes) syntax = @parser.parse_with_debug(bytes)
@ -112,6 +110,13 @@ module Virtual
Compiler.compile( parts , @space.get_main ) Compiler.compile( parts , @space.get_main )
end end
end end
def self.machine
unless defined?(@machine)
@machine = Machine.new
end
@machine
end
end end
require_relative "boot" require_relative "boot"

View File

@ -9,7 +9,7 @@ module FakeMem
super() super()
@memory = [0,nil] @memory = [0,nil]
@position = nil @position = nil
if Virtual::Machine.instance.class_mappings if Virtual.machine.class_mappings
init_layout init_layout
else else
#puts "No init for #{self.class}:#{self.object_id}" #puts "No init for #{self.class}:#{self.object_id}"
@ -17,7 +17,7 @@ module FakeMem
end end
def init_layout def init_layout
vm_name = self.class.name.split("::").last.to_sym vm_name = self.class.name.split("::").last.to_sym
clazz = Virtual::Machine.instance.class_mappings[vm_name] clazz = Virtual.machine.class_mappings[vm_name]
raise "Class not found #{vm_name}" unless clazz raise "Class not found #{vm_name}" unless clazz
raise "Layout not set #{vm_name}" unless clazz.object_layout raise "Layout not set #{vm_name}" unless clazz.object_layout
self.set_layout clazz.object_layout self.set_layout clazz.object_layout
@ -25,7 +25,7 @@ module FakeMem
#TODO, this is copied from module Positioned, maybe avoid duplication ? #TODO, this is copied from module Positioned, maybe avoid duplication ?
def position def position
if @position.nil? if @position.nil?
str = "IN machine #{Virtual::Machine.instance.objects.include?(self)}\n" str = "IN machine #{Virtual.machine.objects.include?(self)}\n"
raise str + "position not set for #{self.class} at #{mem_length} for #{self.inspect[0...100]}" raise str + "position not set for #{self.class} at #{mem_length} for #{self.inspect[0...100]}"
end end
@position @position
@ -71,7 +71,7 @@ class Symbol
true true
end end
def get_layout def get_layout
Virtual::Machine.instance.class_mappings[:Word].object_layout Virtual.machine.class_mappings[:Word].object_layout
end end
def mem_length def mem_length
to_s.length to_s.length
@ -87,7 +87,7 @@ class Symbol
pos = cache_positions[self] pos = cache_positions[self]
if pos == nil if pos == nil
str = "position accessed but not set, " str = "position accessed but not set, "
str += "Machine has object=#{Virtual::Machine.instance.objects.include?(self)} " str += "Machine has object=#{Virtual.machine.objects.include?(self)} "
raise str + " for Symbol:#{self}" raise str + " for Symbol:#{self}"
end end
pos pos

View File

@ -9,7 +9,7 @@ module Virtual
def keep object def keep object
return if object.nil? return if object.nil?
return unless Machine.instance.add_object object return unless Virtual.machine.add_object object
#puts "adding #{object.class}" #puts "adding #{object.class}"
unless object.has_layout? unless object.has_layout?
object.init_layout object.init_layout

View File

@ -13,5 +13,5 @@ module Virtual
end end
end end
end end
Virtual::Machine.instance.add_pass "Virtual::EnterImplementation" Virtual.machine.add_pass "Virtual::EnterImplementation"
end end

View File

@ -48,5 +48,5 @@ module Virtual
end end
end end
end end
Virtual::Machine.instance.add_pass "Virtual::FrameImplementation" Virtual.machine.add_pass "Virtual::FrameImplementation"
end end

View File

@ -13,5 +13,5 @@ module Virtual
end end
end end
end end
Virtual::Machine.instance.add_pass "Virtual::GetImplementation" Virtual.machine.add_pass "Virtual::GetImplementation"
end end

View File

@ -30,7 +30,7 @@ module Virtual
else else
# note: this is the current view: call internal send, even the method name says else # note: this is the current view: call internal send, even the method name says else
# but send is "special" and accesses the internal method name and resolves. # but send is "special" and accesses the internal method name and resolves.
kernel = Virtual::Machine.instance.space.get_class_by_name("Kernel") kernel = Virtual.machine.space.get_class_by_name("Kernel")
method = kernel.get_instance_method(:__send) method = kernel.get_instance_method(:__send)
new_codes << MethodCall.new( method ) new_codes << MethodCall.new( method )
raise "unimplemented: \n#{code}" raise "unimplemented: \n#{code}"