Skip to content

Commit 61bea2f

Browse files
committed
make everything inherit from Object
1 parent f4dd48f commit 61bea2f

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

pixie/vm/object.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,18 @@ def get_type_by_name(nm):
6767
return _type_registry.get_by_name(nm)
6868

6969
class Type(Object):
70-
def __init__(self, name, parent = None):
70+
def __init__(self, name, parent=None, object_inited=True):
7171
assert isinstance(name, unicode), u"Type names must be unicode"
7272
_type_registry.register_type(name, self)
7373
self._name = name
74-
self._parent = parent
75-
if parent is not None:
74+
75+
if object_inited:
76+
if parent is None:
77+
parent = Object._type
78+
7679
parent.add_subclass(self)
7780

81+
self._parent = parent
7882
self._subclasses = []
7983

8084
def name(self):
@@ -89,7 +93,8 @@ def add_subclass(self, tp):
8993
def subclasses(self):
9094
return self._subclasses
9195

92-
Type._type = Type(u"Type")
96+
Object._type = Type(u"pixie.stdlib.Object", None, False)
97+
Type._type = Type(u"pixie.stdlib.Type")
9398

9499
@jit.elidable_promote()
95100
def istypeinstance(obj, t):

tests/pixie/tests/test-object.pxi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@
44
(t/deftest test-hash
55
(t/assert= (hash (var foo)) (hash (var foo)))
66
(t/assert (not= (hash (var foo)) (hash (var bar)))))
7+
8+
9+
(deftype FooType [])
10+
11+
(t/deftest test-everything-is-an-object
12+
(t/assert (instance? Object 42))
13+
(t/assert (instance? Object []))
14+
(t/assert (instance? Object "Foo"))
15+
(t/assert (instance? Object FooType)))

0 commit comments

Comments
 (0)