⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 codecompiler.java

📁 tinyos最新版
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            }        }        return null;    }    public int getslice, setslice, delslice;    public Object Slice(Subscript node, Slice slice) throws Exception {        int ctx = node.ctx;        if (ctx == node.AugStore && augmode == node.Store) {            restoreAugTmps(node, 4);            ctx = node.Store;        } else {            visit(node.value);            if (slice.lower != null)                visit(slice.lower);            else                code.aconst_null();            if (slice.upper != null)                visit(slice.upper);            else                code.aconst_null();            if (slice.step != null)                visit(slice.step);            else                code.aconst_null();            if (node.ctx == node.AugStore && augmode == node.Load) {                saveAugTmps(node, 4);                ctx = node.Load;            }        }        switch (ctx) {        case Subscript.Del:            if (mrefs.delslice == 0) {                mrefs.delslice = code.pool.Methodref(                    "org/python/core/PyObject", "__delslice__",                    "(" + $pyObj + $pyObj + $pyObj + ")V");            }            code.invokevirtual(mrefs.delslice);            return null;        case Subscript.Load:            if (mrefs.getslice == 0) {                mrefs.getslice = code.pool.Methodref(                    "org/python/core/PyObject", "__getslice__",                    "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj);            }            code.invokevirtual(mrefs.getslice);            return null;        case Subscript.Store:            code.aload(temporary);            if (mrefs.setslice == 0) {                mrefs.setslice = code.pool.Methodref(                    "org/python/core/PyObject", "__setslice__",                    "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")V");            }            code.invokevirtual(mrefs.setslice);            return null;        }        return null;    }    public int getitem, delitem, setitem;    public Object visitSubscript(Subscript node) throws Exception {        if (node.slice instanceof Slice) {            return Slice(node, (Slice) node.slice);        }        int ctx = node.ctx;        if (node.ctx == node.AugStore && augmode == node.Store) {            restoreAugTmps(node, 2);            ctx = node.Store;        } else {            visit(node.value);            visit(node.slice);            if (node.ctx == node.AugStore && augmode == node.Load) {                saveAugTmps(node, 2);                ctx = node.Load;            }        }        switch (ctx) {        case Subscript.Del:            if (mrefs.delitem == 0) {                mrefs.delitem = code.pool.Methodref(                    "org/python/core/PyObject", "__delitem__",                    "(" + $pyObj + ")V");            }            code.invokevirtual(mrefs.delitem);            return null;        case Subscript.Load:            if (mrefs.getitem == 0) {                mrefs.getitem = code.pool.Methodref(                    "org/python/core/PyObject", "__getitem__",                    "(" + $pyObj + ")" + $pyObj);            }            code.invokevirtual(mrefs.getitem);            return null;        case Subscript.Store:            code.aload(temporary);            if (mrefs.setitem == 0) {                mrefs.setitem = code.pool.Methodref(                    "org/python/core/PyObject", "__setitem__",                    "(" + $pyObj + $pyObj + ")V");            }            code.invokevirtual(mrefs.setitem);            return null;        }        return null;    }    public Object visitIndex(Index node) throws Exception {        traverse(node);        return null;    }    public Object visitExtSlice(ExtSlice node) throws Exception {        code.new_(code.pool.Class("org/python/core/PyTuple"));        code.dup();        makeArray(node.dims);        if (mrefs.PyTuple_init == 0) {            mrefs.PyTuple_init = code.pool.Methodref(                "org/python/core/PyTuple", "<init>",                "(" + $pyObjArr + ")V");        }        code.invokespecial(mrefs.PyTuple_init);        return null;    }    public int getattr, delattr, setattr;    public Object visitAttribute(Attribute node) throws Exception {        int ctx = node.ctx;        if (node.ctx == node.AugStore && augmode == node.Store) {            restoreAugTmps(node, 2);            ctx = node.Store;        } else {            visit(node.value);            code.ldc(getName(node.attr));            if (node.ctx == node.AugStore && augmode == node.Load) {                saveAugTmps(node, 2);                ctx = node.Load;            }        }        switch (ctx) {        case Attribute.Del:            if (mrefs.delattr == 0) {                mrefs.delattr = code.pool.Methodref(                    "org/python/core/PyObject", "__delattr__",                    "(" + $str + ")V");            }            code.invokevirtual(mrefs.delattr);            return null;        case Attribute.Load:            if (mrefs.getattr == 0) {                mrefs.getattr = code.pool.Methodref(                    "org/python/core/PyObject", "__getattr__",                    "(" + $str + ")" + $pyObj);            }            code.invokevirtual(mrefs.getattr);            return null;        case Attribute.Store:            code.aload(temporary);            if (mrefs.setattr == 0) {                mrefs.setattr = code.pool.Methodref(                    "org/python/core/PyObject", "__setattr__",                    "(" + $str + $pyObj + ")V");            }            code.invokevirtual(mrefs.setattr);            return null;        }        return null;    }    public int getitem2, unpackSequence;    public Object seqSet(exprType[] nodes) throws Exception {        if (mrefs.unpackSequence == 0) {            mrefs.unpackSequence = code.pool.Methodref(                "org/python/core/Py",                "unpackSequence",                "(" + $pyObj + "I)" + $pyObjArr);        }        code.aload(temporary);        code.iconst(nodes.length);        code.invokestatic(mrefs.unpackSequence);        int tmp = code.getLocal("[org/python/core/PyObject");        code.astore(tmp);        for (int i = 0; i < nodes.length; i++) {            code.aload(tmp);            code.iconst(i);            code.aaload();            set(nodes[i]);        }        code.freeLocal(tmp);        return null;    }    public Object seqDel(exprType[] nodes) throws Exception {        for (int i = 0; i < nodes.length; i++) {            visit(nodes[i]);        }        return null;    }    public int PyTuple_init, PyList_init, PyDictionary_init;    public Object visitTuple(Tuple node) throws Exception {        /* if (mode ==AUGSET)            throw new ParseException(                      "augmented assign to tuple not possible", node); */        if (node.ctx == node.Store) return seqSet(node.elts);        if (node.ctx == node.Del) return seqDel(node.elts);        code.new_(code.pool.Class("org/python/core/PyTuple"));        code.dup();        makeArray(node.elts);        if (mrefs.PyTuple_init == 0) {            mrefs.PyTuple_init = code.pool.Methodref(                "org/python/core/PyTuple", "<init>",                "(" + $pyObjArr + ")V");        }        code.invokespecial(mrefs.PyTuple_init);        return null;    }/*    public Object fplist(SimpleNode node) throws Exception {        if (mode == SET) return seqSet(node);        throw new ParseException("in fplist node", node);    }*/    public Object visitList(List node) throws Exception {        /* if (mode ==AUGSET)            throw new ParseException(                      "augmented assign to list not possible", node); */        if (node.ctx == node.Store) return seqSet(node.elts);        if (node.ctx == node.Del) return seqDel(node.elts);        code.new_(code.pool.Class("org/python/core/PyList"));        code.dup();        makeArray(node.elts);        if (mrefs.PyList_init == 0) {            mrefs.PyList_init = code.pool.Methodref(                "org/python/core/PyList", "<init>",                "(" + $pyObjArr + ")V");        }        code.invokespecial(mrefs.PyList_init);        return null;    }    int list_comprehension_count = 0;    public int PyList_init2;    public Object visitListComp(ListComp node) throws Exception {        code.new_(code.pool.Class("org/python/core/PyList"));        code.dup();        if (mrefs.PyList_init2 == 0) {            mrefs.PyList_init2 = code.pool.Methodref(                "org/python/core/PyList", "<init>", "()V");        }        code.invokespecial(mrefs.PyList_init2);        code.dup();        code.ldc("append");        if (mrefs.getattr == 0) {            mrefs.getattr = code.pool.Methodref(                "org/python/core/PyObject", "__getattr__",                "(" + $str + ")" + $pyObj);        }        code.invokevirtual(mrefs.getattr);        String tmp_append = "_[" + (++list_comprehension_count) + "]";                    set(new Name(tmp_append, Name.Store, node));        stmtType n = new Expr(new Call(new Name(tmp_append, Name.Load, node),                                        new exprType[] { node.elt },                                       new keywordType[0], null, null, node),                                            node);        for (int i = node.generators.length - 1; i >= 0; i--) {            listcompType lc = node.generators[i];            for (int j = lc.ifs.length - 1; j >= 0; j--) {                n = new If(lc.ifs[j], new stmtType[] { n }, null, lc.ifs[j]);            }            n = new For(lc.target, lc.iter, new stmtType[] { n }, null, lc);        }        visit(n);        visit(new Delete(new exprType[] { new Name(tmp_append, Name.Del) }));        return null;    }    public Object visitDict(Dict node) throws Exception {        code.new_(code.pool.Class("org/python/core/PyDictionary"));        code.dup();        SimpleNode[] elts = new SimpleNode[node.keys.length * 2];        for (int i = 0; i < node.keys.length; i++) {            elts[i * 2] = node.keys[i];            elts[i * 2 + 1] = node.values[i];        }        makeArray(elts);        if (mrefs.PyDictionary_init == 0) {            mrefs.PyDictionary_init = code.pool.Methodref(                "org/python/core/PyDictionary", "<init>",                "(" + $pyObjArr + ")V");        }        code.invokespecial(mrefs.PyDictionary_init);        return null;    }    public Object visitRepr(Repr node) throws Exception {        visit(node.value);        code.invokevirtual("org/python/core/PyObject", "__repr__",                           "()" + $pyStr);        return null;    }    public int PyFunction_init1,PyFunction_closure_init1;    public Object visitLambda(Lambda node) throws Exception {        String name = "<lambda>";        //Add a return node onto the outside of suite;        modType retSuite = new Suite(new stmtType[] {            new Return(node.body, node) }, node);        setline(node);        code.new_(code.pool.Class("org/python/core/PyFunction"));        code.dup();        loadFrame();        if (mrefs.f_globals == 0) {            mrefs.f_globals = code.pool.Fieldref("org/python/core/PyFrame",                                                 "f_globals", $pyObj);        }        code.getfield(mrefs.f_globals);        ScopeInfo scope = module.getScopeInfo(node);        makeArray(scope.ac.getDefaults());        scope.setup_closure(my_scope);        scope.dump();        module.PyCode(retSuite, name, true, className,                      false, false, node.beginLine, scope).get(code);        Vector freenames = scope.freevars;        if (!makeClosure(freenames)) {            if (mrefs.PyFunction_init1 == 0) {                mrefs.PyFunction_init1 = code.pool.Methodref(                "org/python/core/PyFunction", "<init>",                "(" + $pyObj + $pyObjArr + $pyCode + ")V");            }            code.invokespecial(mrefs.PyFunction_init1);        } else {            if (mrefs.PyFunction_closure_init1 == 0) {                mrefs.PyFunction_closure_init1 = code.pool.Methodref(                "org/python/core/PyFunction", "<init>",                "(" + $pyObj + $pyObjArr + $pyCode + $pyObjArr + ")V");            }            code.invokespecial(mrefs.PyFunction_closure_init1);        }        return null;    }    public int Ellipsis;    public Object visitEllipsis(Ellipsis node) throws Exception {        if (mrefs.Ellipsis == 0) {            mrefs.Ellipsis = code.pool.Fieldref(                "org/python/core/Py", "Ellipsis",                "Lorg/python/core/PyObject;");        }        code.getstatic(mrefs.Ellipsis);        return null;    }    public int PySlice_init;    public Object visitSlice(Slice node) throws Exception {        code.new_(code.pool.Class("org/python/core/PySlice"));        code.dup();        if (node.lower == null) getNone(); else visit(node.lower);        if (node.upper == null) getNone(); else visit(node.upper);        if (node.step == null) getNone(); else visit(node.step);        if (mrefs.PySlice_init == 0) {            mrefs.PySlice_init = code.pool.Methodref(                "org/python/core/PySlice", "<init>",                "(" + $pyObj + $pyObj + $pyObj + ")V");        }        code.invokespecial(mrefs.PySlice_init);        return null;    }    public int makeClass,makeClass_closure;    public Object visitClassDef(ClassDef node) throws Exception {        setline(node);        //Get class name        String name = getName(node.name);        //System.out.println("name: "+name);        code.ldc(name);        makeArra

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -