Skip to content
Permalink
Browse files

Merge pull request #706 from krekoten/move_methods_to_kernel

Move methods from Object to Kernel
  • Loading branch information
alex committed May 16, 2013
2 parents cc542d1 + a80e8e6 commit 5833a79440cfd506fbdf486c78872d613a3db2b3
Showing with 78 additions and 78 deletions.
  1. +0 −1 spec/tags/core/basicobject/basicobject_tags.txt
  2. +76 −1 topaz/modules/kernel.py
  3. +2 −76 topaz/objects/objectobject.py
@@ -1,4 +1,3 @@
fails:BasicObject raises NameError when referencing built-in constants
fails:BasicObject does not define built-in constants (according to defined?)
fails:BasicObject includes itself in its list of constants
fails:BasicObject subclass contains Kernel methods when including Kernel
@@ -3,12 +3,13 @@
import os
import time

from rpython.rlib.objectmodel import compute_identity_hash
from rpython.rlib.rfloat import round_double
from rpython.rlib.streamio import open_file_as_stream

from topaz.coerce import Coerce
from topaz.error import RubyError, error_for_oserror
from topaz.module import ModuleDef
from topaz.module import ModuleDef, check_frozen
from topaz.modules.process import Process
from topaz.objects.bindingobject import W_BindingObject
from topaz.objects.exceptionobject import W_ExceptionObject
@@ -391,3 +392,77 @@ def method_srand(self, space, w_seed=None):
random_class = space.getclassfor(W_RandomObject)
default = space.find_const(random_class, "DEFAULT")
return default.srand(space, w_seed)

@moduledef.method("object_id")
def method_object_id(self, space):
return space.send(self, "__id__")

@moduledef.method("singleton_class")
def method_singleton_class(self, space):
return space.getsingletonclass(self)

@moduledef.method("extend")
def method_extend(self, space, w_mod):
if not space.is_kind_of(w_mod, space.w_module) or space.is_kind_of(w_mod, space.w_class):
if space.is_kind_of(w_mod, space.w_class):
name = "Class"
else:
name = space.obj_to_s(space.getclass(w_mod))
raise space.error(
space.w_TypeError,
"wrong argument type %s (expected Module)" % name
)
space.send(w_mod, "extend_object", [self])
space.send(w_mod, "extended", [self])

@moduledef.method("inspect")
def method_inspect(self, space):
return space.send(self, "to_s")

@moduledef.method("to_s")
def method_to_s(self, space):
return space.newstr_fromstr(space.any_to_s(self))

@moduledef.method("===")
def method_eqeqeq(self, space, w_other):
if self is w_other:
return space.w_true
return space.send(self, "==", [w_other])

@moduledef.method("send")
def method_send(self, space, args_w, block):
return space.send(self, "__send__", args_w, block)

@moduledef.method("nil?")
def method_nilp(self, space):
return space.w_false

@moduledef.method("hash")
def method_hash(self, space):
return space.newint(compute_identity_hash(self))

@moduledef.method("instance_variable_get", name="str")
def method_instance_variable_get(self, space, name):
return space.find_instance_var(self, name)

@moduledef.method("instance_variable_set", name="str")
@check_frozen()
def method_instance_variable_set(self, space, name, w_value):
space.set_instance_var(self, name, w_value)
return w_value

@moduledef.method("method")
def method_method(self, space, w_sym):
return space.send(
space.send(space.getclass(self), "instance_method", [w_sym]),
"bind",
[self]
)

@moduledef.method("tap")
def method_tap(self, space, block):
if block is not None:
space.invoke_block(block, [self])
else:
raise space.error(space.w_LocalJumpError, "no block given")
return self
@@ -1,10 +1,10 @@
import copy

from rpython.rlib import jit
from rpython.rlib.objectmodel import compute_unique_id, compute_identity_hash
from rpython.rlib.objectmodel import compute_unique_id

from topaz.mapdict import MapTransitionCache
from topaz.module import ClassDef, check_frozen
from topaz.module import ClassDef
from topaz.scope import StaticScope


@@ -133,80 +133,6 @@ class W_RootObject(W_BaseObject):
def setup_class(cls, space, w_cls):
space.w_top_self = W_Object(space, w_cls)

@classdef.method("object_id")
def method_object_id(self, space):
return space.send(self, "__id__")

@classdef.method("singleton_class")
def method_singleton_class(self, space):
return space.getsingletonclass(self)

@classdef.method("extend")
def method_extend(self, space, w_mod):
if not space.is_kind_of(w_mod, space.w_module) or space.is_kind_of(w_mod, space.w_class):
if space.is_kind_of(w_mod, space.w_class):
name = "Class"
else:
name = space.obj_to_s(space.getclass(w_mod))
raise space.error(
space.w_TypeError,
"wrong argument type %s (expected Module)" % name
)
space.send(w_mod, "extend_object", [self])
space.send(w_mod, "extended", [self])

@classdef.method("inspect")
def method_inspect(self, space):
return space.send(self, "to_s")

@classdef.method("to_s")
def method_to_s(self, space):
return space.newstr_fromstr(space.any_to_s(self))

@classdef.method("===")
def method_eqeqeq(self, space, w_other):
if self is w_other:
return space.w_true
return space.send(self, "==", [w_other])

@classdef.method("send")
def method_send(self, space, args_w, block):
return space.send(self, "__send__", args_w, block)

@classdef.method("nil?")
def method_nilp(self, space):
return space.w_false

@classdef.method("hash")
def method_hash(self, space):
return space.newint(compute_identity_hash(self))

@classdef.method("instance_variable_get", name="str")
def method_instance_variable_get(self, space, name):
return space.find_instance_var(self, name)

@classdef.method("instance_variable_set", name="str")
@check_frozen()
def method_instance_variable_set(self, space, name, w_value):
space.set_instance_var(self, name, w_value)
return w_value

@classdef.method("method")
def method_method(self, space, w_sym):
return space.send(
space.send(space.getclass(self), "instance_method", [w_sym]),
"bind",
[self]
)

@classdef.method("tap")
def method_tap(self, space, block):
if block is not None:
space.invoke_block(block, [self])
else:
raise space.error(space.w_LocalJumpError, "no block given")
return self


class W_Object(W_RootObject):
_attrs_ = ["map", "storage"]

0 comments on commit 5833a79

Please sign in to comment.
You can’t perform that action at this time.