move to syms for names
This commit is contained in:
@@ -63,6 +63,7 @@ module Arm
|
||||
# return the block of the given name
|
||||
# or raise an exception, as this is meant to be called when the block is available
|
||||
def get_block name
|
||||
name = name.to_sym
|
||||
block = @blocks.find {|b| b.name == name}
|
||||
raise "No block found for #{name} (in #{blocks.collect{|b|b.name}.join(':')})" unless block
|
||||
block
|
||||
|
@@ -24,7 +24,7 @@ module Ast
|
||||
class NameExpression < Expression
|
||||
attr_reader :name
|
||||
def initialize name
|
||||
@name = name
|
||||
@name = name.to_sym
|
||||
end
|
||||
# compiling a variable resolves it.
|
||||
# if it wasn't defined, nli is returned
|
||||
@@ -32,7 +32,7 @@ module Ast
|
||||
context.locals[name]
|
||||
end
|
||||
def inspect
|
||||
self.class.name + '.new("' + name + '")'
|
||||
"#{self.class.name}.new(#{name})"
|
||||
end
|
||||
def to_s
|
||||
name
|
||||
|
@@ -5,7 +5,9 @@ module Ast
|
||||
attr_reader :name, :args , :receiver
|
||||
|
||||
def initialize name, args , receiver = Ast::NameExpression.new(:self)
|
||||
@name , @args , @receiver = name.to_sym , args , receiver
|
||||
@name = name.to_sym
|
||||
@args = args
|
||||
@receiver = receiver
|
||||
end
|
||||
|
||||
def compile context , into
|
||||
@@ -14,6 +16,7 @@ module Ast
|
||||
r = context.current_class.name
|
||||
if !receiver.nil? and receiver.name != :self
|
||||
r = receiver.name
|
||||
raise "uups #{receiver.class}.#{receiver.name.class}" unless r.is_a? Symbol
|
||||
end
|
||||
clazz = context.object_space.get_or_create_class r
|
||||
|
||||
|
@@ -1,6 +1,8 @@
|
||||
module Ast
|
||||
class ModuleExpression < Expression
|
||||
|
||||
attr_reader :name ,:expressions
|
||||
|
||||
def initialize name , expressions
|
||||
@name = name.to_sym
|
||||
@expressions = expressions
|
||||
|
@@ -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
33
lib/vm/meta_class.rb
Normal 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
|
Reference in New Issue
Block a user