work on function entry and exit. fix stack instructions

This commit is contained in:
Torsten Ruger
2014-05-06 12:42:43 +03:00
parent 22b5117c8b
commit 12b6800efe
6 changed files with 48 additions and 28 deletions

View File

@ -15,8 +15,8 @@ module Vm
def initialize(name , args = [])
super(name)
@args = args
@entry = Block.new("entry_#{name}")
@exit = Block.new("exit_#{name}")
@entry = Kernel::function_entry( name )
@exit = Kernel::function_exit( name )
end
attr_reader :args , :entry , :exit

View File

@ -1,16 +1,29 @@
module Vm
module Kernel
def self.start
#TODO extract args into array of strings
Machine.instance.main_entry
end
def self.exit
# Machine.exit mov r7 , 0 + swi 0
Machine.instance.main_exit
end
def self.puts string
# should unwrap from string to char*
Machine.instance.puts string
class Kernel
#there are no Kernel instances, only class methods.
# We use this module syntax to avoid the (ugly) self.
module ClassMethods
def main_start
#TODO extract args into array of strings
Machine.instance.main_start
end
def main_exit
# Machine.exit mov r7 , 0 + swi 0
Machine.instance.main_exit
end
def function_entry f_name
Machine.instance.function_entry f_name
end
def function_exit f_name
Machine.instance.function_exit f_name
end
def self.puts string
# should unwrap from string to char*
Machine.instance.puts string
end
end
extend ClassMethods
end
end

View File

@ -28,10 +28,10 @@ module Vm
@objects = []
# global functions
@functions = []
@entry = Vm::Kernel::start
@entry = Vm::Kernel::main_start
#main gets executed between entry and exit
@main = nil
@exit = Vm::Kernel::exit
@exit = Vm::Kernel::main_exit
end
attr_reader :context , :main , :functions