fixing assembly (wip)

main entry is the main problem, still polishing
This commit is contained in:
Torsten Ruger 2015-05-26 20:17:03 +03:00
parent 8413f6b470
commit 96c59ac144
4 changed files with 14 additions and 29 deletions

View File

@ -20,15 +20,9 @@ module Register
def link def link
@space.set_position(0) @space.set_position(0)
at = @space.mem_length # first jump instruction at = @space.mem_length
# then all functions
@space.objects.each do | objekt| @space.objects.each do | objekt|
next unless objekt.is_a? Parfait::Method next if objekt.is_a? Parfait::Space
objekt.info.set_position(at)
at += objekt.info.mem_length
end
#and then all data object
@objects.each do | objekt|
objekt.set_position at objekt.set_position at
at += objekt.mem_length at += objekt.mem_length
end end

View File

@ -90,22 +90,21 @@ module Virtual
obj.add_instance_method Builtin::Object.send(f , nil) obj.add_instance_method Builtin::Object.send(f , nil)
end end
obj = @class_mappings["Kernel"] obj = @class_mappings["Kernel"]
# create main first, __init__ calls it # create dummy main first, __init__ calls it
@main = Builtin::Kernel.send(:main , @context) [:putstring,:exit,:__send , :main ].each do |f|
obj.add_instance_method @main
underscore_init = Builtin::Kernel.send(:__init__ ,nil) #store , so we don't have to resolve it below
obj.add_instance_method underscore_init
[:putstring,:exit,:__send].each do |f|
obj.add_instance_method Builtin::Kernel.send(f , nil) obj.add_instance_method Builtin::Kernel.send(f , nil)
end end
# and the @init block in turn _jumps_ to __init__ underscore_init = obj.add_instance_method Builtin::Kernel.send(:__init__, nil)
# 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 = @class_mappings["Integer"] obj = @class_mappings["Integer"]
[:putint,:fibo].each do |f| [:putint,:fibo].each do |f|
obj.add_instance_method Builtin::Integer.send(f , nil) obj.add_instance_method Builtin::Integer.send(f , nil)
end end
# and the @init block in turn _jumps_ to __init__
# 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))
end end
end end
end end

View File

@ -28,11 +28,6 @@ module Virtual
# MUST have an uncoditional branch. And remember, all roads lead to return. # MUST have an uncoditional branch. And remember, all roads lead to return.
class CompiledMethodInfo class CompiledMethodInfo
# return the main function (the top level) into which code is compiled
# this just create a "main" with create_method , see there
def self.main
self.create_method( "Kernel" , "main" , [] )
end
# create method does two things # create method does two things
# first it creates the parfait method, for the given class, with given argument names # first it creates the parfait method, for the given class, with given argument names

View File

@ -36,14 +36,12 @@ module Virtual
@parser = Parser::Salama.new @parser = Parser::Salama.new
@passes = [ "Virtual::SendImplementation" ] @passes = [ "Virtual::SendImplementation" ]
end end
attr_reader :message , :passes , :space , :class_mappings attr_reader :message , :passes , :space , :class_mappings , :init
def run_passes def run_passes
#TODO puts "INIT #{@init}"
@passes.each do |pass_class| @passes.each do |pass_class|
puts "run pass #{pass_class}" puts "run pass #{pass_class}"
blocks = []#[@init] #TODO + @main.blocks blocks = [@init]
@space.classes.values.each do |c| @space.classes.values.each do |c|
c.instance_methods.each do |f| c.instance_methods.each do |f|
nb = f.info.blocks nb = f.info.blocks
@ -98,8 +96,7 @@ module Virtual
def compile_main bytes def compile_main bytes
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::CompiledMethodInfo.main Compiler.compile( parts , @space.get_main )
Compiler.compile( parts , main )
end end
end end
end end