move to syms for names

This commit is contained in:
Torsten Ruger
2014-06-03 20:47:06 +03:00
parent b7c2089046
commit ca19f5cb16
12 changed files with 65 additions and 22 deletions

View File

@ -1,15 +1,19 @@
require_relative "meta_class"
module Vm
# class is mainly a list of functions with a name (for now)
# layout of object is seperated into Layout
class BootClass < Code
def initialize name , context , superclass = :Object
def initialize name , context , super_class = :Object
super()
@context = context
# class functions
@functions = []
@name = name.to_sym
@superclass = superclass
@super_class = super_class
@meta_class = MetaClass.new(self)
end
attr_reader :name , :functions
attr_reader :name , :functions , :meta_class
def add_function function
raise "not a function #{function}" unless function.is_a? Function
@ -22,11 +26,11 @@ module Vm
@functions.detect{ |f| f.name == name }
end
# preferred way of creating new functions (also forward declarations, will flag unresolved later)
# way of creating new functions that have not been parsed.
def get_or_create_function name
fun = get_function name
unless fun or name == :Object
supr = @context.object_space.get_or_create_class(@superclass)
supr = @context.object_space.get_or_create_class(@super_class)
fun = supr.get_function name
puts "#{supr.functions.collect(&:name)} for #{name} GOT #{fun.class}" if name == :index_of
end

33
lib/vm/meta_class.rb Normal file
View File

@ -0,0 +1,33 @@
module Vm
# class that acts like a class, but is really the object
# described in the ruby language book as the eigenclass, what you get with
# class MyClass
# class << self <--- this is called the eigenclass, or metaclass, and really is just the class object
# .... but gives us the ability to use the syntax as if it were a class
# PS: can't say i fancy the << self syntax and am considerernig adding a keyword for it, like meta
# In effect it is a very similar construct to def self.function(...)
# So one could write def meta.function(...) and thus define on the meta-class
class MetaClass < Code
# no name, nor nothing. as this is just the object really
def initialize(object)
super()
@functions = []
@me_self = object
end
# in a non-booting version this should map to _add_singleton_method
def add_function function
raise "not a function #{function}" unless function.is_a? Function
raise "syserr " unless function.name.is_a? Symbol
@functions << function
end
def get_function name
name = name.to_sym
@functions.detect{ |f| f.name == name }
end
end
end