Shashank Bharadwaj avatar Shashank Bharadwaj committed bd82dcd

other things to get indy to work

Comments (0)

Files changed (5)

src/org/python/compiler/ClassFile.java

     }
 
     public void write(OutputStream stream) throws IOException {
-        cw.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, this.name, null, this.superclass, interfaces);
+        cw.visit(Opcodes.V1_7, Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, this.name, null, this.superclass, interfaces);
         AnnotationVisitor av = cw.visitAnnotation("Lorg/python/compiler/APIVersion;", true);
         // XXX: should imp.java really house this value or should imp.java point into
         // org.python.compiler?

src/org/python/compiler/Module.java

 
         CodeCompiler compiler = new OptimizedCodeCompiler(this, printResults);
 
-        Code c = classfile.addMethod(code.fname, code.methodDesc, ACC_PUBLIC);
+        String funcName = code.fname;
+        if (shouldGenerateOptimized(code)) {
+            funcName = "_" + funcName;
+            // Py.writeWarning("Module: ", "Creating function: " + funcName);
+        }
+
+        Code c = classfile.addMethod(funcName, code.methodDesc, ACC_PUBLIC);
 
         compiler.parse(tree, c, fast_locals, className, classDoc, classBody, scope, cflags);
         return code;
         c.return_();
     }
 
+    public void addWrapperFunctions() throws IOException {
+        for (PyCodeConstant pyCodeConstant : codes) {
+            if(shouldGenerateOptimized(pyCodeConstant)){
+                Code code = classfile.addMethod(pyCodeConstant.fname, 
+                                                MethodHandleHelper.getMethodType(-1).toMethodDescriptorString(), 
+                                                ACC_PUBLIC);
+                code.aload(0);  // this
+                code.aload(1);  // frame
+                code.aload(2);  // threadstate
+                code.aconst_null(); // PyFunction
+                // Now put all the args on stack (if there are any)
+                for (int j = 0; j < pyCodeConstant.argcount; j++) {
+                    code.aload(1);  // frame
+                    code.iconst(j);  // j-th argument
+                    code.invokevirtual(p(PyFrame.class), "getlocal", sig(PyObject.class, int.class));
+                }
+                code.invokevirtual(classfile.name,
+                                   "_" + pyCodeConstant.fname,
+                                   MethodHandleHelper.getMethodType(pyCodeConstant.argcount)
+                                           .toMethodDescriptorString());
+                code.areturn();
+            }
+        }
+    }
+
     public void addBootstrap() throws IOException {
         Code c = classfile.addMethod(CodeLoader.GET_BOOTSTRAP_METHOD_NAME, sig(CodeBootstrap.class),
                 ACC_PUBLIC | ACC_STATIC);
         addRunnable();
         addMain();
         addBootstrap();
+        addWrapperFunctions();
 
         addFunctions();
 

src/org/python/compiler/OptimizedCodeCompiler.java

         return super.visitCall(node);
     }
     
-    @Override
-    public Object visitName(Name node) throws Exception {
-        String name;
-        if (fast_locals) {
-            name = node.getInternalId();
-        } else {
-            name = getName(node.getInternalId());
-        }
-        SymInfo syminf = tbl.get(name);
-        
-        expr_contextType ctx = node.getInternalCtx();
-
-        if (ctx == expr_contextType.AugStore) {
-            ctx = augmode;
-        }
-        
-        switch(ctx){
-            case Load: {
-                if (my_scope != null && my_scope.ac != null && !my_scope.ac.arglist
-                        && !my_scope.ac.keywordlist) {
-                    int argcount = my_scope.ac.names.size();
-//                    if (((syminf.flags & ScopeInfo.BOUND) != 0) && ((syminf.flags & ScopeInfo.FROM_PARAM) != 0) &&
-                    if ((syminf.flags == 13) &&
-                            (syminf.locals_index < argcount) && (argcount <= MethodHandleHelper.MAX_ARGUMENT_ARITY)) {
-                        int i = 0;
-                        for (i = 0; i < argcount; i++) {
-                            if (my_scope.ac.names.get(i).equals(name))
-                                break;
-                        }
-                        if (i < argcount) {
-//                            Py.writeError(TYPE, "loading " + name + " from stack: " + syminf.locals_index);
-                            code.aload(syminf.locals_index + VAR_OFFSET); 
-                            return null;
-                        }
-                    }
-                }
-                break;
-            }
-            case Store: {
-                if (my_scope != null && my_scope.ac != null && !my_scope.ac.arglist
-                        && !my_scope.ac.keywordlist) {
-                    int argcount = my_scope.ac.names.size();
-//                    if (((syminf.flags & ScopeInfo.BOUND) != 0) && ((syminf.flags & ScopeInfo.FROM_PARAM) != 0) && 
-                    if ((syminf.flags == 13) &&
-                            (syminf.locals_index < argcount) && (argcount <= MethodHandleHelper.MAX_ARGUMENT_ARITY)) {
-                        int i = 0;
-                        for (i = 0; i < argcount; i++) {
-                            if (my_scope.ac.names.get(i).equals(name))
-                                break;
-                        }
-                        if (i < argcount) {
-//                            Py.writeError(TYPE, "storing " + name + " to stack: " + syminf.locals_index);
-                            code.aload(temporary);
-                            code.astore(syminf.locals_index + VAR_OFFSET); 
-                            return null;
-                        }
-                    }
-                }
-                break;
-            }
-        }
-        return super.visitName(node);
-    }
+//    @Override
+//    public Object visitName(Name node) throws Exception {
+//        String name;
+//        if (fast_locals) {
+//            name = node.getInternalId();
+//        } else {
+//            name = getName(node.getInternalId());
+//        }
+//        SymInfo syminf = tbl.get(name);
+//        
+//        expr_contextType ctx = node.getInternalCtx();
+//
+//        if (ctx == expr_contextType.AugStore) {
+//            ctx = augmode;
+//        }
+//        
+//        switch(ctx){
+//            case Load: {
+//                if (my_scope != null && my_scope.ac != null && !my_scope.ac.arglist
+//                        && !my_scope.ac.keywordlist) {
+//                    int argcount = my_scope.ac.names.size();
+////                    if (((syminf.flags & ScopeInfo.BOUND) != 0) && ((syminf.flags & ScopeInfo.FROM_PARAM) != 0) &&
+//                    if ((syminf.flags == 13) &&
+//                            (syminf.locals_index < argcount) && (argcount <= MethodHandleHelper.MAX_ARGUMENT_ARITY)) {
+//                        int i = 0;
+//                        for (i = 0; i < argcount; i++) {
+//                            if (my_scope.ac.names.get(i).equals(name))
+//                                break;
+//                        }
+//                        if (i < argcount) {
+////                            Py.writeError(TYPE, "loading " + name + " from stack: " + syminf.locals_index);
+//                            code.aload(syminf.locals_index + VAR_OFFSET); 
+//                            return null;
+//                        }
+//                    }
+//                }
+//                break;
+//            }
+//            case Store: {
+//                if (my_scope != null && my_scope.ac != null && !my_scope.ac.arglist
+//                        && !my_scope.ac.keywordlist) {
+//                    int argcount = my_scope.ac.names.size();
+////                    if (((syminf.flags & ScopeInfo.BOUND) != 0) && ((syminf.flags & ScopeInfo.FROM_PARAM) != 0) && 
+//                    if ((syminf.flags == 13) &&
+//                            (syminf.locals_index < argcount) && (argcount <= MethodHandleHelper.MAX_ARGUMENT_ARITY)) {
+//                        int i = 0;
+//                        for (i = 0; i < argcount; i++) {
+//                            if (my_scope.ac.names.get(i).equals(name))
+//                                break;
+//                        }
+//                        if (i < argcount) {
+////                            Py.writeError(TYPE, "storing " + name + " to stack: " + syminf.locals_index);
+//                            code.aload(temporary);
+//                            code.astore(syminf.locals_index + VAR_OFFSET); 
+//                            return null;
+//                        }
+//                    }
+//                }
+//                break;
+//            }
+//        }
+//        return super.visitName(node);
+//    }
     
     
 //    @Override

src/org/python/core/PyObject.java

     public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3) {
         return __call__(arg0, arg1, arg2, arg3);
     }
-
+    
+    /**
+     * A variant of the __call__ method with four arguments.  The default
+     * behavior is to invoke <code>__call__(args, keywords)</code> with the
+     * appropriate arguments.  The only reason to override this function
+     * would be for improved performance.
+     *
+     * @param arg0     the first argument to the function.
+     * @param arg1     the second argument to the function.
+     * @param arg2     the third argument to the function.
+     * @param arg3     the fourth argument to the function.
+     * @param arg4     the fifth argument to the function.
+     **/
+    public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4) {
+        return __call__(
+            new PyObject[] { arg0, arg1, arg2, arg3, arg4 },
+            Py.NoKeywords);
+    }
+
+    public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, 
+                             PyObject arg4) {
+        return __call__(arg0, arg1, arg2, arg3, arg4);
+    }
+    
+    /**
+     * A variant of the __call__ method with four arguments.  The default
+     * behavior is to invoke <code>__call__(args, keywords)</code> with the
+     * appropriate arguments.  The only reason to override this function
+     * would be for improved performance.
+     *
+     * @param arg0     the first argument to the function.
+     * @param arg1     the second argument to the function.
+     * @param arg2     the third argument to the function.
+     * @param arg3     the fourth argument to the function.
+     * @param arg4     the fifth argument to the function.
+     * @param arg5     the sixth argument to the function.
+     **/
+    public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, 
+                             PyObject arg5) {
+        return __call__(
+            new PyObject[] { arg0, arg1, arg2, arg3, arg4, arg5 },
+            Py.NoKeywords);
+    }
+
+    public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, 
+                             PyObject arg4, PyObject arg5) {
+        return __call__(arg0, arg1, arg2, arg3, arg4, arg5);
+    }
+    
+    /**
+     * A variant of the __call__ method with four arguments.  The default
+     * behavior is to invoke <code>__call__(args, keywords)</code> with the
+     * appropriate arguments.  The only reason to override this function
+     * would be for improved performance.
+     *
+     * @param arg0     the first argument to the function.
+     * @param arg1     the second argument to the function.
+     * @param arg2     the third argument to the function.
+     * @param arg3     the fourth argument to the function.
+     * @param arg4     the fifth argument to the function.
+     * @param arg5     the sixth argument to the function.
+     * @param arg6     the seventh argument to the function.
+     **/
+    public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, 
+                             PyObject arg5, PyObject arg6) {
+        return __call__(
+            new PyObject[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6 },
+            Py.NoKeywords);
+    }
+
+    public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, 
+                             PyObject arg4, PyObject arg5, PyObject arg6) {
+        return __call__(arg0, arg1, arg2, arg3, arg4, arg5, arg6);
+    }
+    
+    /**
+     * A variant of the __call__ method with four arguments.  The default
+     * behavior is to invoke <code>__call__(args, keywords)</code> with the
+     * appropriate arguments.  The only reason to override this function
+     * would be for improved performance.
+     *
+     * @param arg0     the first argument to the function.
+     * @param arg1     the second argument to the function.
+     * @param arg2     the third argument to the function.
+     * @param arg3     the fourth argument to the function.
+     * @param arg4     the fifth argument to the function.
+     * @param arg5     the sixth argument to the function.
+     * @param arg6     the seventh argument to the function.
+     * @param arg7     the eighth argument to the function.
+     **/
+    public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, 
+                             PyObject arg5, PyObject arg6, PyObject arg7) {
+        return __call__(
+            new PyObject[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 },
+            Py.NoKeywords);
+    }
+
+    public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, 
+                             PyObject arg4, PyObject arg5, PyObject arg6, PyObject arg7) {
+        return __call__(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7);
+    }
+    
+    /**
+     * A variant of the __call__ method with four arguments.  The default
+     * behavior is to invoke <code>__call__(args, keywords)</code> with the
+     * appropriate arguments.  The only reason to override this function
+     * would be for improved performance.
+     *
+     * @param arg0     the first argument to the function.
+     * @param arg1     the second argument to the function.
+     * @param arg2     the third argument to the function.
+     * @param arg3     the fourth argument to the function.
+     * @param arg4     the fifth argument to the function.
+     * @param arg5     the sixth argument to the function.
+     * @param arg6     the seventh argument to the function.
+     * @param arg7     the eighth argument to the function.
+     * @param arg8     the ninth argument to the function.
+     **/
+    public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, 
+                             PyObject arg5, PyObject arg6, PyObject arg7, PyObject arg8) {
+        return __call__(
+            new PyObject[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 },
+            Py.NoKeywords);
+    }
+
+    public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, 
+                             PyObject arg4, PyObject arg5, PyObject arg6, PyObject arg7, PyObject arg8) {
+        return __call__(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
+    }
+
+    /**
+     * A variant of the __call__ method with four arguments.  The default
+     * behavior is to invoke <code>__call__(args, keywords)</code> with the
+     * appropriate arguments.  The only reason to override this function
+     * would be for improved performance.
+     *
+     * @param arg0     the first argument to the function.
+     * @param arg1     the second argument to the function.
+     * @param arg2     the third argument to the function.
+     * @param arg3     the fourth argument to the function.
+     * @param arg4     the fifth argument to the function.
+     * @param arg5     the sixth argument to the function.
+     * @param arg6     the seventh argument to the function.
+     * @param arg7     the eighth argument to the function.
+     * @param arg8     the ninth argument to the function.
+     * @param arg9     the tenth argument to the function.
+     **/
+    public PyObject __call__(PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, PyObject arg4, 
+                             PyObject arg5, PyObject arg6, PyObject arg7, PyObject arg8, PyObject arg9) {
+        return __call__(
+            new PyObject[] { arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 },
+            Py.NoKeywords);
+    }
+
+    public PyObject __call__(ThreadState state, PyObject arg0, PyObject arg1, PyObject arg2, PyObject arg3, 
+                             PyObject arg4, PyObject arg5, PyObject arg6, PyObject arg7, PyObject arg8, PyObject arg9) {
+        return __call__(arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
+    }
+    
     public PyObject _callextra(PyObject[] args,
                                String[] keywords,
                                PyObject starargs,

src/org/python/expose/generate/Exposer.java

         for (int i = 0; i < interfaces.length; i++) {
             interfaces[i] = interfacesImplemented[i].getInternalName();
         }
-        cv.visit(V1_5,
+        cv.visit(V1_7,
                  ACC_PUBLIC,
                  getInternalName(),
                  null,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.