public Memory invokeMethodNoThrow(IObject object, String name, Memory... args) { try { return invokeMethod(object, name, args); } catch (RuntimeException e) { throw e; } catch (Exception e) { this.catchUncaught(e); return Memory.NULL; } catch (Throwable e) { throw new RuntimeException(e); } }
default Memory callMethod(Environment env, String name, Memory... args) { try { return env.invokeMethod(this, name, args); } catch (Throwable throwable) { env.forwardThrow(throwable); return Memory.NULL; } }
@Signature public void addEmptyEntry(Environment env, PArchiveEntry entry) throws Throwable { fetchOutput(env); env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry)); env.invokeMethod(output, "closeEntry"); }
@Signature({@Arg("path"), @Arg(value = "mode", optional = @Optional("r"))}) public static Memory getContents(Environment env, Memory... args) throws Throwable { Stream stream = create(env, args[0].toString(), args[1].toString()); try { return env.invokeMethod(stream, "readFully"); } finally { env.invokeMethod(stream, "close"); } }
public static Memory fwrite(Environment env, TraceInfo trace, Memory stream, Memory value, Memory length) { if (stream.instanceOf(Stream.CLASS_NAME)) { try { return env.invokeMethod(trace, stream, "write", value, length); } catch (Throwable throwable) { env.warning(trace, "fwrite(): " + throwable.getMessage()); return Memory.FALSE; } } env.warning(trace, "fwrite(): unable to write to a non-stream"); return Memory.FALSE; }
public static Memory ftell(Environment env, TraceInfo trace, Memory stream) { if (stream.instanceOf(Stream.CLASS_NAME)) { try { return env.invokeMethod(trace, stream, "getPosition"); } catch (Throwable throwable) { env.warning(trace, "ftell(): " + throwable.getMessage()); return Memory.FALSE; } } env.warning(trace, "ftell(): unable to get position from a non-stream"); return Memory.FALSE; }
public static Memory feof(Environment env, TraceInfo trace, Memory stream) { if (stream.instanceOf(Stream.CLASS_NAME)) { try { return env.invokeMethod(trace, stream, "eof"); } catch (Throwable throwable) { env.warning(trace, "feof(): " + throwable.getMessage()); return Memory.FALSE; } } env.warning(trace, "feof(): unable get eof from a non-stream"); return Memory.FALSE; }
public static Memory fread(Environment env, TraceInfo trace, Memory stream, int length) { if (stream.instanceOf(Stream.CLASS_NAME)) { try { return env.invokeMethod(trace, stream, "read", LongMemory.valueOf(length)); } catch (Throwable throwable) { env.warning(trace, "fread(): " + throwable.getMessage()); return Memory.FALSE; } } env.warning(trace, "fread(): unable to read from a non-stream"); return Memory.FALSE; }
@Signature public void write(Environment env, SourceFile file, SourceWriter writer) throws Throwable { writer.write(env, this, file); env.invokeMethod(this, "update", ObjectMemory.valueOf(file)); }
@Signature public void addFromString(Environment env, PArchiveEntry entry, Memory contents) throws Throwable { fetchOutput(env); byte[] binaryBytes = contents.getBinaryBytes(env.getDefaultCharset()); env.assignProperty(entry, "size", LongMemory.valueOf(binaryBytes.length)); env.invokeMethod(output, "putEntry", ObjectMemory.valueOf(entry)); outputStream.write(binaryBytes); env.invokeMethod(output, "closeEntry"); }
public static Memory fgetc(Environment env, TraceInfo trace, Memory stream) { if (stream.instanceOf(Stream.CLASS_NAME)) { try { Memory memory = env.invokeMethod(trace, stream, "read", Memory.CONST_INT_1); return memory.isNull() ? Memory.FALSE : memory; } catch (Throwable throwable) { env.warning(trace, "fgetc(): " + throwable.getMessage()); return Memory.FALSE; } } env.warning(trace, "fgetc(): unable to read from a non-stream"); return Memory.FALSE; }
@Signature({@Arg("string"), @Arg("format"), @Arg(value = "flags", optional = @Optional("-1"))}) public static Memory parseAs(Environment env, Memory... args) throws Throwable { return env.invokeMethod( WrapProcessor.createByCode(env, args[1].toString(), args[2].toInteger()), "parse", args[0] ); }
@Signature({@Arg("memory"), @Arg("format"), @Arg(value = "flags", optional = @Optional("-1"))}) public static Memory formatAs(Environment env, Memory... args) throws Throwable { return env.invokeMethod( WrapProcessor.createByCode(env, args[1].toString(), args[2].toInteger()), "format", args[0] ); }
@Signature public void put(Environment env, ForeachIterator iterator) throws Throwable { while (iterator.next()) { env.invokeMethod(this, "set", iterator.getMemoryKey(), iterator.getValue()); } }
@Signature public Memory __toString(Environment env, Memory... args) throws Throwable { Memory memory = env.invokeMethod(this, "readFully"); if (memory.isString()) { return memory; } else { return StringMemory.valueOf(memory.toString()); } }
@Signature public void update(Environment env, Memory any) throws Throwable { if (any.instanceOf(SourceFile.class)) { SourceFile sourceFile = any.toObject(SourceFile.class); env.invokeMethod(sourceFile, "update", ObjectMemory.valueOf(this)); } }
@Signature public static Memory parseAs(Environment env, String input, String format, int flags) throws Throwable { Stream stream = Stream.create(env, input, "r"); try { return stream.parseAs(env, StringMemory.valueOf(format), LongMemory.valueOf(flags)); } finally { env.invokeMethod(stream, "close"); } }
@Signature public static Memory formatAs(Environment env, String input, Memory value, String format, int flags) throws Throwable { Stream stream = Stream.create(env, input, "w"); try { return stream.writeFormatted(env, value, StringMemory.valueOf(format), LongMemory.valueOf(flags)); } finally { env.invokeMethod(stream, "close"); } }
@Signature({ @Arg("value"), @Arg(value = "format", type = HintType.STRING), @Arg(value = "flags", optional = @Optional("-1")) }) public Memory writeFormatted(Environment env, Memory... args) throws Throwable { WrapProcessor processor = WrapProcessor.createByCode(env, args[1].toString(), args[2].toInteger()); return env.invokeMethod(processor, "formatTo", args[0], ObjectMemory.valueOf(this)); }
@Signature({ @Arg(value = "format", type = HintType.STRING), @Arg(value = "flags", optional = @Optional("-1")) }) public Memory readFormatted(Environment env, Memory... args) throws Throwable { WrapProcessor processor = WrapProcessor.createByCode(env, args[0].toString(), args[1].toInteger()); return env.invokeMethod(processor, "parse", ObjectMemory.valueOf(this)); }