improve boot

also move to superclass not superclass_name in class
Makes ripples
This commit is contained in:
Torsten Ruger 2015-05-16 20:16:49 +03:00
parent 7085dee510
commit fe2be323d8
13 changed files with 56 additions and 30 deletions

View File

@ -27,7 +27,7 @@ module Parfait
include FakeMem
def self.new_object *args
# Space.space.get_class_by_name(:Word)
puts "I am #{self}"
#puts "I am #{self}"
object = self.new(*args)
object
end

View File

@ -15,12 +15,12 @@ require_relative "meta_class"
module Parfait
class Class < Module
def initialize name , super_class_name = :Object
def initialize name , super_class = nil
super()
# class methods
@instance_methods = []
@name = name.to_sym
@super_class_name = super_class_name.to_sym
@super_class = super_class
@meta_class = Virtual::MetaClass.new(self)
@object_layout = []
end
@ -31,6 +31,13 @@ module Parfait
@instance_methods << method
end
# this needs to be done during booting as we can't have all the classes and superclassses
# instantiated. By that logic it should maybe be part of vm rather.
# On the other hand vague plans to load the hierachy from sof exist, so for now...
def set_super_class sup
@super_class = sup
end
def set_instance_names list
@object_layout = Layout.new_object
@object_layout.set_names list
@ -45,7 +52,7 @@ module Parfait
def resolve_method m_name
method = get_instance_method(m_name)
unless method
unless( @name == :Object)
unless( @name == "Object" )
supr = Space.space.get_class_by_name(@super_class_name)
method = supr.resolve_method(m_name)
end

View File

@ -33,7 +33,7 @@ module Virtual
name = name.to_sym
f = @functions.detect{ |f| f.name == name }
return f if f
if( @me_self == :Object )
if( @me_self == "Object" )
puts "no function for :#{name} in Meta #{@me_self.inspect}"
return nil
else #recurse up class hierachy unless we're at Object

View File

@ -53,7 +53,7 @@ module Parfait
# this is the way to instantiate classes (not Parfait::Class.new)
# so we get and keep exactly one per name
def get_class_by_name name
raise "uups #{name}.#{name.class}" unless name.is_a? Symbol
raise "uups #{name}.#{name.class}" unless name.is_a? String or name.is_a? Word
c = @classes[name]
c
end

View File

@ -12,7 +12,7 @@ module Builtin
# so it is responsible for initial setup (and relocation)
def __init__ context
function = Virtual::CompiledMethod.new(:__init__ , [] , Virtual::Integer)
clazz = Virtual::Machine.instance.space.get_class_by_name :Kernel
clazz = Virtual::Machine.instance.space.get_class_by_name "Kernel"
method = clazz.resolve_method :main
me = Virtual::Self.new(Virtual::Reference)
code = Virtual::Set.new(Virtual::Self.new(me.type), me)

View File

@ -35,7 +35,7 @@ module Virtual
end
def initialize name , arg_names , receiver = Virtual::Self.new , return_type = Virtual::Mystery
@name = name.to_sym
@class_name = :Object
@class_name = "Object"
@arg_names = arg_names
@locals = []
@tmps = []

View File

@ -37,7 +37,7 @@ module Virtual
#the_end = Halt.new
@passes = [ "Virtual::SendImplementation" ]
@space = Parfait::Space.new
# @message = Message.new(the_end , the_end , :Object)
# @message = Message.new(the_end , the_end , "Object" )
end
attr_reader :message , :passes , :space , :init , :main
@ -77,28 +77,34 @@ module Virtual
def self.boot
instance = self.instance
instance.boot_classes! # boot is a verb here
instance.boot_parfait! # boot is a verb here
instance.boot
instance
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
end
# boot the classes, ie create a minimal set of classes with a minimal set of functions
# minimal means only that which can not be coded in ruby
# CompiledMethods are grabbed from respective modules by sending the method name. This should return the
# implementation of the method (ie a method object), not actually try to implement it (as that's impossible in ruby)
def boot_classes!
def boot_parfait!
boot_classes!
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we
# have to define some dummies, just for the other to compile
# TODO: go through the virtual parfait layer and adjust function names to what they really are
obj = @space.create_class :Object , []
obj = @space.get_class_by_name "Object"
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
obj.add_instance_method Builtin::Object.send(f , nil)
end
obj = @space.create_class :Kernel , []
puts "CREATE Kernel #{obj}"
obj = @space.get_class_by_name "Kernel"
# create main first, __init__ calls it
@main = Builtin::Kernel.send(:main , @context)
obj.add_instance_method @main
@ -111,20 +117,33 @@ module Virtual
# the point of which is that by the time main executes, all is "normal"
@init = Block.new(:_init_ , nil )
@init.add_code(Register::RegisterMain.new(underscore_init))
obj = @space.create_class :Integer , []
obj = @space.get_class_by_name "Integer"
[:putint,:fibo].each do |f|
obj.add_instance_method Builtin::Integer.send(f , nil)
end
obj = @space.create_class :Word , []
obj = @space.get_class_by_name "Word"
[:get , :set , :puts].each do |f|
obj.add_instance_method Builtin::Word.send(f , nil)
end
obj = space.create_class :Array , []
obj = space.get_class_by_name "List"
[:get , :set , :push].each do |f|
obj.add_instance_method Builtin::Array.send(f , nil)
end
end
def boot_classes!
values = [ "Integer" , "Object" , "Value" , "Kernel"]
rest = ["Word" , "Class" , "Dictionary" , "Space" , "List", "Layout"]
(values + rest).each { |cl| @space.create_class(cl , []) }
value_class = @space.get_class_by_name "Value"
@space.get_class_by_name("Integer").set_super_class( value_class )
object_class = @space.get_class_by_name("Object")
object_class.set_super_class( value_class )
rest.each do |name|
cl = @space.get_class_by_name( name )
cl.set_super_class(object_class)
end
end
def boot
# read all the files needed for a minimal system at compile
classes = ["object"]

View File

@ -28,7 +28,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.instance.space.get_class_by_name("Kernel")
method = kernel.get_instance_method(:__send)
new_codes << MethodCall.new( method )
raise "unimplemented: \n#{code}"

View File

@ -45,7 +45,7 @@ class TestBasic < MiniTest::Test
def pest_module_name
@string_input = 'FooBar '
@output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER"
@output = ""
check
end

View File

@ -44,7 +44,7 @@ class TestConversion < MiniTest::Test
def pest_module_name
@string_input = 'FooBar '
@output = "---RETURN_MARKER- &1 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods: []RETURN_MARKER name: :FooBarRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *1RETURN_MARKER"
@output = nil
check
end

View File

@ -11,7 +11,7 @@ class Object
end
end
HERE
@output = "-&5 Virtual::BootClass(:length => -1, :name => :Object, :super_class_name => :Object)*^* :instance_methods -Virtual::CompiledMethod(:name => :index_of, :class_name => :Object, :arg_names => &1 Virtual::Reference, :return_type => Virtual::Integer)*^* :locals []*^* :tmps []*^* :receiver [*1]*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^* -Virtual::CompiledMethod(:name => :_get_instance_variable, :class_name => :Object, :receiver => &1 Virtual::Reference, :return_type => &2 Virtual::Mystery)*^* :arg_names [*1]*^* :locals []*^* :tmps []*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^* -Virtual::CompiledMethod(:name => :_set_instance_variable, :class_name => :Object, :receiver => &1 Virtual::Reference, :return_type => &2 Virtual::Mystery)*^* :arg_names [*1, *1]*^* :locals []*^* :tmps []*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^* -&4 Virtual::CompiledMethod(:name => :get_class, :class_name => :Object)*^* :arg_names []*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => *2)*^* :return_type Virtual::Return(:index => 5, :type => *2)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::InstanceGet(:name => :layout)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => *2)*^* :from &3 Virtual::Return(:index => 5, :type => *2)*^* -Virtual::Set()*^* :to Virtual::NewName(:index => 4, :type => *2)*^* :from Parfait::Word(:string => :get_class)*^* -Virtual::MessageSend(:name => :get_class)*^* :me &3 Virtual::Return(:index => 5, :type => *2)*^* :args []*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^* -&4 Virtual::CompiledMethod(:name => :get_class, :class_name => :Object)*^* :arg_names []*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => *2)*^* :return_type Virtual::Return(:index => 5, :type => *2)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::InstanceGet(:name => :layout)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => *2)*^* :from &3 Virtual::Return(:index => 5, :type => *2)*^* -Virtual::Set()*^* :to Virtual::NewName(:index => 4, :type => *2)*^* :from Parfait::Word(:string => :get_class)*^* -Virtual::MessageSend(:name => :get_class)*^* :me &3 Virtual::Return(:index => 5, :type => *2)*^* :args []*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^* :meta_class Virtual::MetaClass(:length => -1, :me_self => *5)*^* :functions []"
@output = nil
check
end

View File

@ -9,7 +9,7 @@ def foo(x)
5
end
HERE
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => :Object)*^* :arg_names [:x]*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => Virtual::Mystery)*^* :return_type &1 Virtual::Return(:index => 5, :type => Virtual::Integer)*^* :value &2 Virtual::IntegerConstant(:integer => 5)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set(:to => *1, :from => *2)*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => 'Object')*^* :arg_names [:x]*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => Virtual::Mystery)*^* :return_type &1 Virtual::Return(:index => 5, :type => Virtual::Integer)*^* :value &2 Virtual::IntegerConstant(:integer => 5)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set(:to => *1, :from => *2)*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
check
end
@ -20,7 +20,7 @@ def foo()
end
foo()
HERE
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => :Object)*^* :arg_names []*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => *1)*^* :return_type Virtual::Return(:index => 5, :type => *1)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => *1)*^* :from &4 Virtual::Self(:index => 3, :type => *1)*^* -Virtual::Set(:from => Parfait::Word('puts'))*^* :to Virtual::NewName(:index => 4, :type => *1)*^* -Virtual::Set(:from => Parfait::Word('Hello'))*^* :to &3 Virtual::Return(:index => 5, :type => &2 Virtual::Reference, :value => Parfait::Word('Hello'))*^* -Virtual::Set()*^* :to &5 Virtual::NewMessageSlot(:index => 0, :type => &2 Virtual::Reference, :value => *3)*^* :from &3 Virtual::Return(:index => 5, :type => &2 Virtual::Reference, :value => Parfait::Word('Hello'))*^* -Virtual::MessageSend(:name => :puts)*^* :me &4 Virtual::Self(:index => 3, :type => *1)*^* :args [*5]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^*-Virtual::Return(:index => 5, :type => &1 Virtual::Mystery)"
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => 'Object')*^* :arg_names []*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => *1)*^* :return_type Virtual::Return(:index => 5, :type => *1)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => *1)*^* :from &4 Virtual::Self(:index => 3, :type => *1)*^* -Virtual::Set(:from => Parfait::Word('puts'))*^* :to Virtual::NewName(:index => 4, :type => *1)*^* -Virtual::Set(:from => Parfait::Word('Hello'))*^* :to &3 Virtual::Return(:index => 5, :type => &2 Virtual::Reference, :value => Parfait::Word('Hello'))*^* -Virtual::Set()*^* :to &5 Virtual::NewMessageSlot(:index => 0, :type => &2 Virtual::Reference, :value => *3)*^* :from &3 Virtual::Return(:index => 5, :type => &2 Virtual::Reference, :value => Parfait::Word('Hello'))*^* -Virtual::MessageSend(:name => :puts)*^* :me &4 Virtual::Self(:index => 3, :type => *1)*^* :args [*5]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)*^*-Virtual::Return(:index => 5, :type => &1 Virtual::Mystery)"
check
end
@ -30,7 +30,7 @@ def String.length(x)
@length
end
HERE
@output = "---RETURN_MARKER- &7 !ruby/object:Virtual::CompiledMethodRETURN_MARKER name: :lengthRETURN_MARKER args:RETURN_MARKER - :xRETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: &6 !ruby/object:Boot::BootClassRETURN_MARKER instance_methods:RETURN_MARKER - &2 !ruby/object:Virtual::CompiledMethodRETURN_MARKER name: :getRETURN_MARKER args:RETURN_MARKER - &1 !ruby/class 'Virtual::Integer'RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &3 !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :getRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *2RETURN_MARKER name: :get_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *3RETURN_MARKER - &4 !ruby/object:Virtual::CompiledMethodRETURN_MARKER name: :setRETURN_MARKER args:RETURN_MARKER - *1RETURN_MARKER - *1RETURN_MARKER locals: []RETURN_MARKER tmps: []RETURN_MARKER receiver: *1RETURN_MARKER return_type: *1RETURN_MARKER blocks:RETURN_MARKER - &5 !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :setRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *4RETURN_MARKER name: :set_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *5RETURN_MARKER name: :WordRETURN_MARKER super_class_name: :ObjectRETURN_MARKER meta_class: !ruby/object:Boot::MetaClassRETURN_MARKER functions: []RETURN_MARKER me_self: *6RETURN_MARKER return_type: !ruby/object:Virtual::ReturnRETURN_MARKER index: 0RETURN_MARKER type: !ruby/class 'Virtual::Mystery'RETURN_MARKER blocks:RETURN_MARKER - &8 !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :lengthRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodEnter {}RETURN_MARKER - !ruby/object:Virtual::InstanceGetRETURN_MARKER name: :lengthRETURN_MARKER - !ruby/object:Virtual::BlockRETURN_MARKER method: *7RETURN_MARKER name: :length_returnRETURN_MARKER branch: RETURN_MARKER codes:RETURN_MARKER - !ruby/object:Virtual::MethodReturn {}RETURN_MARKER current: *8RETURN_MARKER"
@output = nil
check
end
@ -41,7 +41,7 @@ def foo(x)
2 + 5
end
HERE
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => :Object)*^* :arg_names [:x]*^* :locals [:abba]*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &1 Virtual::Mystery)*^* :return_type Virtual::Return(:index => 5, :type => &1 Virtual::Mystery)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *1)*^* :from Virtual::FrameSlot(:index => 1, :type => &3 Virtual::Integer, :value => *4)*^* -Virtual::Set()*^* :to &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* :from &5 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &3 Virtual::Integer)*^* :from &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* -Virtual::Set(:from => Parfait::Word('+'))*^* :to Virtual::NewName(:index => 4, :type => *1)*^* -Virtual::Set()*^* :to &8 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *7)*^* :from &7 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &9 Virtual::NewMessageSlot(:index => 0, :type => &3 Virtual::Integer, :value => *8)*^* :from &8 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *7)*^* -Virtual::MessageSend(:name => :+)*^* :me &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* :args [*9]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => 'Object')*^* :arg_names [:x]*^* :locals [:abba]*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &1 Virtual::Mystery)*^* :return_type Virtual::Return(:index => 5, :type => &1 Virtual::Mystery)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *1)*^* :from Virtual::FrameSlot(:index => 1, :type => &3 Virtual::Integer, :value => *4)*^* -Virtual::Set()*^* :to &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* :from &5 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &3 Virtual::Integer)*^* :from &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* -Virtual::Set(:from => Parfait::Word('+'))*^* :to Virtual::NewName(:index => 4, :type => *1)*^* -Virtual::Set()*^* :to &8 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *7)*^* :from &7 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &9 Virtual::NewMessageSlot(:index => 0, :type => &3 Virtual::Integer, :value => *8)*^* :from &8 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *7)*^* -Virtual::MessageSend(:name => :+)*^* :me &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* :args [*9]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
check
end
@ -51,7 +51,7 @@ def foo()
2 + 5
end
HERE
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => :Object)*^* :arg_names []*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &1 Virtual::Mystery)*^* :return_type Virtual::Return(:index => 5, :type => &1 Virtual::Mystery)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &3 Virtual::Integer)*^* :from &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* -Virtual::Set(:from => Parfait::Word('+'))*^* :to Virtual::NewName(:index => 4, :type => *1)*^* -Virtual::Set()*^* :to &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* :from &5 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &7 Virtual::NewMessageSlot(:index => 0, :type => &3 Virtual::Integer, :value => *6)*^* :from &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* -Virtual::MessageSend(:name => :+)*^* :me &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* :args [*7]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
@output = "-Virtual::CompiledMethod(:name => :foo, :class_name => 'Object')*^* :arg_names []*^* :locals []*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &1 Virtual::Mystery)*^* :return_type Virtual::Return(:index => 5, :type => &1 Virtual::Mystery)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 2)*^* -Virtual::NewMessage(:length => -1)*^* -Virtual::Set()*^* :to Virtual::NewSelf(:index => 3, :type => &3 Virtual::Integer)*^* :from &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* -Virtual::Set(:from => Parfait::Word('+'))*^* :to Virtual::NewName(:index => 4, :type => *1)*^* -Virtual::Set()*^* :to &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* :from &5 Virtual::IntegerConstant(:integer => 5)*^* -Virtual::Set()*^* :to &7 Virtual::NewMessageSlot(:index => 0, :type => &3 Virtual::Integer, :value => *6)*^* :from &6 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *5)*^* -Virtual::MessageSend(:name => :+)*^* :me &4 Virtual::Return(:index => 5, :type => &3 Virtual::Integer, :value => *2)*^* :args [*7]*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
check
end
@ -65,7 +65,7 @@ def ofthen(n)
end
end
HERE
@output = "-Virtual::CompiledMethod(:name => :ofthen, :class_name => :Object)*^* :arg_names [:n]*^* :locals [:isit, :maybenot]*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &4 Virtual::Mystery)*^* :return_type &6 Virtual::Return(:index => 5, :type => &1 Virtual::Integer)*^* :value &7 Virtual::IntegerConstant(:integer => 667)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *1, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 0)*^* -Virtual::IsTrueBranch(:to => *8)*^* -Virtual::Block(:length => -1, :name => :if_false)*^* :codes -Virtual::Set(:to => *6, :from => *7)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *4)*^* :from Virtual::FrameSlot(:index => 2, :type => *1, :value => *6)*^* -Virtual::UnconditionalBranch(:to => *9)*^* -&8 Virtual::Block(:length => -1, :name => :if_true)*^* :codes -Virtual::Set()*^* :to &5 Virtual::Return(:index => 5, :type => *1)*^* :value &3 Virtual::IntegerConstant(:integer => 42)*^* :from &3 Virtual::IntegerConstant(:integer => 42)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *4)*^* :from Virtual::FrameSlot(:index => 1, :type => *1)*^* :value &5 Virtual::Return(:index => 5, :type => *1)*^* :value &3 Virtual::IntegerConstant(:integer => 42)*^* -&9 Virtual::Block(:length => -1, :name => :if_merge)*^* :codes []*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
@output = "-Virtual::CompiledMethod(:name => :ofthen, :class_name => 'Object')*^* :arg_names [:n]*^* :locals [:isit, :maybenot]*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &4 Virtual::Mystery)*^* :return_type &6 Virtual::Return(:index => 5, :type => &1 Virtual::Integer)*^* :value &7 Virtual::IntegerConstant(:integer => 667)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *1, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 0)*^* -Virtual::IsTrueBranch(:to => *8)*^* -Virtual::Block(:length => -1, :name => :if_false)*^* :codes -Virtual::Set(:to => *6, :from => *7)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *4)*^* :from Virtual::FrameSlot(:index => 2, :type => *1, :value => *6)*^* -Virtual::UnconditionalBranch(:to => *9)*^* -&8 Virtual::Block(:length => -1, :name => :if_true)*^* :codes -Virtual::Set()*^* :to &5 Virtual::Return(:index => 5, :type => *1)*^* :value &3 Virtual::IntegerConstant(:integer => 42)*^* :from &3 Virtual::IntegerConstant(:integer => 42)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *4)*^* :from Virtual::FrameSlot(:index => 1, :type => *1)*^* :value &5 Virtual::Return(:index => 5, :type => *1)*^* :value &3 Virtual::IntegerConstant(:integer => 42)*^* -&9 Virtual::Block(:length => -1, :name => :if_merge)*^* :codes []*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
check
end
@ -79,7 +79,7 @@ def fibonaccit(n)
end
end
HERE
@output = ""
@output = "-Virtual::CompiledMethod(:name => :ofthen, :class_name => 'Object')*^* :arg_names [:n]*^* :locals [:isit, :maybenot]*^* :tmps []*^* :receiver Virtual::Self(:index => 3, :type => &4 Virtual::Mystery)*^* :return_type &6 Virtual::Return(:index => 5, :type => &1 Virtual::Integer)*^* :value &7 Virtual::IntegerConstant(:integer => 667)*^* :blocks -Virtual::Block(:length => -1, :name => :enter)*^* :codes -Virtual::MethodEnter(:length => -1)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *1, :value => *2)*^* :from &2 Virtual::IntegerConstant(:integer => 0)*^* -Virtual::IsTrueBranch(:to => *8)*^* -Virtual::Block(:length => -1, :name => :if_false)*^* :codes -Virtual::Set(:to => *6, :from => *7)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *4)*^* :from Virtual::FrameSlot(:index => 2, :type => *1, :value => *6)*^* -Virtual::UnconditionalBranch(:to => *9)*^* -&8 Virtual::Block(:length => -1, :name => :if_true)*^* :codes -Virtual::Set()*^* :to &5 Virtual::Return(:index => 5, :type => *1)*^* :value &3 Virtual::IntegerConstant(:integer => 42)*^* :from &3 Virtual::IntegerConstant(:integer => 42)*^* -Virtual::Set()*^* :to Virtual::Return(:index => 5, :type => *4)*^* :from Virtual::FrameSlot(:index => 1, :type => *1)*^* :value &5 Virtual::Return(:index => 5, :type => *1)*^* :value &3 Virtual::IntegerConstant(:integer => 42)*^* -&9 Virtual::Block(:length => -1, :name => :if_merge)*^* :codes []*^* -Virtual::Block(:length => -1, :name => :return)*^* :codes -Virtual::MethodReturn(:length => -1)"
check
end

View File

@ -9,7 +9,7 @@ module VirtualHelper
end
def check
machine = Virtual::Machine.boot
machine = Virtual::Machine.reboot
expressions = machine.compile_main @string_input
is = Sof::Writer.write(expressions)
#puts is