Exemplo n.º 1
0
def applyPrimitiveProcedure(proc, args, env, cont):
    try:
        return applyInUnderlyingPython(expressions.primitiveImplementation(proc),
                                       [cont, env, pair.toPythonList(args)])
    except Exception, e:
        if isinstance(e, exceptions.SystemExit): raise e
        raise SchemeError, e
Exemplo n.º 2
0
 def type(self, val):
     "Get the Python type of a Scheme value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return types.FunctionType
         return schemepy.types.Lambda
     if symbol.isSymbol(val):
         if val == symbol.true or val == symbol.false:
             return bool
         return schemepy.types.Symbol
     if pair.isNull(val):
         return list
     if isAList(val):
         return dict
     if pair.isList(val):
         return list
     if pair.isPair(val):
         return schemepy.types.Cons
     t = type(val)
     if t not in (int, complex, float, long, str, unicode):
         return object
     return t
Exemplo n.º 3
0
 def type(self, val):
     "Get the Python type of a Scheme value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return types.FunctionType
         return schemepy.types.Lambda
     if symbol.isSymbol(val):
         if val == symbol.true or val == symbol.false:
             return bool
         return schemepy.types.Symbol
     if pair.isNull(val):
         return list
     if isAList(val):
         return dict
     if pair.isList(val):
         return list
     if pair.isPair(val):
         return schemepy.types.Cons
     t = type(val)
     if t not in (int, complex, float, long, str, unicode):
         return object
     return t
Exemplo n.º 4
0
def applyPrimitiveProcedure(proc, args, env, cont):
    try:
        return applyInUnderlyingPython(
            expressions.primitiveImplementation(proc),
            [cont, env, pair.toPythonList(args)])
    except Exception, e:
        if isinstance(e, exceptions.SystemExit): raise e
        raise SchemeError, e
Exemplo n.º 5
0
 def fromscheme(self, val, shallow=False):
     "Convert a Scheme value to a Python value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda(val, self, shallow)
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return orig
         return schemepy.types.Lambda(val, self, shallow)
     if symbol.isSymbol(val):
         if val == symbol.true:
             return True
         if val == symbol.false:
             return False
         return schemepy.types.Symbol(str(val))
     if pair.isNull(val):
         return []
     if isAList(val):
         dic = {}
         while not pair.isNull(val):
             el = pair.car(val)
             key = self.fromscheme(pair.car(el))
             value = pair.cdr(el)
             if not shallow:
                 value = self.fromscheme(value)
             dic[key] = value
             val = pair.cdr(val)
         return dic
     if pair.isList(val):
         lst = []
         while not pair.isNull(val):
             el = pair.car(val)
             if not shallow:
                 el = self.fromscheme(el)
             lst.append(el)
             val = pair.cdr(val)
         return lst
     if pair.isPair(val):
         car = pair.car(val)
         cdr = pair.cdr(val)
         if not shallow:
             car = self.fromscheme(car)
             cdr = self.fromscheme(cdr)
         return schemepy.types.Cons(car, cdr)
     return val
Exemplo n.º 6
0
 def fromscheme(self, val, shallow=False):
     "Convert a Scheme value to a Python value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda(val, self, shallow)
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return orig
         return schemepy.types.Lambda(val, self, shallow)
     if symbol.isSymbol(val):
         if val == symbol.true:
             return True
         if val == symbol.false:
             return False
         return schemepy.types.Symbol(str(val))
     if pair.isNull(val):
         return []
     if isAList(val):
         dic = {}
         while not pair.isNull(val):
             el = pair.car(val)
             key = self.fromscheme(pair.car(el))
             value = pair.cdr(el)
             if not shallow:
                 value = self.fromscheme(value)
             dic[key] = value
             val = pair.cdr(val)
         return dic
     if pair.isList(val):
         lst = []
         while not pair.isNull(val):
             el = pair.car(val)
             if not shallow:
                 el = self.fromscheme(el)
             lst.append(el)
             val = pair.cdr(val)
         return lst
     if pair.isPair(val):
         car = pair.car(val)
         cdr = pair.cdr(val)
         if not shallow:
             car = self.fromscheme(car)
             cdr = self.fromscheme(cdr)
         return schemepy.types.Cons(car, cdr)
     return val