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
Virtual::Machine.instance.add_pass "Arm::CallImplementation"
Virtual.machine.add_pass "Arm::CallImplementation"
end

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ module Builtin
function = Virtual::CompiledMethodInfo.create_method(:Kernel,:__init__ , [])
# puts "INIT LAYOUT #{function.get_layout.get_layout}"
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)
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
function.info.add_code(code)

View File

@ -23,7 +23,7 @@ module Builtin
var_name = get_function.args.first
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] )
# index = get_function.call( index_function )

View File

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

View File

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

View File

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

View File

@ -37,7 +37,7 @@ module Virtual
def self.create_method( class_name , method_name , args)
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
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
method = clazz.create_instance_method( method_name , Virtual.new_list(args))
method.info = CompiledMethodInfo.new

View File

@ -39,6 +39,7 @@ module Virtual
@parser = Parser::Salama.new
@passes = [ "Virtual::SendImplementation" ]
@objects = []
@booted = false
end
attr_reader :passes , :space , :class_mappings , :init , :objects
@ -91,20 +92,17 @@ module Virtual
end
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
raise "already booted" if @booted
me.boot_parfait!
me
end
def self.instance
@instance ||= Machine.new
end
# for testing, make sure no old artefacts hang around
#maybe should be moved to test dir
def self.reboot
@instance = nil
self.boot
raise "redo"
end
def compile_main bytes
syntax = @parser.parse_with_debug(bytes)
@ -112,6 +110,13 @@ module Virtual
Compiler.compile( parts , @space.get_main )
end
end
def self.machine
unless defined?(@machine)
@machine = Machine.new
end
@machine
end
end
require_relative "boot"

View File

@ -9,7 +9,7 @@ module FakeMem
super()
@memory = [0,nil]
@position = nil
if Virtual::Machine.instance.class_mappings
if Virtual.machine.class_mappings
init_layout
else
#puts "No init for #{self.class}:#{self.object_id}"
@ -17,7 +17,7 @@ module FakeMem
end
def init_layout
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 "Layout not set #{vm_name}" unless 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 ?
def position
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]}"
end
@position
@ -71,7 +71,7 @@ class Symbol
true
end
def get_layout
Virtual::Machine.instance.class_mappings[:Word].object_layout
Virtual.machine.class_mappings[:Word].object_layout
end
def mem_length
to_s.length
@ -87,7 +87,7 @@ class Symbol
pos = cache_positions[self]
if pos == nil
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}"
end
pos

View File

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

View File

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

View File

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

View File

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

View File

@ -30,7 +30,7 @@ module Virtual
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.
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)
new_codes << MethodCall.new( method )
raise "unimplemented: \n#{code}"