def compileLetMacro(comp, form): if len(form) < 3: raise CompilerException("alias-properties takes at least two args", form) form = form.next() s = RT.seq(form.first()) syms = [] while s is not None: sym = s.first() syms.append(sym) s = s.next() if s is None: raise CompilerException("let-macro takes a even number of bindings") macro = s.first() comp.pushAlias(sym, LocalMacro(sym, macro)) s = s.next() body = form.next() code = compileImplcitDo(comp, body) comp.popAliases(syms) return code
def compileLetStar(comp, form): if len(form) < 2: raise CompilerException("let* takes at least two args", form) form = form.next() if not isinstance(form.first(), IPersistentVector): raise CompilerException( "let* takes a vector as it's first argument", form) bindings = RT.seq(form.first()) args = [] code = [] if bindings and len(bindings) % 2: raise CompilerException("let* takes a even number of bindings", form) while bindings: local, bindings = bindings.first(), bindings.next() body, bindings = bindings.first(), bindings.next() if not isinstance(local, Symbol) or local.ns is not None: raise CompilerException( "bindings must be non-namespaced symbols", form) code.extend(comp.compile(body)) alias = RenamedLocal(Symbol("{0}_{1}".format(local, RT.nextID())) if comp.getAlias(local) else local) comp.pushAlias(local, alias) args.append(local) code.extend(alias.compileSet(comp)) form = form.next() code.extend(compileImplcitDo(comp, form)) comp.popAliases(args) return code
def compileLetMacro(comp, form): if len(form) < 3: raise CompilerException("alias-properties takes at least two args", form) form = form.next() s = RT.seq(form.first()) syms = [] while s is not None: sym = s.first() syms.append(sym) s = s.next() if s is None: raise CompilerException( "let-macro takes a even number of bindings") macro = s.first() comp.pushAlias(sym, LocalMacro(sym, macro)) s = s.next() body = form.next() code = compileImplcitDo(comp, body) comp.popAliases(syms) return code
def compileLetStar(comp, form): if len(form) < 2: raise CompilerException("let* takes at least two args", form) form = form.next() if not isinstance(form.first(), IPersistentVector): raise CompilerException("let* takes a vector as it's first argument", form) bindings = RT.seq(form.first()) args = [] code = [] if bindings and len(bindings) % 2: raise CompilerException("let* takes a even number of bindings", form) while bindings: local, bindings = bindings.first(), bindings.next() body, bindings = bindings.first(), bindings.next() if not isinstance(local, Symbol) or local.ns is not None: raise CompilerException("bindings must be non-namespaced symbols", form) code.extend(comp.compile(body)) alias = RenamedLocal( Symbol("{0}_{1}".format(local, RT.nextID())) if comp. getAlias(local) else local) comp.pushAlias(local, alias) args.append(local) code.extend(alias.compileSet(comp)) form = form.next() code.extend(compileImplcitDo(comp, form)) comp.popAliases(args) return code
def __eq__(self, other): """Equality test. other -- ISeq or something that implements the seq protocol ASeq.__eq__ is actually used.""" return (self is other or (RT.isSeqable(other) and not isinstance(other, (IPersistentSet, IPersistentMap)) and self.seq() == RT.seq(other)))
def __init__(self, comp, form): form = RT.seq(form) if len(form) < 2: raise CompilerException("FN defs must have at least two vars", form) argv = form.first() if not isinstance(argv, PersistentVector): raise CompilerException("FN arg list must be a vector", form) body = form.next() self.locals, self.args, self.lastisargs, self.argsname = unpackArgs( argv) endLabel = Label("endLabel") argcode = [(LOAD_CONST, len), (LOAD_FAST, '__argsv__'), (CALL_FUNCTION, 1), (LOAD_CONST, len(self.args) - (1 if self.lastisargs else 0)), (COMPARE_OP, ">=" if self.lastisargs else "==")] argcode.extend(emitJump(endLabel)) for x in range(len(self.args)): if self.lastisargs and x == len(self.args) - 1: offset = len(self.args) - 1 argcode.extend([(LOAD_FAST, '__argsv__'), (LOAD_CONST, offset), (SLICE_1, None), (STORE_FAST, self.argsname.name)]) argcode.extend(cleanRest(self.argsname.name)) else: argcode.extend([(LOAD_FAST, '__argsv__'), (LOAD_CONST, x), (BINARY_SUBSCR, None), (STORE_FAST, self.args[x])]) for x in self.locals: comp.pushAlias(x, FnArgument(x)) recurlabel = Label("recurLabel") recur = { "label": recurlabel, "args": map(lambda x: comp.getAlias(symbol(x)).compileSet(comp), self.args) } bodycode = [(recurlabel, None)] comp.pushRecur(recur) bodycode.extend(compileImplcitDo(comp, body)) bodycode.append((RETURN_VALUE, None)) bodycode.extend(emitLanding(endLabel)) comp.popRecur() comp.popAliases(self.locals) self.argcode = argcode self.bodycode = bodycode
def __eq__(self, other): """Equality test. other -- ISeq or something that implements the seq protocol ASeq.__eq__ is actually used.""" if self is other: return True if not RT.isSeqable(other) or isinstance(other, IPersistentSet): return False s = self.seq() o = RT.seq(other) return s == o
def __eq__(self, other): if self is other: return True se = RT.seq(other) if isinstance(se, RT.NotSeq): return False ms = self.seq() while se is not None: if ms is None or not se.first() == ms.first(): return False ms = ms.next() se = se.next() return ms is None
def conjToAssoc(self, o): if isinstance(o, MapEntry): return self.assoc(o.getKey(), o.getValue()) if hasattr(o, "__getitem__") and hasattr(o, "__len__"): if len(o) != 2: raise InvalidArgumentException("Vector arg must be a pair") return self.assoc(o[0], o[1]) s = RT.seq(o) map = self for s in s.interator(): m = s.first() map = map.assoc(m.getKey(), m.getValue()) return map
def __init__(self, comp, form): form = RT.seq(form) if len(form) < 1: raise CompilerException("FN defs must have at least one arg", form) argv = form.first() if not isinstance(argv, PersistentVector): raise CompilerException("FN arg list must be a vector", form) body = form.next() self.locals, self.args, self.lastisargs, self.argsname = unpackArgs(argv) endLabel = Label("endLabel") argcode = [(LOAD_CONST, len), (LOAD_FAST, '__argsv__'), (CALL_FUNCTION, 1), (LOAD_CONST, len(self.args) - (1 if self.lastisargs else 0)), (COMPARE_OP, ">=" if self.lastisargs else "==")] argcode.extend(emitJump(endLabel)) for x in range(len(self.args)): if self.lastisargs and x == len(self.args) - 1: offset = len(self.args) - 1 argcode.extend([(LOAD_FAST, '__argsv__'), (LOAD_CONST, offset), (SLICE_1, None), (STORE_FAST, self.argsname.name)]) argcode.extend(cleanRest(self.argsname.name)) else: argcode.extend([(LOAD_FAST, '__argsv__'), (LOAD_CONST, x), (BINARY_SUBSCR, None), (STORE_FAST, self.args[x])]) for x in self.locals: comp.pushAlias(x, FnArgument(x)) recurlabel = Label("recurLabel") recur = {"label": recurlabel, "args": map(lambda x: comp.getAlias(symbol(x)).compileSet(comp), self.args)} bodycode = [(recurlabel, None)] comp.pushRecur(recur) bodycode.extend(compileImplcitDo(comp, body)) bodycode.append((RETURN_VALUE, None)) bodycode.extend(emitLanding(endLabel)) comp.popRecur() comp.popAliases(self.locals) self.argcode = argcode self.bodycode = bodycode
def vec(seq): """Return a PersistentVector. seq -- ISeq If seq is an APersistentVector return seq. Else the returned vector will contain the items in seq.""" if isinstance(seq, APersistentVector): return seq s = RT.seq(seq) v = EMPTY while s is not None: v = v.cons(RT.first(s)) s = RT.next(s) return v
def __eq__(self, other): if self is other: return True if not RT.isSeqable(other) or (isinstance(other, IPersistentSet)): return False se = RT.seq(other) if isinstance(se, RT.NotSeq): print other, type(other) return False ms = self.seq() while se is not None: if ms is None or not se.first() == ms.first(): return False ms = ms.next() se = se.next() return ms is None
def __eq__(self, other): if self is other: return True if not RT.isSeqable(other) or isinstance(other, IPersistentSet): return False se = RT.seq(other) # XXX: don't think this is used # if isinstance(se, RT.NotSeq): # print other, type(other) # return False ms = self.seq() while se is not None: if ms is None or not se.first() == ms.first(): return False ms = ms.next() se = se.next() return ms is None
def __init__(self, comp, form, argsv): with ResolutionContext(comp): form = RT.seq(form) if len(form) < 1: raise CompilerException("FN defs must have at least one arg", form) argv = form.first() if not isinstance(argv, PersistentVector): raise CompilerException("FN arg list must be a vector", form) body = form.next() self.locals, self.args, self.lastisargs, self.argsname = unpackArgs(argv) wlocals = map(lambda x: tr.Argument(x.getName()), self.locals) argcode = tr.GreaterOrEqual( tr.Call(getAttrChain("__builtin__.len"), argsv), tr.Const(len(self.args) - (1 if self.lastisargs else 0))) argscode = [] for x in range(len(wlocals)): if self.lastisargs and x == len(wlocals) - 1: offset = len(wlocals) - 1 argscode.append(tr.Do(wlocals[x].StoreLocal(argsv.Slice1(tr.Const(x))), wlocals[x].StoreLocal(cleanRest(wlocals[x])))) else: argscode.append(wlocals[x].StoreLocal(argsv.Subscript(tr.Const(x)))) for x in wlocals: comp.pushAlias(symbol(x.name),x) bodycode = compileImplcitDo(comp, body).Return() self.argcode = argcode self.extractcode = tr.Do(*argscode) self.bodycode = bodycode
def __eq__(self, other): return isinstance(other, (Sequential, list, tuple)) and RT.seq(other) is None
def __eq__(self, other): s = self.seq() if not RT.isSeqable(other): return False o = RT.seq(other) return s == o
def __eq__(self, other): s = self.seq() o = RT.seq(other) return s == o
def __eq__(self, other): s = self.seq() if not RT.isSeqable(other) or isinstance(other, IPersistentSet): return False o = RT.seq(other) return s == o