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

📄 codecompiler.java

📁 tinyos最新版
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            exceptionTest(exc, else_end, node, 1);            handler_end.setPosition();            //do else clause            suite(node.orelse);            else_end.setPosition();        }        code.freeFinallyLocal(exc);        code.addExceptionHandler(start, end, handler_start,                                 code.pool.Class("java/lang/Throwable"));        return null;    }    public Object visitSuite(Suite node) throws Exception {        return suite(node.body);    }    public Object suite(stmtType[] stmts) throws Exception {        int n = stmts.length;        for(int i = 0; i < n; i++) {            Object exit = visit(stmts[i]);            //System.out.println("exit: "+exit+", "+n+", "+(exit != null));            if (exit != null)                return Exit;        }        return null;    }    public Object visitBoolOp(BoolOp node) throws Exception {        Label end = code.getLabel();        visit(node.values[0]);        for (int i = 1; i < node.values.length; i++) {            code.dup();            if (mrefs.nonzero == 0) {                mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject",                                                    "__nonzero__", "()Z");            }            code.invokevirtual(mrefs.nonzero);            switch (node.op) {            case BoolOp.Or :                 code.ifne(end);                break;            case BoolOp.And :                 code.ifeq(end);                break;            }            code.pop();            visit(node.values[i]);        }        end.setPosition();        return null;    }    public Object visitCompare(Compare node) throws Exception {        int tmp1 = code.getLocal("org/python/core/PyObject");        int tmp2 = code.getLocal("org/python/core/PyObject");        int op;        if (mrefs.nonzero == 0) {            mrefs.nonzero = code.pool.Methodref("org/python/core/PyObject",                                                "__nonzero__", "()Z");        }        Label end = code.getLabel();        visit(node.left);        int n = node.ops.length;        for(int i = 0; i < n - 1; i++) {            visit(node.comparators[i]);            code.dup();            code.astore(tmp1);            code.invokevirtual(make_cmpop(node.ops[i]));            code.dup();            code.astore(tmp2);            code.invokevirtual(mrefs.nonzero);            code.ifeq(end);            code.aload(tmp1);        }        visit(node.comparators[n-1]);        code.invokevirtual(make_cmpop(node.ops[n-1]));        if (n > 1) {            code.astore(tmp2);            end.setPosition();            code.aload(tmp2);        }        code.freeLocal(tmp1);        code.freeLocal(tmp2);        return null;    }    int[] compare_ops = new int[11];    public int make_cmpop(int op) throws Exception {        if (compare_ops[op] == 0) {            String name = null;            switch (op) {            case Compare.Eq:    name = "_eq"; break;            case Compare.NotEq: name = "_ne"; break;            case Compare.Lt:    name = "_lt"; break;            case Compare.LtE:   name = "_le"; break;            case Compare.Gt:    name = "_gt"; break;            case Compare.GtE:   name = "_ge"; break;            case Compare.Is:    name = "_is"; break;            case Compare.IsNot: name = "_isnot"; break;            case Compare.In:    name = "_in"; break;            case Compare.NotIn: name = "_notin"; break;            }            compare_ops[op] = code.pool.Methodref(                "org/python/core/PyObject", name,                "(" + $pyObj + ")" + $pyObj);        }        return compare_ops[op];    }    static String[] bin_methods = new String[] {        null,        "_add",        "_sub",        "_mul",        "_div",        "_mod",        "_pow",        "_lshift",        "_rshift",        "_or",        "_xor",        "_and",        "_floordiv",    };    int[] bin_ops = new int[13];    public int make_binop(int op) throws Exception {        if (bin_ops[op] == 0) {            String name = bin_methods[op];            if (op == BinOp.Div && module.getFutures().areDivisionOn()) {                name = "_truediv";            }            bin_ops[op] = code.pool.Methodref(                "org/python/core/PyObject", name,                "(" + $pyObj + ")" + $pyObj);        }        return bin_ops[op];    }    public Object visitBinOp(BinOp node) throws Exception {        visit(node.left);        visit(node.right);        code.invokevirtual(make_binop(node.op));        return null;    }        static String[] unary_methods = new String[] {        null,        "__invert__",        "__not__",        "__pos__",        "__neg__",    };    int[] unary_ops = new int[unary_methods.length];    public int make_unaryop(int op) throws Exception {        if (unary_ops[op] == 0) {            String name = unary_methods[op];            unary_ops[op] = code.pool.Methodref(                "org/python/core/PyObject", name, "()" + $pyObj);        }        return unary_ops[op];    }    public Object visitUnaryOp(UnaryOp node) throws Exception {        visit(node.operand);        code.invokevirtual(make_unaryop(node.op));        return null;    }    static String[] aug_methods = new String[] {        null,        "__iadd__",        "__isub__",        "__imul__",        "__idiv__",        "__imod__",        "__ipow__",        "__ilshift__",        "__irshift__",        "__ior__",        "__ixor__",        "__iand__",        "__ifloordiv__",    };    int[] augbin_ops = new int[aug_methods.length];    public int make_augbinop(int op) throws Exception {        if (augbin_ops[op] == 0) {            String name = aug_methods[op];            if (op == BinOp.Div && module.getFutures().areDivisionOn()) {                name = "__itruediv__";            }            augbin_ops[op] = code.pool.Methodref(                "org/python/core/PyObject", name,                "(" + $pyObj + ")" + $pyObj);        }        return augbin_ops[op];    }    public Object visitAugAssign(AugAssign node) throws Exception {        visit(node.value);        int tmp = storeTop();        augmode = expr_contextType.Load;        visit(node.target);        code.aload(tmp);        code.invokevirtual(make_augbinop(node.op));        code.freeLocal(tmp);        temporary = storeTop();        augmode = expr_contextType.Store;        visit(node.target);        code.freeLocal(temporary);        return null;    }    public static void makeStrings(Code c, String[] names, int n)        throws IOException    {        c.iconst(n);        c.anewarray(c.pool.Class("java/lang/String"));        int strings = c.getLocal("[java/lang/String");        c.astore(strings);        for (int i=0; i<n; i++) {            c.aload(strings);            c.iconst(i);            c.ldc(names[i]);            c.aastore();        }        c.aload(strings);        c.freeLocal(strings);    }    public int invokea0, invokea1, invokea2;    public int invoke2;    public Object Invoke(Attribute node, SimpleNode[] values)        throws Exception    {        String name = getName(node.attr);        visit(node.value);        code.ldc(name);        //System.out.println("invoke: "+name+": "+values.length);        switch (values.length) {        case 0:            if (mrefs.invokea0 == 0) {                mrefs.invokea0 = code.pool.Methodref(                    "org/python/core/PyObject", "invoke",                    "(" + $str + ")" + $pyObj);            }            code.invokevirtual(mrefs.invokea0);            break;        case 1:            if (mrefs.invokea1 == 0) {                mrefs.invokea1 = code.pool.Methodref(                    "org/python/core/PyObject", "invoke",                    "(" + $str + $pyObj + ")" + $pyObj);            }            visit(values[0]);            code.invokevirtual(mrefs.invokea1);            break;        case 2:            if (mrefs.invokea2 == 0) {                mrefs.invokea2 = code.pool.Methodref(                    "org/python/core/PyObject", "invoke",                    "(" + $str + $pyObj + $pyObj + ")" + $pyObj);            }            visit(values[0]);            visit(values[1]);            code.invokevirtual(mrefs.invokea2);            break;        default:            makeArray(values);            if (mrefs.invoke2 == 0) {                mrefs.invoke2 = code.pool.Methodref(                    "org/python/core/PyObject", "invoke",                    "(" + $str + $pyObjArr + ")" + $pyObj);            }            code.invokevirtual(mrefs.invoke2);            break;        }        return null;    }    public int callextra;    public int call1, call2;    public int calla0, calla1, calla2, calla3, calla4;    public Object visitCall(Call node) throws Exception {        String[] keys = new String[node.keywords.length];        exprType[] values = new exprType[node.args.length + keys.length];        for (int i = 0; i < node.args.length; i++) {            values[i] = node.args[i];        }        for (int i = 0; i < node.keywords.length; i++) {            keys[i] = node.keywords[i].arg;            values[node.args.length + i] = node.keywords[i].value;        }        // Detect a method invocation with no keywords        if (node.keywords == null && node.starargs == null &&            node.kwargs == null && node.func instanceof Attribute)        {            return Invoke((Attribute) node.func, values);        }        visit(node.func);        if (node.starargs != null || node.kwargs != null) {            makeArray(values);            makeStrings(code, keys, keys.length);            if (node.starargs == null)                code.aconst_null();            else                visit(node.starargs);            if (node.kwargs == null)                code.aconst_null();            else                visit(node.kwargs);            if (mrefs.callextra == 0) {                mrefs.callextra = code.pool.Methodref(                    "org/python/core/PyObject", "_callextra",                    "(" + $pyObjArr + $strArr + $pyObj + $pyObj + ")" +                    $pyObj);            }            code.invokevirtual(mrefs.callextra);        } else if (keys.length > 0) {            makeArray(values);            makeStrings(code, keys, keys.length);            if (mrefs.call1 == 0) {                mrefs.call1 = code.pool.Methodref(                    "org/python/core/PyObject", "__call__",                    "(" + $pyObjArr + $strArr + ")" + $pyObj);            }            code.invokevirtual(mrefs.call1);        } else {            switch (values.length) {            case 0:                if (mrefs.calla0 == 0) {                    mrefs.calla0 = code.pool.Methodref(                        "org/python/core/PyObject", "__call__",                        "()" + $pyObj);                }                code.invokevirtual(mrefs.calla0);                break;            case 1:                if (mrefs.calla1 == 0) {                    mrefs.calla1 = code.pool.Methodref(                        "org/python/core/PyObject", "__call__",                        "(" + $pyObj + ")" + $pyObj);                }                visit(values[0]);                code.invokevirtual(mrefs.calla1);                break;            case 2:                if (mrefs.calla2 == 0) {                    mrefs.calla2 = code.pool.Methodref(                        "org/python/core/PyObject", "__call__",                        "(" + $pyObj + $pyObj + ")" + $pyObj);                }                visit(values[0]);                visit(values[1]);                code.invokevirtual(mrefs.calla2);                break;            case 3:                if (mrefs.calla3 == 0) {                    mrefs.calla3 = code.pool.Methodref(                        "org/python/core/PyObject", "__call__",                        "(" + $pyObj + $pyObj + $pyObj + ")" + $pyObj);                }                visit(values[0]);                visit(values[1]);                visit(values[2]);                code.invokevirtual(mrefs.calla3);                break;            case 4:                if (mrefs.calla4 == 0) {                    mrefs.calla4 = code.pool.Methodref(                        "org/python/core/PyObject", "__call__",                        "(" + $pyObj + $pyObj + $pyObj + $pyObj + ")" +                            $pyObj);                }                visit(values[0]);                visit(values[1]);                visit(values[2]);                visit(values[3]);                code.invokevirtual(mrefs.calla4);                break;            default:                makeArray(values);                if (mrefs.call2 == 0) {                    mrefs.call2 = code.pool.Methodref(                        "org/python/core/PyObject", "__call__",                        "(" + $pyObjArr + ")" + $pyObj);                }                code.invokevirtual(mrefs.call2);                break;

⌨️ 快捷键说明

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