2014-09-10 20:35:52 +02:00
|
|
|
module Builtin
|
|
|
|
module Kernel
|
|
|
|
module ClassMethods
|
|
|
|
# main entry point, ie __init__ calls this
|
|
|
|
# defined here as empty, to be redefined
|
|
|
|
def main context
|
2015-05-24 12:31:33 +02:00
|
|
|
function = Virtual::CompiledMethodInfo.create_method("Kernel","main" , [])
|
|
|
|
function.info.return_type = Virtual::Integer
|
2014-09-10 20:35:52 +02:00
|
|
|
return function
|
|
|
|
end
|
|
|
|
# this is the really really first place the machine starts.
|
|
|
|
# it isn't really a function, ie it is jumped to (not called), exits and may not return
|
|
|
|
# so it is responsible for initial setup (and relocation)
|
|
|
|
def __init__ context
|
2015-05-24 12:31:33 +02:00
|
|
|
function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , [])
|
|
|
|
function.info.return_type = Virtual::Integer
|
|
|
|
clazz = Virtual::Machine.instance.class_mappings["Kernel"]
|
|
|
|
method = clazz.resolve_method Virtual::new_word "main"
|
2014-09-11 14:01:50 +02:00
|
|
|
me = Virtual::Self.new(Virtual::Reference)
|
2014-09-11 20:26:22 +02:00
|
|
|
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
|
2015-05-24 12:31:33 +02:00
|
|
|
function.info.add_code(code)
|
|
|
|
function.info.add_code Virtual::MethodCall.new(method)
|
2014-09-10 20:35:52 +02:00
|
|
|
return function
|
|
|
|
end
|
2015-05-13 11:15:14 +02:00
|
|
|
def putstring context
|
2015-05-24 12:31:33 +02:00
|
|
|
function = Virtual::CompiledMethodInfo.create_method("Kernel" , "putstring" , [] )
|
2014-09-10 20:35:52 +02:00
|
|
|
return function
|
|
|
|
ret = Virtual::RegisterMachine.instance.write_stdout(function)
|
|
|
|
function.set_return ret
|
|
|
|
function
|
|
|
|
end
|
|
|
|
def exit context
|
2015-05-24 12:31:33 +02:00
|
|
|
function = Virtual::CompiledMethodInfo.create_method("Kernel","exit" , [])
|
|
|
|
function.info.return_type = Virtual::Integer
|
2014-09-10 20:35:52 +02:00
|
|
|
return function
|
|
|
|
ret = Virtual::RegisterMachine.instance.exit(function)
|
|
|
|
function.set_return ret
|
|
|
|
function
|
|
|
|
end
|
2014-09-24 17:14:23 +02:00
|
|
|
def __send context
|
2015-05-24 12:31:33 +02:00
|
|
|
function = Virtual::CompiledMethodInfo.create_method("Kernel" ,"__send" , [] )
|
|
|
|
function.info.return_type = Virtual::Integer
|
2014-09-23 19:16:05 +02:00
|
|
|
return function
|
|
|
|
end
|
2014-09-10 20:35:52 +02:00
|
|
|
end
|
|
|
|
extend ClassMethods
|
|
|
|
end
|
|
|
|
end
|