getting the symbols to work

This commit is contained in:
Torsten Ruger 2015-06-01 08:33:23 +03:00
parent bee73801eb
commit f08d9659fc
9 changed files with 53 additions and 42 deletions

View File

@ -45,16 +45,15 @@ module Register
objekt.set_position at objekt.set_position at
at += objekt.mem_length at += objekt.mem_length
end end
@machine.objects.each do |objekt|
objekt.position
end
end end
def assemble def assemble
# must be same order as link # must be same order as link
begin begin
link link
@machine.objects.each do |objekt|
objekt.position
end
# first we need to create the binary code for the methods # first we need to create the binary code for the methods
@machine.objects.each do |objekt| @machine.objects.each do |objekt|
next unless objekt.is_a? Parfait::Method next unless objekt.is_a? Parfait::Method
@ -88,16 +87,17 @@ module Register
# and then plonk that binary data into the method.code array # and then plonk that binary data into the method.code array
def assemble_binary_method method def assemble_binary_method method
stream = StringIO.new stream = StringIO.new
begin
method.info.blocks.each do |block| method.info.blocks.each do |block|
block.codes.each do |code| block.codes.each do |code|
begin
code.assemble( stream ) code.assemble( stream )
rescue => e
puts "Method error #{method.name}\n#{Sof::Writer.write(method.info.blocks).to_s[0...2000]}"
puts Sof::Writer.write(code)
raise e
end
end end
end end
rescue => e
puts "Method error #{method.name}\n#{Sof::Writer.write(method.info.blocks).to_s[0...2000]}"
raise e
end
method.code.fill_with 0 method.code.fill_with 0
index = 1 index = 1
stream.each_byte do |b| stream.each_byte do |b|
@ -204,7 +204,7 @@ module Register
def assemble_String( string ) def assemble_String( string )
str = string.to_s if string.is_a? Parfait::Word str = string.to_s if string.is_a? Parfait::Word
str = string.to_s if str.is_a? Symbol str = string.to_s if string.is_a? Symbol
word = (str.length + 7) / 32 # all object are multiple of 8 words (7 for header) word = (str.length + 7) / 32 # all object are multiple of 8 words (7 for header)
raise "String too long (implement split string!) #{word}" if word > 15 raise "String too long (implement split string!) #{word}" if word > 15
# first line is integers, convention is that following lines are the same # first line is integers, convention is that following lines are the same

View File

@ -32,7 +32,7 @@ module Register
# need a temporay place because of indexed load/store # need a temporay place because of indexed load/store
tmp = RegisterReference.tmp_reg tmp = RegisterReference.tmp_reg
# for constants we have to "move" the constants value # for constants we have to "move" the constants value
if( code.from.is_a? Parfait::Value) if( code.from.is_a?(Parfait::Value) or code.from.is_a?(Symbol))
move1 = LoadConstant.new( tmp , code.from ) move1 = LoadConstant.new( tmp , code.from )
else # while otherwise we "load" else # while otherwise we "load"
move1 = GetSlot.new( tmp , code.from.reg , code.from.index ) move1 = GetSlot.new( tmp , code.from.reg , code.from.index )

View File

@ -64,12 +64,6 @@ module Virtual
end end
end end
# double check that all objects dependents are really in the space too (debugging)
def double_check
@objects.each do |o|
check o
end
end
# Objects are data and get assembled after functions # Objects are data and get assembled after functions
def add_object o def add_object o
return false if @objects.include?(o) return false if @objects.include?(o)
@ -77,21 +71,6 @@ module Virtual
true true
end end
# private
def check object , recurse = true
raise "No good #{object.class}" unless @objects.include? object
puts "#{object.class}"
puts "#{object}" if object.class == Parfait::Word
check object.get_layout
return unless recurse
object.get_layout.each do |name|
check name , false
inst = object.instance_variable_get "@#{name}".to_sym
check inst , false
end
end
# Passes may be added to by anyone who wants # Passes may be added to by anyone who wants
# This is intentionally quite flexible, though one sometimes has to watch the order of them # This is intentionally quite flexible, though one sometimes has to watch the order of them
# most ordering is achieved by ordering the requires and using add_pass # most ordering is achieved by ordering the requires and using add_pass
@ -112,10 +91,10 @@ module Virtual
end end
def self.boot def self.boot
instance = self.instance me = self.instance
# 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
instance.boot_parfait! me.boot_parfait!
instance me
end end
def self.instance def self.instance
@instance ||= Machine.new @instance ||= Machine.new

View File

@ -73,6 +73,35 @@ class Symbol
def get_layout def get_layout
Virtual::Machine.instance.class_mappings[:Word].object_layout Virtual::Machine.instance.class_mappings[:Word].object_layout
end end
def mem_length
to_s.length
end
# not the prettiest addition to the game, but it wasn't me who decided symbols are frozen in 2.x
def cache_positions
unless defined?(@@symbol_positions)
@@symbol_positions = {}
end
@@symbol_positions
end
def position
pos = cache_positions[self]
if pos == nil
str = "position accessed but not set, "
str += "Machine has object=#{Virtual::Machine.instance.objects.include?(self)} "
raise str + " for Symbol:#{self}"
end
pos
end
def set_position pos
# resetting of position used to be error, but since relink and dynamic instruction size it is ok.
# in measures (of 32)
old = cache_positions[self]
if old != nil and ((old - pos).abs > 32)
raise "position set again #{pos}!=#{old} for #{self}"
end
cache_positions[self] = pos
end
end end
module Parfait module Parfait

View File

@ -14,9 +14,12 @@ module Virtual
unless object.has_layout? unless object.has_layout?
object.init_layout object.init_layout
end end
if( object.is_a? Parfait::Method)
object.info.constants.each{|c| keep(c) }
end
layout = object.get_layout layout = object.get_layout
#puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(layout)}"
keep layout keep layout
#puts "Layout #{layout.get_object_class.name} #{Machine.instance.objects.include?(layout)}"
layout.each do |name| layout.each do |name|
inst = object.instance_variable_get "@#{name}".to_sym inst = object.instance_variable_get "@#{name}".to_sym
keep inst keep inst

View File

@ -21,9 +21,9 @@ module Virtual
def run block def run block
block.codes.dup.each do |code| block.codes.dup.each do |code|
if code.is_a?(NewFrame) if code.is_a?(NewFrame)
kind = "next_frame" kind = :next_frame
elsif code.is_a?(NewMessage) elsif code.is_a?(NewMessage)
kind = "next_message" kind = :next_message
else else
next next
end end

View File

@ -22,13 +22,13 @@ module Virtual
puts "function was already removed #{ function.name}" puts "function was already removed #{ function.name}"
return return
end end
#puts "stayer #{function.name}"
@gonners.delete function @gonners.delete function
function.info.blocks.each do |block| function.info.blocks.each do |block|
block.codes.each do |code| block.codes.each do |code|
if code.is_a? Virtual::MessageSend if code.is_a? Virtual::MessageSend
str_name = code.name.to_s
@gonners.each do |stay| @gonners.each do |stay|
remove stay if(stay.name == str_name) remove stay if(stay.name == code.name)
end end
end end
remove code.method if code.is_a? Virtual::MethodCall remove code.method if code.is_a? Virtual::MethodCall

View File

@ -13,7 +13,7 @@ require 'parslet/convenience'
module Fragments module Fragments
# need a code generator, for arm # need a code generator, for arm
def setup def setup
@object_machine = Virtual::Machine.new "Arm" @object_machine = Virtual::Machin.new "Arm"
end end
def parse def parse

View File

@ -9,7 +9,7 @@ module VirtualHelper
end end
def check def check
machine = Virtual::Machine.reboot machine = Virtual::Machine.boot
expressions = machine.compile_main @string_input expressions = machine.compile_main @string_input
if( expressions.first.is_a? Parfait::Method ) if( expressions.first.is_a? Parfait::Method )
# stops the whole objectspace beeing tested # stops the whole objectspace beeing tested