Permalink
Browse files

Support for #is_a?; also needed to add default Object#==, since compa…

…rison of object references is used in the #is_a? implementation
  • Loading branch information...
vidarh committed Sep 23, 2014
1 parent b3edea5 commit e19a85d2b183ae4bea677a7f21e30cb7f2f0070a
Showing with 30 additions and 5 deletions.
  1. +18 −0 lib/core/class.rb
  2. +11 −1 lib/core/object.rb
  3. +1 −4 lib/core/string.rb
View
@@ -49,6 +49,24 @@ def to_s
@name
end
# FIXME: Should inherit this from Object, but current
# bootstrapping won't do that
def == other
%s(if (eq self other) true false)
end
def != other
!(self == other)
end
# FIXME: The "if" is a workaround due to bootstrap
# issues which get any classes that get initialized before
# Object set up with the superclass pointer set to 0 at
# the moment. A proper fix is needed
def superclass
%s(if (index self 3) (index self 3) Object)
end
# FIXME
# &block will be a "bare" %s(lambda) (that needs to be implemented),
# define_method needs to attach that to the vtable (for now) and/or
View
@@ -17,6 +17,10 @@ def inspect
"#<#{self.class.name}:#{buf}>"
end
def == other
%s(if (eq self other) true false)
end
def nil?
false
end
@@ -25,8 +29,14 @@ def respond_to?
puts "Object#respond_to not implemented"
end
# FIXME: This will not handle eigenclasses correctly.
def is_a?(c)
false
k = self.class
while k != c && k != Object
k = k.superclass
end
return (k == c)
end
def __send__ sym, *args
View
@@ -32,14 +32,11 @@ def initialize *str
)
end
def !
false
end
def is_a? c
true
end
def nil?
false
end

0 comments on commit e19a85d

Please sign in to comment.