work on ObjectWriter

Back to the root! but lots of adjusting
ObjectWriter takes machine, machine has space
Virtual constants become Parfait::Objects etc
This commit is contained in:
Torsten Ruger
2015-05-16 12:53:10 +03:00
parent 9d8dc68bf4
commit 9376b8bc16
12 changed files with 65 additions and 50 deletions

View File

@ -34,21 +34,21 @@ module Virtual
def initialize
@parser = Parser::Salama.new
the_end = Halt.new
#the_end = Halt.new
@passes = [ "Virtual::SendImplementation" ]
@space = Parfait::Space.new
# @message = Message.new(the_end , the_end , :Object)
end
attr_reader :message , :passes , :space
attr_reader :message , :passes , :space , :init , :main
def run_passes
@passes.each do |pass_class|
blocks = [@init] + main.blocks
@classes.values.each do |c|
blocks = [@init] + @main.blocks
@space.classes.values.each do |c|
c.instance_methods.each {|f| blocks += f.blocks }
end
#puts "running #{pass_class}"
all.each do |block|
blocks.each do |block|
pass = eval pass_class
raise "no such pass-class as #{pass_class}" unless pass
pass.new.run(block)
@ -90,8 +90,9 @@ module Virtual
# 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!
# 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
# 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.get_or_create_class :Object
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
obj.add_instance_method Builtin::Object.send(f , nil)

View File

@ -14,13 +14,15 @@ module Virtual
new_codes = [ ]
ref = code.me
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
# value known at compile time, got do something with it
if(ref.value)
me = ref.value
if( me.is_a? BootClass )
if( me.is_a? Parfait::Class )
raise "unimplemented #{code}"
elsif( me.is_a? ObjectConstant )
elsif( me.is_a? Parfait::Object )
# get the function from my class. easy peasy
method = me.clazz.get_instance_method(code.name)
puts "Me is #{me.class}"
method = me.get_class.get_instance_method(code.name)
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
new_codes << MethodCall.new( method )
else
@ -29,9 +31,11 @@ module Virtual
kernel = Virtual::Machine.instance.space.get_or_create_class(:Kernel)
method = kernel.get_instance_method(:__send)
new_codes << MethodCall.new( method )
raise "unimplemented #{code}"
raise "unimplemented: \n#{code}"
end
else
# must defer send to run-time
# So inlining the code from message.send (in the future)
raise "not constant/ known object for send #{ref.inspect}"
end
block.replace(code , new_codes )