def AssemblyDisplay(asprog): for vname in asprog: o, odsa = asprog[vname] prp.printf(vname + ': ') if o == '"': prp.printf('" ') pio.WriteItemln(odsa) continue prp.printf(o + ' ') for od in odsa: prp.printf(od) prp.printf(' ') print()
def Gterm(t,formals): """ apply globals to all nonformals in t""" if LiteralP(t): return t if VarP(t): if pop.Occurs(Var(t),formals): return t return Operation1C(GLOBALWord,t) if OperationP(t): o,opds = OperationD(t) gopds = pop.ConsAll2(opds,Gterm,formals) return OperationC(o,gopds) if CallP(t): fun, actuals = CallD(t) gactuals = pop.ConsAll2(actuals,Gterm,formals) return CallC(fun,gactuals) print('Cannot globalize ') pio.WriteItemln(t) exit()
def Compile(f): """ compile the program in file f to atomic equations """ pio.parsing = True pg = prs.ParseFile(f) print('Program is ') #pio.WriteItemln(pg) prp.Termln(pg) print('Defs to import ', prs.defined) defs = pop.Empty for w in prs.defined: #read parse and add defs of defined operators like wvr wname = WordName(w) f = open("defs/" + wname + ".lu", "r") sourcedef = f.read() f.close() ig = pio.ItemGenStringC(sourcedef) df = prs.Definition(ig) #print('Adding df') #prp.Termln(df);exit() defs = pop.AddElement(defs, df) subj, wk, body = exp.WhereD(pg) body = pop.Append(body, defs) #add imported definitions pg = exp.WhereC(subj, wk, body) print('Expanded program') prp.Termln(pg) #print("check locals") pre.CheckLocals(pg) print("check dups") pre.CheckDups(pg) print("check embeddings") pre.ProgramEmbedded(pg) print('renamed program ') rpg = ren.Rename(pg, pop.EmptySet) prp.Termln(rpg) m = ari.Aritytab(rpg, map.EmptyMap) ok, var, arity = ari.ArityCheck(rpg, m) if ok: k = 1 print('arities check out ') else: prp.printf("Variable ") pio.WriteItem(var) prp.printf(" should have arity ") print(arity) exit() lpg = elp.Eloop(rpg, map.EmptyMap) print('Delooped program ') prp.Termln(lpg) fpg = ewh.Eprogram(lpg) print('flattened program') pio.WriteItemln(fpg) prp.Termln(fpg) atab, ftab, ypg = ali.ActualTable(fpg, map.EmptyMap, map.EmptyMap) print('alified program') prp.Termln(ypg) defs = ali.ActualDefs(atab, ftab) subj, wk, body = exp.WhereD(ypg) body = pop.Append(body, defs) #add ali defs ypg = exp.WhereC(subj, wk, body) #print('globalized program') ypg = glb.Gprogram(ypg) #prp.Termln(ypg) print('reflattend program') ypg = ewh.Eprogram(ypg) prp.Termln(ypg) print('atomized program') apg, dfs = atz.Aexpr(ypg) prp.Termln(apg) return apg
def Expect(w,ig): if pio.CurrentItem(ig) == w: pio.NextItem(ig); return True prp.printf('Expected ');pio.WriteItemln(w) print('Found '); pio.Dump5(ig) print() exit()
WVRWord = pop.WordC("wvr") UPNWord = pop.WordC("upn") SWVRWord = pop.WordC("swvr") WHILEWord = pop.WordC("while") INTERMWord = pop.WordC("interm") reservedwords = Reserve(pio.Popliteral("[if then else fi where whereloop end valof]")) definables = {WVRWord,SWVRWord,WHILEWord,UPNWord} #binary ops that have definitions as udfs funstants = {pop.FBY2Word,pop.ATTIME2Word,pop.APPLYWord} #operation constants called like functions eg fby2(a,b1,b2) defined = set() #definables that were actually encountered def ParseFile(fname): f = open(fname,"r") sourceprog = f.read() f.close() ig = pio.ItemGenStringC(sourceprog) return Expr(ig) if __name__ == "__main__": prog = '' while True: ln = input() if ln==';': break prog = prog + '\n' + ln cg = gen.CharStringC(prog) ig = pio.ItemGenChargenC(cg) pio.parsing = True ex = Expr(ig) pio.WriteItemln(ex) prp.Termln(ex) #print("Need defs of ",defined)
def ArityCheckList(l, m): while l != pop.Empty: e, l = pop.ConsD(l) ok, v, n = ArityCheck(e, m) if not ok: return False, v, n return True, None, None def AritytabList(l, m): while l != pop.Empty: e, l = pop.ConsD(l) m = Aritytab(e, m) return m if __name__ == "__main__": pg = prs.ParseFile("testprog.lu") print('renamed program ') rpg = ren.Rename(pg, pop.EmptySet) prp.Termln(rpg) m = Aritytab(rpg, map.EmptyMap) pio.WriteItemln(m) ok, var, arity = ArityCheck(rpg, m) if ok: print('arities check out ') else: prp.printf("Variable ") pio.WriteItem(var) prp.printf(" should have arity ") print(arity) print(ArityCheck(rpg, m))
return exp.Lprecedence(exp.OperationSymbol(t)) return 100 return 100 """ def If(c): ol = OperationOperandL(c); PrpIndent();PrpNewline(); printf("if ");PrpTerm(el1(ol)); PrpIndent();PrpNewline(); printf("then ");PrpTerm(el2(ol)); PrpNewline(); printf("else ");PrpTerm(el3(ol)); PrpExdent();PrpNewline(); printf("fi ");PrpExdent(); } """ if __name__ == "__main__": progfile = open("testprog.lu") progs = progfile.read() progfile.close() cg = gen.CharStringC(progs) ig = pio.ItemGenChargenC(cg) prog = prs.Expr(ig) print('Program is ') pio.WriteItemln(prog) Term(prog) print()
while not pop.EmptyP(funset): #run through the functions fun, funset = pop.AddD(funset) ok, actsl = map.Apply(amap, fun) if not ok: print('No actuals recorded for ' + str(fun)) exit() ok, formals = map.Apply(formap, fun) fms = formals al = actsl while not pop.EmptyP(fms): acts = pop.ConsAll(al, pop.Head) al = pop.ConsAll(al, pop.Tail) fm, fms = pop.ConsD(fms) actexpr = OperationC(ACTUALWord, acts) df = DefinitionC(VarC(fm), EQUALWord, actexpr) deflist = pop.Cons(df, deflist) return deflist if __name__ == "__main__": pg = prs.ParseFile("testprog.lu") atab, ftab, ypg = ActualTable(pg, map.EmptyMap, map.EmptyMap) prp.Term(ypg) print() pio.WriteItemln(atab) pio.WriteItemln(ftab) defs = ActualDefs(atab, ftab) while not pop.EmptyP(defs): df, defs = pop.ConsD(defs) prp.Term(df) print()
return pio.Popliteral('[vpop0 time]') def AssembleSindex(): return pio.Popliteral('[vpop0 space]') def AssembleAnd(opds): return pio.Popliteral('[vpop0 "%s eval not ["false] breakc "%s eval ]' % (opds[0], opds[1])) def AssembleOr(opds): return pio.Popliteral('[vpop0 "%s eval ["true] breakc "%s eval ]' % (opds[0], opds[1])) def AssembleActual(opds): s = '' for opd in opds: s = s + ' ' + opd return pio.Popliteral( '[ savevar setvar waresearch [restorevar] breakc [ %s] saveplace popplace select eval restoreplace waresave restorevar ]' % s) if __name__ == "__main__": o = "[%" opds = ["a", "b", "c", "d"] pio.WriteItemln(AssembleActual(opds))