public RunnableInvoker(Environment env, Callback<Memory, Memory[]> runnable) { super(env, env.trace()); this.runnable = runnable; }
final public Memory call(Memory... args) throws Throwable { trace = trace == null ? (env == null ? TraceInfo.UNKNOWN : env.trace()) : trace; /*pushCall(trace, args); try {*/ return invoke(args); /*} finally { popCall(); }*/ }
public static Memory invokeMethod(Memory object, String methodName, Environment env, Memory... args) throws Throwable { return invokeMethod(object, methodName, methodName.toLowerCase(), env, env.trace(), args); }
@SuppressWarnings("unchecked") public <T> T toBean(Environment env, T instance) { return toBean(env, env.trace(), instance); }
@SuppressWarnings("unchecked") public static Memory wrap(Environment env, Object o) { if (o == null) { return NULL; } MemoryOperation operation = MemoryOperation.get(o.getClass(), null); if (operation != null) { return operation.unconvertNoThow(env, env == null ? TraceInfo.UNKNOWN : env.trace(), o); } else { return NULL; } }
@Signature public Memory start(Environment env, Memory... args){ invoker.setTrace(env.trace()); thread.start(); return Memory.NULL; }
@Signature public Memory run(Environment env, Memory... args){ invoker.setTrace(env.trace()); thread.run(); return Memory.NULL; }
public void __throwException(BaseBaseException e, boolean clearSilent) { if (clearSilent) { __clearSilent(); } e.setTraceInfo(this, trace()); throw e; }
@Signature private Memory __sleep(Environment env, Memory... args) { env.exception(env.trace(), "Serialization of 'Generator' is not allowed"); return Memory.NULL; }
public Memory getObjectProperty(IObject object, String propertyName) throws Throwable { if (object == null) { return Memory.NULL; } return object.getReflection().getProperty(this, this.trace(), object, propertyName, null, -1); }
public <T extends IObject> T newMock(Environment env) throws Throwable { if (nativeConstructor == null) { env.error(env.trace(), ErrorType.E_CORE_ERROR, "Cannot find a java constructor %s(Environment, ClassEntity)", getName()); } try { IObject object = (IObject) nativeConstructor.newInstance(env, this); object.setAsMock(); return (T) object; } catch (InstantiationException e) { return null; } }
@Signature(@Arg(value = "mode", optional = @Optional("r"))) public Memory open(Environment env, Memory... args) throws Throwable { ClassEntity classEntity = env.fetchClass(FileStream.class); return classEntity.newObject(env, env.trace(), true, StringMemory.valueOf(file.getPath()), args[0]); }
public Invoker toInvoker(Environment env) { Invoker invoker = Invoker.valueOf(env, null, this); if (invoker != null) { invoker.setTrace(env.trace()); invoker.setMemory(this); return invoker; } return null; }
@Signature({@Arg(value = "object", optional = @Optional, type = HintType.OBJECT)}) public Memory invoke(Environment env, Memory... args) throws Throwable { Memory self = args[0]; Memory[] arguments = args.length == 1 ? new Memory[0] : Arrays.copyOfRange(args, 1, args.length - 1); Invoker invoker; if (self.isNull()) { invoker = new StaticMethodInvoker(env, env.trace(), methodEntity.getClazzName(), methodEntity); } else { invoker = new DynamicMethodInvoker(env, env.trace(), self.toObject(IObject.class), methodEntity); } return invoker.call(arguments); }
@Signature public Memory newInstance(Environment env, Memory... args) throws Throwable { return new ObjectMemory(entity.newObject(env, env.trace(), true, args)); }
@Signature(@Arg(value = "runnable")) public Memory execute(Environment env, Memory... args) throws Throwable { Invoker invoker = Invoker.valueOf(this.environment, null, args[0]); if (invoker == null) { env.exception("Argument 1 must be callable in environment"); return Memory.NULL; } invoker.setTrace(env.trace()); return invoker.call(); }
@Signature public Memory getDefaultValue(Environment env, Memory... args) { if (entity.getDefaultValue() == null) { exception(env, "Parameter has no default value"); return Memory.NULL; } return entity.getDefaultValue().toImmutable(env, env.trace()); }
@Signature public Memory call(Environment env, Memory... args) { invoker.setTrace(env.trace()); env.popCall(); try { return invoker.callNoThrow(args); } finally { env.pushCall(this, "call"); } }
@Name("throw") @Signature(@Arg(value = "throwable", nativeType = BaseException.class)) synchronized public Memory _throw(Environment env, Memory... args) { if (valid) { newThrow = args[0].toObject(BaseException.class); ((BaseException)newThrow).setTraceInfo(env, env.trace()); return _next(env); } else { env.__throwException(args[0].toObject(BaseException.class)); } return Memory.NULL; }
@Signature(@Arg("name")) public Memory getPackage(Environment env, Memory... args) { PackageManager packageManager = this.environment.getPackageManager(); if (packageManager.has(args[0].toString())) { Package aPackage = packageManager.tryFind(args[0].toString(), env.trace()); if (aPackage == null) { return Memory.NULL; } return ObjectMemory.valueOf(new WrapPackage(env, aPackage)); } else { return Memory.NULL; } }