Loading builtin.py +1 −1 Original line number Diff line number Diff line Loading @@ -151,7 +151,7 @@ def Pyle_describe(arglist): """@desc args: OBJ; result: description list Return a list of OBJ's attributes. """ return arglist.car().describe() return p2l(arglist.car().describe()) def Pyle_debug(arglist): """@desc args: FLAG...; return: flags Loading object.py +63 −8 Original line number Diff line number Diff line Loading @@ -10,7 +10,8 @@ from exceptions import * import dep import utils # symbols that we need internally # Symbols that we need internally. These need to be created ASAP, i.e. as soon # as we have the root environment. Nil = None NilName = "nil" T = None Loading @@ -27,6 +28,12 @@ CurrentEnv = None def p2l(value): """Return an Object for value. If value is already an Object, return it; otherwise, create the appropriate Object and return it. """ if isinstance(value, Object): return value elif type(value) is bool: Loading @@ -50,49 +57,96 @@ def p2l(value): else: return String(str(value)) class Object: """This is the base class for all objects, intended as purely virtual. """This is the base class for all objects, intended as purely abstract. There are a few default functions. """ def __repr__(self): """Return a default string representation.""" return "#<{n}:{i}>".format(n=self.__class__.__name__, i=id(self)) def __str__(self): """Return the nicely formatted string for object.""" return self.__repr__() def __iter__(self): """Return an iterator for the object. Will raise an error for most.""" return ListIterator(self) def __bool__(self): """Return the boolean value of the object.""" return self is not Nil def __format__(self, format_spec): """Return a formatted representation of the object.""" return str(self).__format__(format_spec) def eq(self, obj): """Return true iff object is eq to obj.""" return self is obj def type(self): """Return the class name of object.""" return self.__class__.__name__ def isNil(self): """Return true iff the object is Nil.""" return self is Nil def isProper(self): """Return true iff the object is a proper list.""" return False def dump(self): """Return a text dump of the object.""" return self.__repr__() def cxr(self): """Return car and cdr of the object. Will be an error for most.""" raise PyleIterateAtomError(self) def typename(self): """Return the lowercase class name of object.""" return self.__class__.__name__.lower() def describe(self): return p2l({ "type": self.typename(), "id": id(self) }) """Return object's attributes as a dict.""" return { "type": intern(self.typename()), "id": id(self) } def car(self): raise PyleArgTypeError(self, 'car', 'list') def cdr(self): raise PyleArgTypeError(self, 'cdr', 'list') def rplaca(self, ob): raise PyleArgTypeError(self, 'rplaca', 'pair') def rplacd(self, ob): raise PyleArgTypeError(self, 'rplacd', 'pair') def isAtom(self): return False def isEnvironment(self): return False def isFunction(self): return False def isList(self): return False def isMacro(self): return False def isNumber(self): return False def isPair(self): return False def isString(self): return False def isSymbol(self): return False def isError(self): return False class Error(Object): def __init__(self, e): self.e = e # the Python exception Loading @@ -111,8 +165,9 @@ class Error(Object): def __repr__(self): return str(self) def describe(self): lc = ListCollector() return p2l(self.e.__dict__) a = super().describe() a.update(self.e.__dict__) return a _gensym_counter = 8385 Loading Loading @@ -212,9 +267,9 @@ class Symbol(Object): else: raise PyleArgTypeError(self, 'cxr', 'list') def describe(self): return p2l({ "type": intern(self.typename()), "props": p2l(self._props), }) a = super(Symbol, self).describe() a["props"] = self._props return a def init_symbol(): global Nil, T, ImmutableSymbol, FunctionSymbol, NamePropSymbol, IdPropSymbol Loading Loading
builtin.py +1 −1 Original line number Diff line number Diff line Loading @@ -151,7 +151,7 @@ def Pyle_describe(arglist): """@desc args: OBJ; result: description list Return a list of OBJ's attributes. """ return arglist.car().describe() return p2l(arglist.car().describe()) def Pyle_debug(arglist): """@desc args: FLAG...; return: flags Loading
object.py +63 −8 Original line number Diff line number Diff line Loading @@ -10,7 +10,8 @@ from exceptions import * import dep import utils # symbols that we need internally # Symbols that we need internally. These need to be created ASAP, i.e. as soon # as we have the root environment. Nil = None NilName = "nil" T = None Loading @@ -27,6 +28,12 @@ CurrentEnv = None def p2l(value): """Return an Object for value. If value is already an Object, return it; otherwise, create the appropriate Object and return it. """ if isinstance(value, Object): return value elif type(value) is bool: Loading @@ -50,49 +57,96 @@ def p2l(value): else: return String(str(value)) class Object: """This is the base class for all objects, intended as purely virtual. """This is the base class for all objects, intended as purely abstract. There are a few default functions. """ def __repr__(self): """Return a default string representation.""" return "#<{n}:{i}>".format(n=self.__class__.__name__, i=id(self)) def __str__(self): """Return the nicely formatted string for object.""" return self.__repr__() def __iter__(self): """Return an iterator for the object. Will raise an error for most.""" return ListIterator(self) def __bool__(self): """Return the boolean value of the object.""" return self is not Nil def __format__(self, format_spec): """Return a formatted representation of the object.""" return str(self).__format__(format_spec) def eq(self, obj): """Return true iff object is eq to obj.""" return self is obj def type(self): """Return the class name of object.""" return self.__class__.__name__ def isNil(self): """Return true iff the object is Nil.""" return self is Nil def isProper(self): """Return true iff the object is a proper list.""" return False def dump(self): """Return a text dump of the object.""" return self.__repr__() def cxr(self): """Return car and cdr of the object. Will be an error for most.""" raise PyleIterateAtomError(self) def typename(self): """Return the lowercase class name of object.""" return self.__class__.__name__.lower() def describe(self): return p2l({ "type": self.typename(), "id": id(self) }) """Return object's attributes as a dict.""" return { "type": intern(self.typename()), "id": id(self) } def car(self): raise PyleArgTypeError(self, 'car', 'list') def cdr(self): raise PyleArgTypeError(self, 'cdr', 'list') def rplaca(self, ob): raise PyleArgTypeError(self, 'rplaca', 'pair') def rplacd(self, ob): raise PyleArgTypeError(self, 'rplacd', 'pair') def isAtom(self): return False def isEnvironment(self): return False def isFunction(self): return False def isList(self): return False def isMacro(self): return False def isNumber(self): return False def isPair(self): return False def isString(self): return False def isSymbol(self): return False def isError(self): return False class Error(Object): def __init__(self, e): self.e = e # the Python exception Loading @@ -111,8 +165,9 @@ class Error(Object): def __repr__(self): return str(self) def describe(self): lc = ListCollector() return p2l(self.e.__dict__) a = super().describe() a.update(self.e.__dict__) return a _gensym_counter = 8385 Loading Loading @@ -212,9 +267,9 @@ class Symbol(Object): else: raise PyleArgTypeError(self, 'cxr', 'list') def describe(self): return p2l({ "type": intern(self.typename()), "props": p2l(self._props), }) a = super(Symbol, self).describe() a["props"] = self._props return a def init_symbol(): global Nil, T, ImmutableSymbol, FunctionSymbol, NamePropSymbol, IdPropSymbol Loading