Exemple #1
0
    def syntax_quote(form):
        if isinstance(form, Symbol) and compiler.is_compiler_special(form):
            ret = rt.list(QUOTE, form)

        elif isinstance(form, Symbol):
            if rt.namespace(form) is None and rt.name(form).endswith("#"):
                gmap = rt.deref(GEN_SYM_ENV)
                affirm(gmap is not nil, u"Gensym literal used outside a syntax quote")
                gs = rt.get(gmap, form)
                if gs is nil:
                    gs = rt.symbol(rt.str(form, rt.wrap(u"__"), rt.gensym()))
                    GEN_SYM_ENV.set_value(rt.assoc(gmap, form, gs))
                form = gs
            else:
                var = rt.resolve_in(compiler.NS_VAR.deref(), form)
                if var is nil:
                    form = rt.symbol(rt.str(rt.wrap(rt.name(rt.deref(compiler.NS_VAR))), rt.wrap(u"/"), form))
                else:
                    form = rt.symbol(rt.str(rt.wrap(rt.namespace(var)), rt.wrap(u"/"), rt.str(rt.wrap(rt.name(var)))))
            ret = rt.list(QUOTE, form)
        elif is_unquote(form):
            ret = rt.first(rt.next(form))
        elif is_unquote_splicing(form):
            return runtime_error(u"Unquote splicing not used inside list")
        elif rt.vector_QMARK_(form) is true:
            ret = rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(form))
        elif rt.map_QMARK_(form) is true:
            mes = SyntaxQuoteReader.flatten_map(form)
            ret = rt.list(APPLY, HASHMAP, rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(mes)))
        elif form is not nil and rt.seq_QMARK_(form) is true:
            ret = rt.list(APPLY, LIST, rt.cons(CONCAT, SyntaxQuoteReader.expand_list(rt.seq(form))))
        else:
            ret = rt.list(QUOTE, form)
        return ret
Exemple #2
0
    def syntax_quote(form):
        if isinstance(form, Symbol) and compiler.is_compiler_special(form):
            ret = rt.list(QUOTE, form)

        elif isinstance(form, Symbol):
            if rt.namespace(form) is None and rt.name(form).endswith("#"):
                gmap = rt.deref(GEN_SYM_ENV)
                affirm(gmap is not nil, u"Gensym literal used outside a syntax quote")
                gs = rt.get(gmap, form)
                if gs is nil:
                    gs = rt.symbol(rt.str(form, rt.wrap(u"__"), rt.gensym()))
                    GEN_SYM_ENV.set_value(rt.assoc(gmap, form, gs))
                form = gs
            else:
                var = rt.resolve_in(compiler.NS_VAR.deref(), form)
                if var is nil:
                    form = rt.symbol(rt.str(rt.wrap(rt.name(rt.deref(compiler.NS_VAR))), rt.wrap(u"/"), form))
                else:
                    form = rt.symbol(rt.str(rt.wrap(rt.namespace(var)), rt.wrap(u"/"), rt.str(rt.wrap(rt.name(var)))))
            ret = rt.list(QUOTE, form)
        elif is_unquote(form):
            ret = rt.first(rt.next(form))
        elif is_unquote_splicing(form):
            raise Exception("Unquote splicing not used inside list")
        elif rt.vector_QMARK_(form) is true:
            ret = rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(form))
        elif rt.seq_QMARK_(form) is true:
            ret = rt.list(APPLY, LIST, rt.cons(CONCAT, SyntaxQuoteReader.expand_list(rt.seq(form))))
        else:
            ret = rt.list(QUOTE, form)
        return ret
Exemple #3
0
def write_seq(s, wtr):
    write_tag(SEQ, wtr)
    write_int_raw(rt.count(s), wtr)

    s = rt.seq(s)

    while s is not nil:
        write_object(rt.first(s), wtr)
        s = rt.next(s)
Exemple #4
0
def write_seq(s, wtr):
    write_tag(SEQ, wtr)
    write_int_raw(rt.count(s), wtr)

    s = rt.seq(s)

    while s is not nil:
        write_object(rt.first(s), wtr)
        s = rt.next(s)
Exemple #5
0
 def lazy_seq_seq(self):
     self.sval()
     if self._s is not nil:
         ls = self._s
         while True:
             if isinstance(ls, LazySeq):
                 ls = ls.sval()
                 continue
             else:
                 self._s = ls
                 return rt.seq(self._s)
     else:
         return nil
Exemple #6
0
 def lazy_seq_seq(self):
     self.sval()
     if self._s is not nil:
         ls = self._s
         while True:
             if isinstance(ls, LazySeq):
                 ls = ls.sval()
                 continue
             else:
                 self._s = ls
                 return rt.seq(self._s)
     else:
         return nil
Exemple #7
0
 def syntax_quote(form):
     if isinstance(form, Symbol):
         ret = rt.list(QUOTE, form)
     elif is_unquote(form):
         ret = rt.first(rt.next(form))
     elif is_unquote_splicing(form):
         raise Exception("Unquote splicing not used inside list")
     elif rt.vector_QMARK_(form) is true:
         ret = rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(form))
     elif rt.seq_QMARK_(form) is true:
         ret = rt.list(APPLY, LIST, rt.cons(CONCAT, SyntaxQuoteReader.expand_list(rt.seq(form))))
     else:
         ret = rt.list(QUOTE, form)
     return ret
def _eq(self, obj):
    assert isinstance(self, PersistentHashSet)
    if self is obj:
        return true
    if not isinstance(obj, PersistentHashSet):
        return false
    if self._map._cnt != obj._map._cnt:
        return false

    seq = rt.seq(obj)
    while seq is not nil:
        if rt._contains_key(self, rt.first(seq)) is false:
            return false
        seq = rt.next(seq)
    return true
Exemple #9
0
def _eq(self, obj):
    assert isinstance(self, PersistentHashSet)
    if self is obj:
        return true
    if not isinstance(obj, PersistentHashSet):
        return false
    if self._map._cnt != obj._map._cnt:
        return false

    seq = rt.seq(obj)
    while seq is not nil:
        if rt._contains_key(self, rt.first(seq)) is false:
            return false
        seq = rt.next(seq)
    return true
def _eq(self, obj):
    if self is obj:
        return true
    elif isinstance(obj, PersistentVector):
        if self._cnt != obj._cnt:
            return false
        for i in range(0, intmask(self._cnt)):
            if not rt.eq(self.nth(i), obj.nth(i)):
                return false
        return true
    else:
        if not rt.satisfies_QMARK_(proto.ISeqable, obj):
            return false
        seq = rt.seq(obj)
        for i in range(0, intmask(self._cnt)):
            if seq is nil or not rt.eq(self.nth(i), rt.first(seq)):
                return false
            seq = rt.next(seq)
        if seq is not nil:
            return false
        return true
Exemple #11
0
def _eq(self, obj):
    assert isinstance(self, PersistentVector)
    if self is obj:
        return true
    elif isinstance(obj, PersistentVector):
        if self._cnt != obj._cnt:
            return false
        for i in range(0, intmask(self._cnt)):
            if not rt.eq(self.nth(i), obj.nth(i)):
                return false
        return true
    else:
        if obj is nil or not rt.satisfies_QMARK_(proto.ISeqable, obj):
            return false
        seq = rt.seq(obj)
        for i in range(0, intmask(self._cnt)):
            if seq is nil or not rt.eq(self.nth(i), rt.first(seq)):
                return false
            seq = rt.next(seq)
        if seq is not nil:
            return false
        return true
Exemple #12
0
def _first(self):
    assert isinstance(self, LazySeq)
    rt.seq(self)
    return rt.first(self._s)
Exemple #13
0
def _next(self):
    rt.seq(self)
    return rt.next(self._s)
Exemple #14
0
def _next(self):
    assert isinstance(self, LazySeq)
    rt.seq(self)
    return rt.next(self._s)
Exemple #15
0
def _first(self):
    rt.seq(self)
    return rt.first(self._s)
Exemple #16
0
def _next(self):
    assert isinstance(self, LazySeq)
    rt.seq(self)
    return rt.next(self._s)
Exemple #17
0
def _first(self):
    assert isinstance(self, LazySeq)
    rt.seq(self)
    return rt.first(self._s)