2014-05-06 11:47:07 +02:00
|
|
|
module Core
|
2014-05-06 11:42:43 +02:00
|
|
|
class Kernel
|
|
|
|
|
|
|
|
#there are no Kernel instances, only class methods.
|
2014-05-06 20:36:28 +02:00
|
|
|
# We use this module syntax to avoid the (ugly) self (also eases searching).
|
2014-05-06 11:42:43 +02:00
|
|
|
module ClassMethods
|
2014-05-13 17:21:24 +02:00
|
|
|
def main_start block
|
2014-05-06 11:42:43 +02:00
|
|
|
#TODO extract args into array of strings
|
2014-05-13 17:21:24 +02:00
|
|
|
Vm::CMachine.instance.main_start block
|
2014-05-14 09:47:30 +02:00
|
|
|
block
|
2014-05-06 11:42:43 +02:00
|
|
|
end
|
2014-05-13 17:21:24 +02:00
|
|
|
def main_exit block
|
2014-05-06 11:42:43 +02:00
|
|
|
# Machine.exit mov r7 , 0 + swi 0
|
2014-05-13 17:21:24 +02:00
|
|
|
Vm::CMachine.instance.main_exit block
|
2014-05-14 09:47:30 +02:00
|
|
|
block
|
2014-05-06 11:42:43 +02:00
|
|
|
end
|
2014-05-13 17:21:24 +02:00
|
|
|
def function_entry block , f_name
|
|
|
|
Vm::CMachine.instance.function_entry block , f_name
|
2014-05-06 11:42:43 +02:00
|
|
|
end
|
2014-05-13 17:21:24 +02:00
|
|
|
def function_exit block , f_name
|
|
|
|
Vm::CMachine.instance.function_exit block , f_name
|
2014-05-06 11:42:43 +02:00
|
|
|
end
|
2014-05-13 20:06:12 +02:00
|
|
|
|
|
|
|
#TODO this is in the wrong place. It is a function that returns a function object
|
|
|
|
# while all other methods add their code into some block. --> kernel
|
2014-05-15 15:54:23 +02:00
|
|
|
def putstring context
|
2014-05-13 20:06:12 +02:00
|
|
|
function = Vm::Function.new(:putstring , [Vm::Integer , Vm::Integer ] )
|
|
|
|
block = function.body
|
|
|
|
# should be another level of indirection, ie write(io,str)
|
|
|
|
ret = Vm::CMachine.instance.write_stdout(block)
|
|
|
|
function.return_type = ret
|
|
|
|
function
|
2014-05-06 11:42:43 +02:00
|
|
|
end
|
2014-05-15 15:54:23 +02:00
|
|
|
|
|
|
|
def putint context
|
|
|
|
function = Vm::Function.new(:putint , [Vm::Integer , Vm::Integer ] )
|
|
|
|
block = function.body
|
|
|
|
buffer = Vm::StringConstant.new(" ")
|
|
|
|
context.program.add_object buffer
|
|
|
|
# should be another level of indirection, ie write(io,str)
|
|
|
|
ret = Vm::CMachine.instance.integer_to_s(block , buffer)
|
|
|
|
function.return_type = ret
|
|
|
|
function
|
|
|
|
end
|
2014-05-02 07:02:25 +02:00
|
|
|
end
|
2014-05-06 11:42:43 +02:00
|
|
|
|
|
|
|
extend ClassMethods
|
2014-05-02 07:02:25 +02:00
|
|
|
end
|
|
|
|
end
|