make the tests run (and pass) again

This commit is contained in:
Torsten Ruger 2015-05-04 11:10:40 +03:00
parent 4aca2caa05
commit 3659cb4b81
3 changed files with 16 additions and 25 deletions

View File

@ -1,15 +1,15 @@
require 'parslet' require 'parslet'
module Parfait module Parfait
eval(File.open("./lib/parfait/hash.rb").read) eval(File.open("./lib/parfait/hash.rb").read)
end end
require "ast/all"
require "stream_reader"
require "elf/object_writer" require "elf/object_writer"
require 'salama-reader' require 'salama-reader'
require 'parser/transform' require 'parser/transform'
require "sof/all" require "salama-object-file"
require "virtual/machine" require "virtual/machine"
require "register/register_machine" require "register/register_machine"
require "arm/arm_machine" require "arm/arm_machine"
require "ast/all"
require_relative "stream_reader"

View File

@ -15,21 +15,21 @@ module Virtual
# (ie garbage collection is reclaming, not destroying and recreating) although there may be a way to increase that number. # (ie garbage collection is reclaming, not destroying and recreating) although there may be a way to increase that number.
# #
# The ast is transformed to virtaul-machine objects, some of which represent code, some data. # The ast is transformed to virtaul-machine objects, some of which represent code, some data.
# #
# The next step transforms to the register machine layer, which is what actually executes. # The next step transforms to the register machine layer, which is what actually executes.
# #
# More concretely, a virtual machine is a sort of oo turing machine, it has a current instruction, executes the # More concretely, a virtual machine is a sort of oo turing machine, it has a current instruction, executes the
# instructions, fetches the next one and so on. # instructions, fetches the next one and so on.
# Off course the instructions are not soo simple, but in oo terms quite so. # Off course the instructions are not soo simple, but in oo terms quite so.
# #
# The machine is virtual in the sense that it is completely modeled in software, # The machine is virtual in the sense that it is completely modeled in software,
# it's complete state explicitly available (not implicitly by walking stacks or something) # it's complete state explicitly available (not implicitly by walking stacks or something)
# The machine has a no register, but local variables, a scope at each point in time. # The machine has a no register, but local variables, a scope at each point in time.
# Scope changes with calls and blocks, but is saved at each level. In terms of lower level implementation this means # Scope changes with calls and blocks, but is saved at each level. In terms of lower level implementation this means
# that the the model is such that what is a variable in ruby, never ends up being just on the pysical stack. # that the the model is such that what is a variable in ruby, never ends up being just on the pysical stack.
# #
class Machine class Machine
def initialize def initialize
@ -59,19 +59,9 @@ module Virtual
syntax = @parser.parse_with_debug(bytes) syntax = @parser.parse_with_debug(bytes)
parts = Parser::Transform.new.apply(syntax) parts = Parser::Transform.new.apply(syntax)
main = Virtual::CompiledMethod.main main = Virtual::CompiledMethod.main
expressions = parts.compile( main , self.message ) parts.compile( main , self.message )
end end
# run the instruction stream given. Instructions are a graph and executing means traversing it.
# If there is no next instruction the machine stops
def run instruction
while instruction do
next_instruction = instruction.next
instruction.execute
instruction = next_instruction
end
end
end end
end end

View File

@ -1,5 +1,6 @@
require_relative "type" require_relative "type"
require "parfait/message" require "parfait/message"
require "parfait/frame"
module Positioned module Positioned
def position def position
@ -9,7 +10,7 @@ module Positioned
def set_position pos def set_position pos
# resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures # resetting of position used to be error, but since relink and dynamic instruction size it is ok. in measures
if @position != nil and ((@position - pos).abs > 32) if @position != nil and ((@position - pos).abs > 32)
raise "position set again #{pos}!=#{@position} for #{self}" raise "position set again #{pos}!=#{@position} for #{self}"
end end
@position = pos @position = pos
end end
@ -19,7 +20,7 @@ module Virtual
# our machine is made up of objects, some of which are code, some data # our machine is made up of objects, some of which are code, some data
# #
# during compilation objects are module Virtual objects, but during execution they are not scoped # during compilation objects are module Virtual objects, but during execution they are not scoped
# #
# So compiling/linking/assembly turns ::virtual objects into binary that represents ruby objects at runtime # So compiling/linking/assembly turns ::virtual objects into binary that represents ruby objects at runtime
# The equivalence is listed below (i'll try and work on clearer correspondence later) # The equivalence is listed below (i'll try and work on clearer correspondence later)
# ::Virtual Runtime / parfait # ::Virtual Runtime / parfait
@ -65,7 +66,7 @@ module Virtual
when Array , Symbol , String , Virtual::CompiledMethod , Virtual::Block , Virtual::StringConstant when Array , Symbol , String , Virtual::CompiledMethod , Virtual::Block , Virtual::StringConstant
@@ARRAY @@ARRAY
when Hash when Hash
@@HASH.merge :keys => object.keys , :values => object.values @@HASH.merge :keys => object.keys , :values => object.values
when Virtual::BootClass when Virtual::BootClass
@@CLAZZ @@CLAZZ
when Virtual::BootSpace when Virtual::BootSpace