still recoving from previous block - function change. no more exceptions at least

This commit is contained in:
Torsten Ruger
2014-06-11 00:38:46 +03:00
parent e9519d4f05
commit 7cca50cd3a
9 changed files with 72 additions and 74 deletions

View File

@ -35,8 +35,7 @@ module Vm
attr_reader :name , :next , :codes , :function , :assigns , :uses
attr_accessor :branch
def reachable
ret = []
def reachable ret = []
add_next ret
add_branch ret
ret
@ -98,14 +97,14 @@ module Vm
return if @next.nil?
return if ret.include? @next
ret << @next
ret + @next.reachable
@next.reachable ret
end
# helper for determining reachable blocks
def add_branch ret
return if @branch.nil?
return if ret.include? @branch
ret << @branch
ret + @branch.reachable
@branch.reachable ret
end
end
end

View File

@ -13,7 +13,7 @@ module Vm
@super_class = super_class
@meta_class = MetaClass.new(self)
end
attr_reader :name , :functions , :meta_class
attr_reader :name , :functions , :meta_class , :context
def add_function function
raise "not a function #{function}" unless function.is_a? Function

View File

@ -31,12 +31,13 @@ module Vm
@classes = {}
@context = Context.new(self)
@context.current_class = get_or_create_class :Object
@main = Function.new("main")
@context.function = @main
#global objects (data)
@objects = []
@entry = Core::Kernel::main_start Vm::Block.new("main_entry",nil,nil)
@entry = RegisterMachine.instance.main_start @context
#main gets executed between entry and exit
@main = Block.new("main",nil,nil)
@exit = Core::Kernel::main_exit Vm::Block.new("main_exit",nil,nil)
@exit = RegisterMachine.instance.main_exit @context
boot_classes
end
attr_reader :context , :main , :classes , :entry , :exit

View File

@ -48,11 +48,11 @@ module Vm
end
end
set_return return_type
@exit = Core::Kernel::function_exit( Vm::Block.new("exit" , self , nil) , name )
@exit = RegisterMachine.instance.function_exit( Vm::Block.new("exit" , self , nil) , name )
@return = Block.new("return", self , @exit)
@body = Block.new("body", self , @return)
@insert_at = @body
@entry = Core::Kernel::function_entry( Vm::Block.new("entry" , self , @body) ,name )
@entry = RegisterMachine.instance.function_entry( Vm::Block.new("entry" , self , @body) ,name )
@locals = []
@linked = false # incase link is called twice, we only calculate locals once
end
@ -153,7 +153,6 @@ module Vm
# to the current block
# also symbols are supported and wrapped as register usages (for bare metal programming)
def method_missing(meth, *args, &block)
puts "passing #{meth} , #{args.length} #{args}"
add_code RegisterMachine.instance.send(meth , *args)
end
@ -169,7 +168,7 @@ module Vm
if push = b.call_block?
locals = locals_at b
if(locals.empty?)
puts "Empty #{b}"
puts "Empty #{b.name}"
else
puts "PUSH #{push}"
push.set_registers(locals)