Example #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();
  }
Example #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;
   }
 }