2014-06-03 13:49:02 +02:00
|
|
|
module Boot
|
|
|
|
class Object
|
|
|
|
module ClassMethods
|
|
|
|
|
|
|
|
# return the index of the variable. Now "normal" code can't really do anything with that, but
|
|
|
|
# set/get instance variable use it.
|
|
|
|
# This is just a placeholder, as we code this in ruby, but the instance methods need the definition before.
|
|
|
|
def index_of context , name = Vm::Integer
|
2014-06-24 18:34:36 +02:00
|
|
|
index_function = Vm::Function.new(:index_of , Vm::Reference , [Vm::Reference] , Vm::Integer )
|
2014-06-03 13:49:02 +02:00
|
|
|
return index_function
|
|
|
|
end
|
|
|
|
|
2014-06-14 22:48:12 +02:00
|
|
|
def self.layout
|
|
|
|
layout_function = Vm::Function.new(:layout , Vm::Reference , [ ] , Vm::Reference )
|
|
|
|
layout_function.at_index 2
|
|
|
|
layout_function
|
|
|
|
end
|
2014-06-03 13:49:02 +02:00
|
|
|
|
|
|
|
# in ruby, how this goes is
|
|
|
|
# def _get_instance_variable var
|
|
|
|
# i = self.index_of(var)
|
|
|
|
# return at_index(i)
|
|
|
|
# end
|
2014-06-24 18:34:36 +02:00
|
|
|
# The at_index is just "below" the api, something we need but don't want to expose, so we can't code the above in ruby
|
2014-06-03 13:49:02 +02:00
|
|
|
def _get_instance_variable context , name = Vm::Integer
|
2014-06-24 18:34:36 +02:00
|
|
|
get_function = Vm::Function.new(:_get_instance_variable , Vm::Reference , [ Vm::Reference ] , Vm::Mystery )
|
2014-06-07 16:59:44 +02:00
|
|
|
me = get_function.receiver
|
|
|
|
var_name = get_function.args.first
|
2014-06-03 13:49:02 +02:00
|
|
|
return_to = get_function.return_type
|
2014-06-24 18:34:36 +02:00
|
|
|
|
2014-06-13 22:41:45 +02:00
|
|
|
index_function = context.object_space.get_or_create_class(:Object).resolve_function(:index_of)
|
2014-06-10 22:57:56 +02:00
|
|
|
get_function.push( [me] )
|
2014-06-24 18:34:36 +02:00
|
|
|
index = get_function.call( index_function )
|
2014-06-10 22:57:56 +02:00
|
|
|
|
2014-06-24 18:34:36 +02:00
|
|
|
after_body = get_function.new_block("after_index")
|
2014-06-10 22:57:56 +02:00
|
|
|
get_function.insert_at after_body
|
2014-06-24 18:34:36 +02:00
|
|
|
|
2014-06-10 22:57:56 +02:00
|
|
|
get_function.pop([me])
|
|
|
|
return_to.at_index( get_function , me , return_to )
|
2014-06-24 18:34:36 +02:00
|
|
|
|
2014-06-03 13:49:02 +02:00
|
|
|
get_function.set_return return_to
|
|
|
|
return get_function
|
|
|
|
end
|
|
|
|
|
2014-06-24 11:36:32 +02:00
|
|
|
def _set_instance_variable(context , name = Vm::Integer , value = Vm::Integer )
|
2014-06-24 18:34:36 +02:00
|
|
|
set_function = Vm::Function.new(:_set_instance_variable , Vm::Reference ,[Vm::Reference ,Vm::Reference], Vm::Mystery )
|
2014-06-24 11:23:58 +02:00
|
|
|
me = set_function.receiver
|
|
|
|
var_name = set_function.args.first
|
|
|
|
return_to = set_function.return_type
|
|
|
|
index_function = context.object_space.get_or_create_class(:Object).resolve_function(:index_of)
|
|
|
|
set_function.push( [me] )
|
|
|
|
set_function.call( index_function )
|
|
|
|
after_body = set_function.new_block("after_index")
|
|
|
|
|
|
|
|
set_function.insert_at after_body
|
|
|
|
set_function.pop([me])
|
|
|
|
return_to.at_index( set_function , me , return_to )
|
|
|
|
set_function.set_return return_to
|
|
|
|
return set_function
|
2014-06-03 13:49:02 +02:00
|
|
|
end
|
|
|
|
|
2014-06-05 17:17:00 +02:00
|
|
|
def _get_singleton_method(context , name )
|
2014-06-03 13:49:02 +02:00
|
|
|
raise name
|
|
|
|
end
|
2014-06-05 17:17:00 +02:00
|
|
|
def _add_singleton_method(context, method)
|
2014-06-03 13:49:02 +02:00
|
|
|
raise "4"
|
|
|
|
end
|
2014-06-05 17:17:00 +02:00
|
|
|
def initialize(context)
|
2014-06-03 13:49:02 +02:00
|
|
|
raise "4"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
extend ClassMethods
|
|
|
|
end
|
|
|
|
end
|