Exemplo n.º 1
0
    def compileForm(self, form):
        if form.first() in builtins:
            return builtins[form.first()](self, form)
        if isinstance(form.first(), Symbol):
            macro = findItem(self.getNS(), form.first())

            if macro is not None:
                if (hasattr(macro, "meta") and macro.meta()[_MACRO_])\
                or (hasattr(macro, "macro?") and getattr(macro, "macro?")):
                    args = RT.seqToTuple(form.next())
                    mresult = macro(macro, self, *args)
                    s = repr(mresult)
                    return self.compile(mresult)
        if isinstance(form.first(), Symbol):
            if form.first().name.startswith(".-"):
                return self.compilePropertyAccess(form)
            if form.first().name.startswith(".") and form.first().ns is None:
                return self.compileMethodAccess(form)
        c = self.compile(form.first())
        f = form.next()
        acount = 0
        while f is not None:
            c.extend(self.compile(f.first()))
            acount += 1
            f = f.next()
        c.append((CALL_FUNCTION, acount))

        return c
Exemplo n.º 2
0
    def compileForm(self, form):
        if form.first() in builtins:
            return builtins[form.first()](self, form)
        if isinstance(form.first(), Symbol):
            macro = findItem(self.getNS(), form.first())
            # Handle macros here
            # TODO: Break this out into a seperate function
            if macro is not None:
                if not isinstance(macro, type) \
		        and (hasattr(macro, "meta") and macro.meta()[_MACRO_])\
                or (hasattr(macro, "macro?") and getattr(macro, "macro?")):
                    args = RT.seqToTuple(form.next())
                    
                    macroform = macro
                    if hasattr(macro, "_macro-form"):
                    	macroform = getattr(macro, "_macro-form")

                    mresult = macro(macroform, self, *args)
                    
                    if hasattr(mresult, "withMeta") \
                       and hasattr(form, "meta"):
                        mresult = mresult.withMeta(form.meta())
                    s = repr(mresult)
                    return self.compile(mresult)
        if isinstance(form.first(), Symbol):
            if form.first().ns == "py.bytecode":
                return compileBytecode(self, form)
            if form.first().name.startswith(".-"):
                return self.compilePropertyAccess(form)
            if form.first().name.startswith(".") and form.first().ns is None:
                return self.compileMethodAccess(form)
        c = self.compile(form.first())
        f = form.next()
        acount = 0
        while f is not None:
            c.extend(self.compile(f.first()))
            acount += 1
            f = f.next()
        c.append((CALL_FUNCTION, acount))

        return c