def syntaxQuote(self, form): from py.clojure.lang.compiler import builtins as compilerbuiltins if form in compilerbuiltins: ret = RT.list(_QUOTE_, form) elif isinstance(form, Symbol): sym = form if sym.ns is None and sym.name.endswith("#"): gmap = GENSYM_ENV.deref() if gmap == None: raise ReaderException("Gensym literal not in syntax-quote, before", self.rdr) gs = gmap[sym] if gs is None: gs = symbol(None, sym.name[:-1] + "__" + str(RT.nextID()) + "__auto__") GENSYM_ENV.set(gmap.assoc(sym, gs)) sym = gs elif sym.ns is None and sym.name.endswith("."): ret = sym elif sym.ns is None and sym.name.startswith("."): ret = sym elif sym.ns is not None: ret = sym else: comp = currentCompiler.get(lambda: None) if comp is None: raise IllegalStateException("No Compiler found in syntax quote!") ns = comp.getNS() if ns is None: raise IllegalStateException("No ns in reader") sym = symbol(ns.__name__, sym.name) ret = RT.list(_QUOTE_, sym) else: if isUnquote(form): return form.next().first() elif isUnquoteSplicing(form): raise IllegalStateException("splice not in list") elif isinstance(form, IPersistentCollection): if isinstance(form, IPersistentMap): keyvals = flattenMap(form) ret = RT.list(_APPLY_, _HASHMAP_, RT.list(RT.cons(_CONCAT_, self.sqExpandList(keyvals.seq())))) elif isinstance(form, (IPersistentVector, IPersistentSet)): ret = RT.list(_APPLY_, _VECTOR_, RT.list(_SEQ_, RT.cons(_CONCAT_, self.sqExpandList(form.seq())))) elif isinstance(form, (ISeq, IPersistentList)): seq = form.seq() if seq is None: ret = RT.cons(_LIST_, None) else: ret = RT.list(_SEQ_, RT.cons(_CONCAT_, self.sqExpandList(seq))) else: raise IllegalStateException("Unknown collection type") elif isinstance(form, (int, float, str, Keyword)): ret = form else: ret = RT.list(_QUOTE_, form) if hasattr(form, "meta") and form.meta() is not None: newMeta = form.meta().without(LINE_KEY) if len(newMeta) > 0: return RT.list(_WITH_META_, ret, self.syntaxQuote(form.meta())) return ret
def seqFrom(self, key, ascending): if self._count > 0: stack = None t = tree while t is not None: c = self.doCompare(key, t.key()) if c == 0: stack = RT.cons(t, stack) return Seq(stack, ascending) elif ascending: if c < 0: stack = RT.cons(t, stack) t = t.left() else: t = t.right() else: if c > 0: stack = RT.cons(t, stack) t = t.right() else: t = t.left() if stack is not None: return Seq(stack, ascending) return None
def pushSeq(t, stack, asc): while t is not None: stack = RT.cons(t, stack) t = t.left() if asc else t.right() return stack
def pushRecur(self, label): """ Pushes a new recursion label. All recur calls will loop back to this point """ self.recurPoint = RT.cons(label, self.recurPoint)
def pushLocals(self, locals): for x in locals: if x in self.locals: self.locals[x] = RT.cons(x, self.locals[x]) else: self.locals[x] = RT.cons(x, None)
def pushRecur(self, label): self.recurPoint = RT.cons(label, self.recurPoint)