move main to object (from kernel)
This commit is contained in:
parent
24259fa18b
commit
079306dbf8
@ -67,7 +67,7 @@ module Parfait
|
|||||||
end
|
end
|
||||||
|
|
||||||
def get_main
|
def get_main
|
||||||
kernel = get_class_by_name "Kernel"
|
kernel = get_class_by_name "Object"
|
||||||
kernel.get_instance_method "main"
|
kernel.get_instance_method "main"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,25 +1,17 @@
|
|||||||
module Builtin
|
module Builtin
|
||||||
module Kernel
|
module Kernel
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
# main entry point, ie __init__ calls this
|
|
||||||
# defined here as empty, to be redefined
|
|
||||||
def main context
|
|
||||||
function = Virtual::CompiledMethodInfo.create_method("Kernel","main" , [])
|
|
||||||
function.info.return_type = Virtual::Integer
|
|
||||||
return function
|
|
||||||
end
|
|
||||||
# this is the really really first place the machine starts.
|
# 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
|
# 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)
|
# so it is responsible for initial setup (and relocation)
|
||||||
def __init__ context
|
def __init__ context
|
||||||
function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , [])
|
function = Virtual::CompiledMethodInfo.create_method("Kernel","__init__" , [])
|
||||||
function.info.return_type = Virtual::Integer
|
function.info.return_type = Virtual::Integer
|
||||||
clazz = Virtual::Machine.instance.class_mappings["Kernel"]
|
main = Virtual::Machine.instance.space.get_main
|
||||||
method = clazz.resolve_method Virtual::new_word "main"
|
|
||||||
me = Virtual::Self.new(Virtual::Reference)
|
me = Virtual::Self.new(Virtual::Reference)
|
||||||
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
|
code = Virtual::Set.new(Virtual::Self.new(me.type), me)
|
||||||
function.info.add_code(code)
|
function.info.add_code(code)
|
||||||
function.info.add_code Virtual::MethodCall.new(method)
|
function.info.add_code Virtual::MethodCall.new(main)
|
||||||
return function
|
return function
|
||||||
end
|
end
|
||||||
def putstring context
|
def putstring context
|
||||||
|
@ -2,20 +2,11 @@ module Builtin
|
|||||||
class Object
|
class Object
|
||||||
module ClassMethods
|
module ClassMethods
|
||||||
|
|
||||||
# return the index of the variable. Now "normal" code can't really do anything with that, but
|
# main entry point, ie __init__ calls this
|
||||||
# set/get instance variable use it.
|
# defined here as empty, to be redefined
|
||||||
# This is just a placeholder, as we code this in ruby,
|
def main context
|
||||||
# but the instance methods need the definition before.
|
function = Virtual::CompiledMethodInfo.create_method("Object","main" , [])
|
||||||
def index_of context , name = Virtual::Integer
|
return function
|
||||||
index_function = Virtual::CompiledMethodInfo.create_method("Object" , "index_of" , [Virtual::Reference] )
|
|
||||||
index_function.info.return_type = Virtual::Integer
|
|
||||||
return index_function
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.layout
|
|
||||||
layout_function = Virtual::Function.new(:layout , [ ] , Virtual::Reference , Virtual::Reference )
|
|
||||||
layout_function.at_index 2
|
|
||||||
layout_function
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# in ruby, how this goes is
|
# in ruby, how this goes is
|
||||||
|
@ -86,12 +86,12 @@ module Virtual
|
|||||||
# have to define some dummies, just for the other to compile
|
# have to define some dummies, just for the other to compile
|
||||||
# TODO: go through the virtual parfait layer and adjust function names to what they really are
|
# TODO: go through the virtual parfait layer and adjust function names to what they really are
|
||||||
obj = @class_mappings["Object"]
|
obj = @class_mappings["Object"]
|
||||||
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
[:main , :_get_instance_variable , :_set_instance_variable].each do |f|
|
||||||
obj.add_instance_method Builtin::Object.send(f , nil)
|
obj.add_instance_method Builtin::Object.send(f , nil)
|
||||||
end
|
end
|
||||||
obj = @class_mappings["Kernel"]
|
obj = @class_mappings["Kernel"]
|
||||||
# create dummy main first, __init__ calls it
|
# create dummy main first, __init__ calls it
|
||||||
[:putstring,:exit,:__send , :main ].each do |f|
|
[:putstring,:exit,:__send ].each do |f|
|
||||||
obj.add_instance_method Builtin::Kernel.send(f , nil)
|
obj.add_instance_method Builtin::Kernel.send(f , nil)
|
||||||
end
|
end
|
||||||
underscore_init = obj.add_instance_method Builtin::Kernel.send(:__init__, nil)
|
underscore_init = obj.add_instance_method Builtin::Kernel.send(:__init__, nil)
|
||||||
|
@ -24,10 +24,7 @@ HERE
|
|||||||
|
|
||||||
def test_puts_string
|
def test_puts_string
|
||||||
@string_input = <<HERE
|
@string_input = <<HERE
|
||||||
def foo()
|
putstring("Hello")
|
||||||
putstring("Hello")
|
|
||||||
end
|
|
||||||
foo()
|
|
||||||
HERE
|
HERE
|
||||||
check
|
check
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user