Пример #1
0
def cons_ensureConsDataStructure( cons):
 ensure( cons, [Cons])
 consid= id( cons)
 if False:
  pass
 elif not ht_cons_consid2consAndTypeSet.has_key( consid):
  ht_cons_consid2consAndTypeSet[ consid]= ( cons, set())
Пример #2
0
 def test(self):
     assert 0 == len(self.lParams)
     try:
         ensure(self.consWrapped, [Cons])
     except:
         return False
     walker = self.consWrapped
     while isinstance(walker.cdr(), Cons):  # baustelle: loopt ggf. unendlich
         walker = walker.cdr()
     return id(nil) == id(walker.cdr())
Пример #3
0
 def symAdd( self, symbol, lParents):
 
  ensure( symbol, [Symbol])
 
  if None==lParents:
   lParents= []
  
  ensure( lParents, [list])
 
  if self.ht.has_key( symbol):
   raise Exception( 'already registered %s' % symbol)
  
  self.ht[ symbol]= lParents
Пример #4
0
 def macroBufFeed( self, l, outer= True): 

  ensure( l, [Cons])

  if outer:
   if isinstance( l.cdr(), Cons):
    if isinstance( l.cdr().car(), Cons):
     ensureConsType( l.cdr().car(), ar_codeList) # baustelle: ggf. uebertestet
     ensureConsType( l.cdr().car().cdr().car(), ar_codeListConfig) # baustelle: ggf. uebertestet
     pass

  uNames.next( usRename( ConsSimple, 'cs'))
  uNames.next( usRename( Symbol, 's'))

  c= l
  r= nil # reverse

  while not id( nil) == id( c):
   r= ConsSimple( c.car(), r)
   c= c.cdr()

  self.macroBufAdd( False, Symbol( ')'))

  while not id( nil) == id( r):
   value= r.car()
   if isinstance( value, Cons) and typeSymbolChk( value.car(), ar_codeList): # f69eef8ad76e459da16194dcdd0c73c6
    codeListEnsure( value) # b73fcfe5b4de4df6946ee586d8f79713
    self.macroBufFeed( codeListGetParameterValues( value), outer= False) # 2849da4969b146bc88315f20fd205e06 baustelle0: hier wird das Environment verworfen
   else: 
    self.macroBufAdd( False, value)
   r= r.cdr()

  self.macroBufAdd( outer, Symbol( '(')) # 64005373aae94f3a9314d303d5f4016e

  uNames.undo()
  uNames.undo()
Пример #5
0
        def calculate(self, consWrapped=None):  # parameter von ConsRepr fuer rekursion notwendig

            if None == consWrapped:
                consWrapped = self.consRepr.consWrapped

            if isinstance(consWrapped, CpctReprParamListWrapper):
                lCpctReprIdxStart = 1 + consWrapped.lCpctReprIdx  # baustelle0 : ungetestet
                consWrapped = consWrapped.wrapped
            else:
                lCpctReprIdxStart = 0

            ht_selfid2Name = self.ht_selfid2Name
            lCpctRepr = self.lCpctRepr

            repr_wrapped_class_name = consWrapped.__class__.__name__

            registered_to_ht_selfid2Name = False

            id_self = id(consWrapped)

            if None == ht_selfid2Name:
                ht_selfid2Name = dict()  # baustelle0: ggf. ineffizient
            elif ht_selfid2Name.has_key(id_self):
                # return '<cycle>'
                return self.ht_selfid2NameRepr(ht_selfid2Name[id_self])
            else:
                ht_selfid2Name[id_self] = "<cycle>"
                registered_to_ht_selfid2Name = True

            foundIn_lCpctRepr = []
            if not None == lCpctRepr:
                i = idx = None
                # for i in lCpctRepr:
                for idx in range(lCpctReprIdxStart, len(lCpctRepr)):
                    i = lCpctRepr[idx]
                    i = i(consWrapped)
                    ensure(i, [CpctRepr])
                    if i.test():
                        foundIn_lCpctRepr.append(i)
                        break  # f5fbafd44f9a4a3c9f65860301b2c1c5
                lCpctReprIdx = idx
                del idx, i

            # if 2==len( foundIn_lCpctRepr): # f5fbafd44f9a4a3c9f65860301b2c1c5
            #  raise Exception( '2==len( foundIn_lCpctRepr)')

            if 1 == len(foundIn_lCpctRepr):
                paramList = foundIn_lCpctRepr[0].paramList()
                for n in range(0, len(paramList)):

                    if isinstance(paramList[n], CpctReprParamListWrapper):
                        paramList[n].lCpctReprIdx = lCpctReprIdx

                    # 991ade2498184498ab8cdce0867ceae5
                    # paramList[ n]= ConsRepr( paramList[ n]).repr_wrapped( ht_selfid2Name, lCpctRepr)
                    paramList[n] = self.calculate(paramList[n])
                    # /991ade2498184498ab8cdce0867ceae5

                ret = foundIn_lCpctRepr[0].repr_wrapped(ht_selfid2Name, lCpctRepr)
            elif not isinstance(consWrapped, Cons):
                # ret= repr( consWrapped)
                ret = self.whenUnknown(consWrapped)
            else:

                # 991ade2498184498ab8cdce0867ceae5
                # repr_wrapped_ar= ConsRepr( consWrapped.car()).repr_wrapped( ht_selfid2Name, lCpctRepr)
                # repr_wrapped_dr= ConsRepr( consWrapped.cdr()).repr_wrapped( ht_selfid2Name, lCpctRepr)
                repr_wrapped_ar = self.calculate(consWrapped.car())
                repr_wrapped_dr = self.calculate(consWrapped.cdr())
                # /991ade2498184498ab8cdce0867ceae5

                # ret= '%s( %s, %s)' % ( repr_wrapped_class_name, repr_wrapped_ar, repr_wrapped_dr)
                ret = self.returnFunction(repr_wrapped_class_name, repr_wrapped_ar, repr_wrapped_dr)

            if registered_to_ht_selfid2Name:
                del ht_selfid2Name[id_self]

            return ret
Пример #6
0
    def mirrors(self, consEqState2):

        ensure(consEqState2, [ConsEqState])

        return self.eq_lhs == consEqState2.eq_rhs and self.eq_rhs == consEqState2.eq_lhs
Пример #7
0
    def __init__(self, interpreter):

        ensure(interpreter, [Interpreter.Interpreter])

        self.htInterpreterSymbolTableNames = dict()
        ht = self.htInterpreterSymbolTableNames

        ht["macro"] = NativeQuotationMacro()
        ht["macro2"] = NativeQuotationMacro2()
        ht["function"] = NativeQuotationFunction()
        ht["quotation"] = NativeQuotationQuotation()

        ht["if"] = NativeMacroIf()
        ht["ifpre"] = NativeQuotationIfPre()
        ht["fif"] = NativeFunctionFif()

        ht["q1"] = NativeQuotationQ1()
        ht["q2"] = NativeQuotationQ2()  # parameter1 wird ignoriert, fuer uq2pre
        ht["ql"] = NativeQuotationQL()
        ht["qn1"] = BuiltinMacroQN1()
        ht["qconses"] = NativeQuotationQConses()
        ht["qswap2"] = NativeQuotationQSwap2()

        ht["pyprint"] = BuiltinFunctionPyPrint()
        ht["pyprintconses"] = BuiltinFunctionPyPrintConses()
        ht["pyprintconsesRest"] = BuiltinFunctionPyPrintConsesRest()
        ht["pyprintStack"] = BuiltinFunctionPyPrintStack()
        ht["pyprintStack2"] = BuiltinFunctionPyPrintStack2()
        ht["pyprintStackShort"] = BuiltinFunctionPyPrintStackShort()

        ht["prog"] = BuiltinFunctionProg()
        ht["prog2"] = BuiltinFunctionProg2()
        ht["progn"] = BuiltinFunctionProgN()
        ht["progn-1"] = BuiltinFunctionProgNMinus1()

        ht["conses"] = BuiltinFunctionConses()
        ht["consesRest"] = BuiltinFunctionConsesRest()

        ht["unconses"] = NativeFunctionUnConses()

        ht["thru1"] = BuiltinFunctionThru1()
        ht["nameOfSymbol"] = BuiltinFunctionNameOfSymbol()

        ht["cons"] = BuiltinFunctionCons()
        ht["car"] = BuiltinFunctionCar()
        ht["cdr"] = BuiltinFunctionCdr()

        ht["eval1"] = NativeFunctionEval1()
        ht["eval"] = NativeFunctionEval()

        ht["set2"] = NativeFunctionSet2()

        ht["env-push-new0"] = NativeFunctionEnvPushNew0()
        ht["env-quotationMode-push-new0"] = NativeFunctionEnvQuotationModePushNew0()
        ht["env-pop0"] = NativeFunctionEnvPop0()
        ht["env-exists1"] = NativeFunctionEnvExists1()

        ht["uqset1"] = NativeFunctionUQSet1()

        ht["stack-get0"] = NativeFunctionStackGet()
        ht["stack-clone1"] = NativeFunctionStackClone()
        ht["stack-apply2"] = NativeFunctionStackApply()

        del ht

        self.htInterpreterSymbolTable = dict()

        for k in self.htInterpreterSymbolTableNames:
            v = self.htInterpreterSymbolTableNames[k]
            self.htInterpreterSymbolTable[Symbol(k)] = v
        del k, v

        self.htInterpreterSymbolTableNames["nil"] = nil
        self.htInterpreterSymbolTableNames["noo"] = noo
        self.htInterpreterSymbolTableNames["true"] = true

        self.htInterpreterSymbolTable[nil] = nil
        self.htInterpreterSymbolTable[noo] = noo
        self.htInterpreterSymbolTable[true] = true

        for k in self.htInterpreterSymbolTable:
            v = self.htInterpreterSymbolTable[k]
            if isinstance(v, InterpreterNative):
                v.setInterpreter(interpreter)
        del k, v

        def tmpSetRepr(v, repr_name):
            v.__repr__ = lambda: repr(repr_name)

        for k in self.htInterpreterSymbolTableNames:

            v = self.htInterpreterSymbolTable[k]
            repr_name = "sys:" + k

            if isinstance(v, ExecuteObject):
                tmpSetRepr(v, repr_name)
Пример #8
0
def cons_ensureConsTypeDataStructure( consType):
 ensure( consType, [ConsType])
 if False:
  pass
 elif not ht_cons_consType2ConsidSetAndFunctionSet.has_key( consType):
  ht_cons_consType2ConsidSetAndFunctionSet[ consType]= ( set(), set())
Пример #9
0
 def symDel( self, symbol):
 
  ensure( symbol, [Symbol])
 
  del self.ht[ symbol]