rubyx/lib/register/builtin/kernel.rb

45 lines
1.6 KiB
Ruby
Raw Normal View History

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
function = Virtual::CompiledMethod.new(:main , [] , Virtual::Integer)
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
function = Virtual::CompiledMethod.new(:__init__ , [] , Virtual::Integer)
2015-05-16 11:54:11 +02:00
clazz = Virtual::Machine.instance.space.get_class_by_name :Kernel
2014-09-11 14:01:50 +02:00
method = clazz.resolve_method :main
me = Virtual::Self.new(Virtual::Reference)
2014-09-11 20:26:22 +02:00
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
2014-09-11 14:01:50 +02:00
function.add_code(code)
function.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
2014-09-10 20:35:52 +02:00
function = Virtual::CompiledMethod.new(:putstring , [] )
return function
ret = Virtual::RegisterMachine.instance.write_stdout(function)
function.set_return ret
function
end
def exit context
function = Virtual::CompiledMethod.new(:exit , [] , Virtual::Integer)
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
function = Virtual::CompiledMethod.new(:__send , [] , Virtual::Integer)
return function
end
2014-09-10 20:35:52 +02:00
end
extend ClassMethods
end
end