Commit 2e9baa9f authored by Juergen Nickelsen's avatar Juergen Nickelsen

some more (and admittedly rather mechanic) object overhaul.

parent 20f266d1
# This file is part of the Python Lambda Experiment (pyle),
# Copyright (C) 2017 Juergen Nickelsen <ni@w21.org>.
# Copyright (C) 2017, 2018 Juergen Nickelsen <ni@w21.org>.
# See LICENSE for the conditions under which this code is licensed to you.
import re
......@@ -59,8 +59,7 @@ def p2l(value):
class Object:
"""This is the base class for all objects, intended as purely abstract.
"""This is the base class for all Pyle objects, purely abstract.
There are a few default functions.
......@@ -118,42 +117,86 @@ class Object:
"""Return object's attributes as a dict."""
return { "type": intern(self.typename()), "id": id(self) }
def car(self): raise PyleArgTypeError(self, 'car', 'list')
def car(self):
"""Return the car of a cons.
If this is not a cons => error.
"""
raise PyleArgTypeError(self, 'car', 'list')
def cdr(self): raise PyleArgTypeError(self, 'cdr', 'list')
def cdr(self):
"""Return the cdr of a cons.
If this is not a cons => error.
"""
raise PyleArgTypeError(self, 'cdr', 'list')
def rplaca(self, ob): raise PyleArgTypeError(self, 'rplaca', 'pair')
def rplaca(self, ob):
"""Replace the car of a cons.
If this is not a cons => error.
"""
raise PyleArgTypeError(self, 'rplaca', 'pair')
def rplacd(self, ob): raise PyleArgTypeError(self, 'rplacd', 'pair')
def rplacd(self, ob):
"""Replace the cdr of a cons.
If this is not a cons => error.
"""
raise PyleArgTypeError(self, 'rplacd', 'pair')
def isAtom(self): return False
def isAtom(self):
"""Return true iff the object is an Atom. False by default."""
return False
def isEnvironment(self): return False
def isEnvironment(self):
"""Return true iff this is an environment. False by default."""
return False
def isFunction(self): return False
def isFunction(self):
"""Return true iff this is a function. False by default."""
return False
def isList(self): return False
def isList(self):
"""Return true iff this is a list. False by default."""
return False
def isMacro(self): return False
def isMacro(self):
"""Return true iff this is a macro. False by default."""
return False
def isNumber(self): return False
def isNumber(self):
"""Return true iff this is a number. False by default."""
return False
def isPair(self): return False
def isPair(self):
"""Return true iff this is a pair. False by default."""
return False
def isString(self): return False
def isString(self):
"""Return true iff this is a string. False by default."""
return False
def isSymbol(self): return False
def isSymbol(self):
"""Return true iff this is a symbol. False by default."""
return False
def isError(self): return False
def isError(self):
"""Return true iff this is an error. False by default."""
return False
class Error(Object):
"""Error class. These are derived from the Pyle exceptions."""
def __init__(self, e):
self.e = e # the Python exception
errName = re.sub("^Pyle", "", e.__class__.__name__)
self.e.kind = intern(utils.dashify(errName))
def isError(self):
return True
def __str__(self):
elems = ["#<Error"]
firstSem = ""
......@@ -162,8 +205,10 @@ class Error(Object):
firstSem = ";"
elems.append(">")
return "".join(elems)
def __repr__(self):
return str(self)
def describe(self):
attrs = super().describe()
attrs.update(self.e.__dict__)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment