fixing assembly (wip)
main entry is the main problem, still polishing
This commit is contained in:
parent
8413f6b470
commit
96c59ac144
@ -20,15 +20,9 @@ module Register
|
||||
|
||||
def link
|
||||
@space.set_position(0)
|
||||
at = @space.mem_length # first jump instruction
|
||||
# then all functions
|
||||
at = @space.mem_length
|
||||
@space.objects.each do | objekt|
|
||||
next unless objekt.is_a? Parfait::Method
|
||||
objekt.info.set_position(at)
|
||||
at += objekt.info.mem_length
|
||||
end
|
||||
#and then all data object
|
||||
@objects.each do | objekt|
|
||||
next if objekt.is_a? Parfait::Space
|
||||
objekt.set_position at
|
||||
at += objekt.mem_length
|
||||
end
|
||||
|
@ -90,22 +90,21 @@ module Virtual
|
||||
obj.add_instance_method Builtin::Object.send(f , nil)
|
||||
end
|
||||
obj = @class_mappings["Kernel"]
|
||||
# create main first, __init__ calls it
|
||||
@main = Builtin::Kernel.send(:main , @context)
|
||||
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|
|
||||
# create dummy main first, __init__ calls it
|
||||
[:putstring,:exit,:__send , :main ].each do |f|
|
||||
obj.add_instance_method Builtin::Kernel.send(f , nil)
|
||||
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))
|
||||
underscore_init = obj.add_instance_method Builtin::Kernel.send(:__init__, nil)
|
||||
|
||||
obj = @class_mappings["Integer"]
|
||||
[:putint,:fibo].each do |f|
|
||||
obj.add_instance_method Builtin::Integer.send(f , nil)
|
||||
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
|
||||
|
@ -28,11 +28,6 @@ module Virtual
|
||||
# MUST have an uncoditional branch. And remember, all roads lead to return.
|
||||
|
||||
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
|
||||
# first it creates the parfait method, for the given class, with given argument names
|
||||
|
@ -36,14 +36,12 @@ module Virtual
|
||||
@parser = Parser::Salama.new
|
||||
@passes = [ "Virtual::SendImplementation" ]
|
||||
end
|
||||
attr_reader :message , :passes , :space , :class_mappings
|
||||
attr_reader :message , :passes , :space , :class_mappings , :init
|
||||
|
||||
def run_passes
|
||||
#TODO puts "INIT #{@init}"
|
||||
|
||||
@passes.each do |pass_class|
|
||||
puts "run pass #{pass_class}"
|
||||
blocks = []#[@init] #TODO + @main.blocks
|
||||
blocks = [@init]
|
||||
@space.classes.values.each do |c|
|
||||
c.instance_methods.each do |f|
|
||||
nb = f.info.blocks
|
||||
@ -98,8 +96,7 @@ module Virtual
|
||||
def compile_main bytes
|
||||
syntax = @parser.parse_with_debug(bytes)
|
||||
parts = Parser::Transform.new.apply(syntax)
|
||||
main = Virtual::CompiledMethodInfo.main
|
||||
Compiler.compile( parts , main )
|
||||
Compiler.compile( parts , @space.get_main )
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user