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 __eq__(self, other): if self is other: return True if not (isinstance(other, Sequential) or isinstance(other, list) or isinstance(other, tuple)): return False se = RT.seq(other) ms = self.seq() for s in se.interate(): if ms is None or not (s.first() == ms.first()): return False return ms is None
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) < 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_FAST, '__argsv__'), (LOAD_ATTR, '__len__'), (CALL_FUNCTION, 0), (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": 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 __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") code = [(LOAD_FAST, '__argsv__'), (LOAD_ATTR, '__len__'), (CALL_FUNCTION, 0), (LOAD_CONST, len(self.args) - (1 if self.lastisargs else 0)), (COMPARE_OP, ">=" if self.lastisargs else "=="), (POP_JUMP_IF_FALSE, endLabel)] for x in range(len(self.args)): if self.lastisargs and x == len(self.args) - 1: offset = len(self.args) - 1 code.extend([(LOAD_FAST, '__argsv__'), (LOAD_CONST, offset), (SLICE_1, None), (STORE_FAST, self.argsname.name)]) else: code.extend([(LOAD_FAST, '__argsv__'), (LOAD_CONST, x), (BINARY_SUBSCR, None), (STORE_FAST, self.args[x])]) comp.pushLocals(self.locals) recurlabel = Label("recurLabel") recur = {"label": recurlabel, "args": self.args} code.append((recurlabel, None)) comp.pushRecur(recur) code.extend(compileImplcitDo(comp, body)) code.append((RETURN_VALUE, None)) code.append((endLabel, None)) comp.popRecur() comp.popLocals(self.locals) self.code = code
def __eq__(self, other): s = self.seq() o = RT.seq(other) return s == o
def __eq__(self, other): return isinstance(other, (Sequential, list, tuple)) and RT.seq(other) is None
def __eq__(self, other): return (isinstance(other, Sequential) or isinstance(other, list) or isinstance(other, tuple)) \ and RT.seq(other) is None