rename method
This commit is contained in:
@ -4,28 +4,28 @@ module Boot
|
||||
# class is mainly a list of methods with a name (for now)
|
||||
# layout of object is seperated into Layout
|
||||
class BootClass < Virtual::ObjectConstant
|
||||
def initialize name , super_class = :Object
|
||||
def initialize name , super_class_name = :Object
|
||||
super()
|
||||
# class methods
|
||||
@methods = []
|
||||
@method_definitions = []
|
||||
@name = name.to_sym
|
||||
@super_class = super_class
|
||||
@super_class_name = super_class_name.to_sym
|
||||
@meta_class = MetaClass.new(self)
|
||||
end
|
||||
attr_reader :name , :methods , :meta_class , :context , :super_class
|
||||
def attributes
|
||||
[:name , :super_class]
|
||||
end
|
||||
def add_method method
|
||||
raise "not a method #{method}" unless method.is_a? Virtual::Method
|
||||
def add_method_definition method
|
||||
raise "not a method #{method}" unless method.is_a? Virtual::MethodDefinition
|
||||
raise "syserr " unless method.name.is_a? Symbol
|
||||
@methods << method
|
||||
@method_definitions << method
|
||||
end
|
||||
|
||||
def get_method fname
|
||||
def get_method_definition fname
|
||||
fname = fname.to_sym
|
||||
f = @methods.detect{ |f| f.name == fname }
|
||||
names = @methods.collect{|f| f.name }
|
||||
f = @method_definitions.detect{ |f| f.name == fname }
|
||||
names = @method_definitions.collect{|f| f.name }
|
||||
f
|
||||
end
|
||||
|
||||
@ -33,7 +33,7 @@ module Boot
|
||||
def resolve_method name
|
||||
fun = get_method name
|
||||
unless fun or name == :Object
|
||||
supr = @context.object_space.get_or_create_class(@super_class)
|
||||
supr = @context.object_space.get_or_create_class(@super_class_name)
|
||||
fun = supr.get_method name
|
||||
puts "#{supr.methods.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
|
||||
end
|
||||
|
@ -5,13 +5,13 @@ require "boot/object"
|
||||
require "boot/string"
|
||||
|
||||
module Boot
|
||||
# The BootSpace is contains all objects for a program. In functional terms it is a program, but on oo
|
||||
# The BootSpace contains all objects for a program. In functional terms it is a program, but in oo
|
||||
# it is a collection of objects, some of which are data, some classes, some functions
|
||||
|
||||
# The main entry is a function called (of all things) "main", This _must be supplied by the compling
|
||||
# There is a start and exit block that call main, which receives an array of strings
|
||||
|
||||
# While data "ususally" would live in a .data section, we may also "inline" it into the code
|
||||
# While data ususally would live in a .data section, we may also "inline" it into the code
|
||||
# in an oo system all data is represented as objects
|
||||
|
||||
class BootSpace
|
||||
@ -21,7 +21,7 @@ module Boot
|
||||
def initialize machine = nil
|
||||
super()
|
||||
@classes = {}
|
||||
@main = Virtual::Method.new("main" , [] )
|
||||
@main = Virtual::MethodDefinition.new("main" , [] )
|
||||
#global objects (data)
|
||||
@objects = []
|
||||
boot_classes
|
||||
@ -43,24 +43,24 @@ module Boot
|
||||
|
||||
# boot the classes, ie create a minimal set of classes with a minimal set of functions
|
||||
# minimal means only that which can not be coded in ruby
|
||||
# Functions are grabbed from respective modules by sending the sunction name. This should return the
|
||||
# implementation of the function (ie a function object), not actually try to implement it (as that's impossible in ruby)
|
||||
# MethodDefinitions are grabbed from respective modules by sending the method name. This should return the
|
||||
# implementation of the method (ie a method object), not actually try to implement it (as that's impossible in ruby)
|
||||
def boot_classes
|
||||
# very fiddly chicken 'n egg problem. Functions need to be in the right order, and in fact we have to define some
|
||||
# dummies, just for the other to compile
|
||||
obj = get_or_create_class :Object
|
||||
[:index_of , :_get_instance_variable , :_set_instance_variable].each do |f|
|
||||
#puts "Boot Object::#{f}"
|
||||
obj.add_method Boot::Object.send(f , @context)
|
||||
obj.add_method_definition Boot::Object.send(f , @context)
|
||||
end
|
||||
[:putstring,:putint,:fibo,:exit].each do |f|
|
||||
#puts "Boot Kernel::#{f}"
|
||||
obj.add_method Crystal::Kernel.send(f , @context)
|
||||
obj.add_method_definition Crystal::Kernel.send(f , @context)
|
||||
end
|
||||
obj = get_or_create_class :String
|
||||
[:get , :set].each do |f|
|
||||
#puts "Boot String::#{f}"
|
||||
obj.add_method Boot::String.send(f , @context)
|
||||
obj.add_method_definition Boot::String.send(f , @context)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -6,7 +6,7 @@ module Boot
|
||||
# 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 = Virtual::Integer
|
||||
index_function = Virtual::Method.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
|
||||
index_function = Virtual::MethodDefinition.new(:index_of , Virtual::Reference , [Virtual::Reference] , Virtual::Integer )
|
||||
return index_function
|
||||
end
|
||||
|
||||
@ -23,7 +23,7 @@ module Boot
|
||||
# end
|
||||
# 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
|
||||
def _get_instance_variable context , name = Virtual::Integer
|
||||
get_function = Virtual::Method.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery )
|
||||
get_function = Virtual::MethodDefinition.new(:_get_instance_variable , [ Virtual::Reference ] , Virtual::Reference ,Virtual::Mystery )
|
||||
return get_function
|
||||
me = get_function.receiver
|
||||
var_name = get_function.args.first
|
||||
@ -44,7 +44,7 @@ module Boot
|
||||
end
|
||||
|
||||
def _set_instance_variable(context , name = Virtual::Integer , value = Virtual::Integer )
|
||||
set_function = Virtual::Method.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery )
|
||||
set_function = Virtual::MethodDefinition.new(:_set_instance_variable ,[Virtual::Reference ,Virtual::Reference], Virtual::Reference ,Virtual::Mystery )
|
||||
return set_function
|
||||
receiver set_function
|
||||
me = set_function.receiver
|
||||
|
@ -2,11 +2,11 @@ module Boot
|
||||
class String
|
||||
module ClassMethods
|
||||
def get context , index = Virtual::Integer
|
||||
get_function = Virtual::Method.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
|
||||
get_function = Virtual::MethodDefinition.new(:get , [ Virtual::Integer] , Virtual::Integer , Virtual::Integer )
|
||||
return get_function
|
||||
end
|
||||
def set context , index = Virtual::Integer , char = Virtual::Integer
|
||||
set_function = Virtual::Method.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
|
||||
set_function = Virtual::MethodDefinition.new(:set , [Virtual::Integer, Virtual::Integer] , Virtual::Integer ,Virtual::Integer )
|
||||
return set_function
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user