Esempio n. 1
0
  public void addProxy() throws Exception {
    // implement PyProxy interface
    classfile.addField("__proxy", $pyObj, Modifier.PROTECTED);
    // setProxy methods
    Code code = classfile.addMethod("_setPyInstance", makeSig("V", $pyObj), Modifier.PUBLIC);
    code.aload(0);
    code.aload(1);
    code.putfield(classfile.name, "__proxy", $pyObj);
    code.return_();

    // getProxy method
    code = classfile.addMethod("_getPyInstance", makeSig($pyObj), Modifier.PUBLIC);
    code.aload(0);
    code.getfield(classfile.name, "__proxy", $pyObj);
    code.areturn();

    String pySys = "Lorg/python/core/PySystemState;";
    // implement PyProxy interface
    classfile.addField("__systemState", pySys, Modifier.PROTECTED | Modifier.TRANSIENT);

    // setProxy method
    code = classfile.addMethod("_setPySystemState", makeSig("V", pySys), Modifier.PUBLIC);

    code.aload(0);
    code.aload(1);
    code.putfield(classfile.name, "__systemState", pySys);
    code.return_();

    // getProxy method
    code = classfile.addMethod("_getPySystemState", makeSig(pySys), Modifier.PUBLIC);
    code.aload(0);
    code.getfield(classfile.name, "__systemState", pySys);
    code.areturn();
  }
Esempio n. 2
0
 public static void doNullReturn(Code code, Class<?> type) throws Exception {
   switch (getType(type)) {
     case tNone:
       break;
     case tCharacter:
     case tBoolean:
     case tByte:
     case tShort:
     case tInteger:
       code.iconst_0();
       code.ireturn();
       break;
     case tLong:
       code.lconst_0();
       code.lreturn();
       break;
     case tFloat:
       code.fconst_0();
       code.freturn();
       break;
     case tDouble:
       code.dconst_0();
       code.dreturn();
       break;
     case tVoid:
       code.return_();
       break;
     default:
       code.aconst_null();
       code.areturn();
       break;
   }
 }
Esempio n. 3
0
  public void addClassDictInit() throws Exception {
    // classDictInit method
    classfile.addInterface(mapClass(org.python.core.ClassDictInit.class));
    Code code =
        classfile.addMethod(
            "classDictInit", makeSig("V", $pyObj), Modifier.PUBLIC | Modifier.STATIC);
    code.aload(0);
    code.ldc("__supernames__");

    int strArray = CodeCompiler.makeStrings(code, supernames);
    code.aload(strArray);
    code.freeLocal(strArray);
    code.invokestatic("org/python/core/Py", "java2py", makeSig($pyObj, $obj));
    code.invokevirtual("org/python/core/PyObject", "__setitem__", makeSig("V", $str, $pyObj));
    code.return_();
  }
Esempio n. 4
0
 public void doConstants() throws Exception {
   Code code = classfile.addMethod("<clinit>", makeSig("V"), Modifier.STATIC);
   code.return_();
 }