?? codecompiler.java
字號:
public Object visitAssign(Assign node) throws Exception { setline(node); visit(node.value); if (node.targets.length == 1) { set(node.targets[0]); return null; } int tmp = storeTop(); for (int i=node.targets.length-1; i>=0; i--) { set(node.targets[i], tmp); } code.freeLocal(tmp); return null; } public int print1, print2, print3, print4, print5, print6; public Object visitPrint(Print node) throws Exception { setline(node); int tmp = -1; int printcomma, printlnv, println; if (node.dest != null) { visit(node.dest); tmp = storeTop(); if (mrefs.print4 == 0) { mrefs.print4 = pool.Methodref( "org/python/core/Py", "printComma", "(" + $pyObj + $pyObj + ")V"); } printcomma = mrefs.print4; if (mrefs.print5 == 0) { mrefs.print5 = pool.Methodref( "org/python/core/Py", "println", "(" + $pyObj + $pyObj + ")V"); } println = mrefs.print5; if (mrefs.print6 == 0) { mrefs.print6 = pool.Methodref( "org/python/core/Py", "printlnv", "(" + $pyObj + ")V"); } printlnv = mrefs.print6; } else { if (mrefs.print1 == 0) { mrefs.print1 = pool.Methodref( "org/python/core/Py", "printComma", "(" + $pyObj + ")V"); } printcomma = mrefs.print1; if (mrefs.print2 == 0) { mrefs.print2 = pool.Methodref( "org/python/core/Py", "println", "(" + $pyObj + ")V"); } println = mrefs.print2; if (mrefs.print3 == 0) { mrefs.print3 = pool.Methodref( "org/python/core/Py", "println", "()V"); } printlnv = mrefs.print3; } if (node.values == null || node.values.length == 0) { if (node.dest != null) code.aload(tmp); code.invokestatic(printlnv); } else { for (int i = 0; i < node.values.length; i++) { if (node.dest != null) code.aload(tmp); visit(node.values[i]); if (node.nl && i == node.values.length - 1) { code.invokestatic(println); } else { code.invokestatic(printcomma); } } } if (node.dest != null) code.freeLocal(tmp); return null; } public Object visitDelete(Delete node) throws Exception { setline(node); traverse(node); return null; } public Object visitPass(Pass node) throws Exception { setline(node); return null; } public Object visitBreak(Break node) throws Exception { //setline(node); Not needed here... if (breakLabels.empty()) { throw new ParseException("'break' outside loop", node); } for (int i = finallyLabels.size() - 1; i >= bcfLevel; i--) { doFinallyPart((InFinally)finallyLabels.elementAt(i)); } code.goto_((Label)breakLabels.peek()); return null; } public Object visitContinue(Continue node) throws Exception { //setline(node); Not needed here... if (continueLabels.empty()) { throw new ParseException("'continue' not properly in loop", node); } for (int i = finallyLabels.size() - 1; i >= bcfLevel; i--) { doFinallyPart((InFinally)finallyLabels.elementAt(i)); } code.goto_((Label)continueLabels.peek()); return Exit; } int yield_count = 0; int f_savedlocals; public Object visitYield(Yield node) throws Exception { setline(node); if (!fast_locals) { throw new ParseException("'yield' outside function", node); } if (!finallyLabels.empty()) { throw new ParseException("'yield' not allowed in a 'try' "+ "block with a 'finally' clause", node); } InFinally inFinally = null; if (inFinallyLabels.size() > 0) inFinally = (InFinally) inFinallyLabels.peek(); if (inFinally == null) { saveLocals(); visit(node.value); setLastI(++yield_count); code.areturn(); Label restart = code.getLabel(); yields.addElement(restart); restart.setPosition(); restoreLocals(); } else { saveLocals(); visit(node.value); code.areturn(); code.ret(inFinally.retLocal); inFinally.labels[inFinally.cnt++].setPosition(); code.stack = 1; code.astore(inFinally.retLocal); restoreLocals(); } return null; } private void restoreLocals() throws Exception { Vector v = code.getActiveLocals(); loadFrame(); if (mrefs.f_savedlocals == 0) { mrefs.f_savedlocals = code.pool.Fieldref( "org/python/core/PyFrame", "f_savedlocals", "[Ljava/lang/Object;"); } code.getfield(mrefs.f_savedlocals); int locals = code.getLocal("[java/lang/Object"); code.astore(locals); for (int i = 0; i < v.size(); i++) { String type = (String) v.elementAt(i); if (type == null) continue; code.aload(locals); code.iconst(i); code.aaload(); code.checkcast(code.pool.Class(type)); code.astore(i); } code.freeLocal(locals); } private void saveLocals() throws Exception { Vector v = code.getActiveLocals();//System.out.println("bs:" + bs); code.iconst(v.size()); //code.anewarray(code.pool.Class("org/python/core/PyObject")); code.anewarray(code.pool.Class("java/lang/Object")); int locals = code.getLocal("[java/lang/Object"); code.astore(locals); for (int i = 0; i < v.size(); i++) { String type = (String) v.elementAt(i); if (type == null) continue; code.aload(locals); code.iconst(i); //code.checkcast(code.pool.Class("java/lang/Object")); if (i == 2222) { code.aconst_null(); } else code.aload(i); code.aastore(); } if (mrefs.f_savedlocals == 0) { mrefs.f_savedlocals = code.pool.Fieldref( "org/python/core/PyFrame", "f_savedlocals", "[Ljava/lang/Object;"); } loadFrame(); code.aload(locals); code.putfield(mrefs.f_savedlocals); code.freeLocal(locals); } public Object visitReturn(Return node) throws Exception { return visitReturn(node, false); } public Object visitReturn(Return node, boolean inEval) throws Exception { setline(node); if (!inEval && !fast_locals) { throw new ParseException("'return' outside function", node); } int tmp = 0; if (node.value != null) { if (my_scope.generator) throw new ParseException("'return' with argument " + "inside generator", node); visit(node.value); tmp = code.getReturnLocal(); code.astore(tmp); } for (int i = finallyLabels.size() - 1; i >= 0; i--) { doFinallyPart((InFinally) finallyLabels.elementAt(i)); } setLastI(-1); if (node.value != null) { code.aload(tmp); } else { getNone(); } code.areturn(); return Exit; } public int makeException0, makeException1, makeException2, makeException3; public Object visitRaise(Raise node) throws Exception { setline(node); traverse(node); if (node.type == null) { if (mrefs.makeException0 == 0) { mrefs.makeException0 = code.pool.Methodref( "org/python/core/Py", "makeException", "()" + $pyExc); } code.invokestatic(mrefs.makeException0); } else if (node.inst == null) { if (mrefs.makeException1 == 0) { mrefs.makeException1 = code.pool.Methodref( "org/python/core/Py", "makeException", "(" + $pyObj + ")" + $pyExc); } code.invokestatic(mrefs.makeException1); } else if (node.tback == null) { if (mrefs.makeException2 == 0) { mrefs.makeException2 = code.pool.Methodref( "org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + ")" + $pyExc); } code.invokestatic(mrefs.makeException2); } else { if (mrefs.makeException3 == 0) { mrefs.makeException3 = code.pool.Methodref( "org/python/core/Py", "makeException", "(" + $pyObj + $pyObj + $pyObj + ")" + $pyExc); } code.invokestatic(mrefs.makeException3); } code.athrow(); return Exit; } public int importOne, importOneAs; public Object visitImport(Import node) throws Exception { setline(node); for (int i = 0; i < node.names.length; i++) { String asname = null; if (node.names[i].asname != null) { String name = node.names[i].name; asname = node.names[i].asname; code.ldc(name); loadFrame(); if (mrefs.importOneAs == 0) { mrefs.importOneAs = code.pool.Methodref( "org/python/core/imp", "importOneAs", "(" + $str + $pyFrame + ")" + $pyObj); } code.invokestatic(mrefs.importOneAs); } else { String name = node.names[i].name; asname = name; if (asname.indexOf('.') > 0) asname = asname.substring(0, asname.indexOf('.')); code.ldc(name); loadFrame(); if (mrefs.importOne == 0) { mrefs.importOne = code.pool.Methodref( "org/python/core/imp", "importOne", "(" + $str + $pyFrame + ")" + $pyObj); } code.invokestatic(mrefs.importOne); } set(new Name(asname, Name.Store, node)); } return null; } public int importAll, importFrom; public Object visitImportFrom(ImportFrom node) throws Exception { Future.checkFromFuture(node); // future stmt support setline(node); code.ldc(node.module); if (node.names.length > 0) { String[] names = new String[node.names.length]; String[] asnames = new String[node.names.length]; for (int i = 0; i < node.names.length; i++) { names[i] = node.names[i].name; asnames[i] = node.names[i].asname; if (asnames[i] == null) asnames[i] = names[i]; } makeStrings(code, names, names.length); loadFrame(); if (mrefs.importFrom == 0) { mrefs.importFrom = code.pool.Methodref( "org/python/core/imp", "importFrom", "(" + $str + $strArr + $pyFrame + ")" + $pyObjArr); } code.invokestatic(mrefs.importFrom); int tmp = storeTop(); for (int i = 0; i < node.names.length; i++) { code.aload(tmp); code.iconst(i); code.aaload(); set(new Name(asnames[i], Name.Store, node)); } code.freeLocal(tmp); } else { loadFrame(); if (mrefs.importAll == 0) { mrefs.importAll = code.pool.Methodref( "org/python/core/imp", "importAll", "(" + $str + $pyFrame + ")V"); } code.invokestatic(mrefs.importAll); } return null; } public Object visitGlobal(Global node) throws Exception { return null; } public int exec; public Object visitExec(Exec node) throws Exception { setline(node); visit(node.body); if (node.globals != null) { visit(node.globals); } else { code.aconst_null(); } if (node.locals != null) { visit(node.locals); } else { code.aconst_null(); } //do the real work here if (mrefs.exec == 0) { mrefs.exec = code.pool.Methodref( "org/python/core/Py", "exec", "(" + $pyObj + $pyObj + $pyObj + ")V"); } code.invokestatic(mrefs.exec); return null;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -