@Override public void invoke(ExecutionContext context) throws ResolvedControlThrowable { System.out.println("invoke"); try { context.resumeAfter(new AsyncTask() { @Override public void execute(ContinueCallback callback) { System.out.println("in task"); callback.finished(); } }); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } // control never reaches this point System.out.println("after async -- not!"); }
@Override public void invoke(ExecutionContext context, Object id, Object arg2) throws ResolvedControlThrowable { @SuppressWarnings("unchecked") final BlockingQueue<Continuation> workQueue = (BlockingQueue<Continuation>) arg2; System.out.println("[" + Thread.currentThread() + "]: Invoke " + id); AtomicInteger var = new AtomicInteger(0); try { context.resumeAfter(new SleepAndSpawn(id, var, context, workQueue)); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, new Object[] {id, var}); } throw new AssertionError(); // control never reaches this point }
@Override public void invoke(ExecutionContext context, Object[] args) throws ResolvedControlThrowable { try { Dispatch.call(context, x); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, Arrays.copyOf(args, args.length)); } resume(context, args); }
private void load(ExecutionContext context, ByteString modName, LuaFunction loader, Object origin) throws ResolvedControlThrowable { try { Dispatch.call(context, loader, modName, origin); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, modName); } resumeLoad(context, modName); }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { IoFile file = lib.getDefaultInputFile(); ArrayList<Object> callArgs = new ArrayList<>(); callArgs.add(file); callArgs.addAll(Arrays.asList(args.copyAll())); try { Dispatch.call(context, file_read(), callArgs.toArray()); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } resume(context, file); }
@Override public void invoke(ExecutionContext context, Object arg1, Object arg2, Object arg3) throws ResolvedControlThrowable { try { // b + c Dispatch.add(context, arg2, arg3); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, arg1); } resume(context, arg1); }
@Override public void invoke(ExecutionContext context, Object t, Object k) throws ResolvedControlThrowable { try { Dispatch.index(context, t, k); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } resume(context, null); }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { try { context.yield(args.copyAll()); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } }
@Override public void invoke(ExecutionContext context, Object t, Object k, Object v) throws ResolvedControlThrowable { try { Dispatch.setindex(context, t, k, v); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } resume(context, null); }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { IoFile file = lib.getDefaultOutputFile(); ArrayList<Object> callArgs = new ArrayList<>(); callArgs.add(file); callArgs.addAll(Arrays.asList(args.copyAll())); try { Dispatch.call(context, file_write(), callArgs.toArray()); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } resume(context, file); }
@Override public void resume(ExecutionContext context, Object target) throws ResolvedControlThrowable { try { Dispatch.call(context, target, context.getReturnBuffer().getAsArray()); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(); } }
@Override public void invoke(ExecutionContext context, Object[] args) throws ResolvedControlThrowable { context.getReturnBuffer().setTo(); try { context.resume(coroutine, args); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { IoFile outFile = lib.getDefaultOutputFile(); try { Dispatch.call(context, file_flush()); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, outFile); } resume(context, outFile); }
private void _erase(ExecutionContext context, int state, Table t, long idx, Object result) throws ResolvedControlThrowable { try { switch (state) { case _ERASE_PREPARE: state = _ERASE_RESUME; Dispatch.setindex(context, t, idx, null); case _ERASE_RESUME: // we're done break; default: throw new IllegalStateException("Illegal state: " + state); } } catch (UnresolvedControlThrowable ct) { // no need to carry any information but the result around throw ct.resolve(this, new SuspendedState(state, null, null, 0, 0, result)); } // finished, set the result context.getReturnBuffer().setTo(result); }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { final IoFile file = args.hasNext() ? args.nextUserdata(IoFile.typeName(), IoFile.class) : lib.getDefaultOutputFile(); try { Dispatch.call(context, file_close(), file); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { Coroutine coroutine = args.nextCoroutine(); Object[] resumeArgs = args.copyRemaining(); context.getReturnBuffer().setTo(); try { context.resume(coroutine, resumeArgs); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { Table table = args.nextTable(); long index = args.nextInteger(); index += 1; try { Dispatch.index(context, table, index); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, index); } Object result = context.getReturnBuffer().get0(); processResult(context, index, result); }
private static void _call_comparison_mt(ExecutionContext context, boolean cmpTo, Object handler, Object a, Object b) throws UnresolvedControlThrowable { try { call(context, handler, a, b); } catch (UnresolvedControlThrowable ct) { // suspended in the metamethod call throw ct.resolve(cmpResultResumable(cmpTo), null).unresolve(); } // not suspended: set the result, possibly flipping it ReturnBuffer result = context.getReturnBuffer(); result.setTo(cmpTo == Conversions.booleanValueOf(result.get0())); }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { Object callTarget = args.nextAny(); Object[] callArgs = args.copyRemaining(); try { Dispatch.call(context, callTarget, callArgs); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } catch (Exception ex) { resumeError(context, null, Conversions.toErrorObject(ex)); return; } resume(context, null); }
@Override protected void invoke(ExecutionContext context, ArgumentIterator args) throws ResolvedControlThrowable { Table t = args.nextTable(); Object metamethod = Metatables.getMetamethod(context, MT_PAIRS, t); if (metamethod != null) { try { Dispatch.call(context, metamethod, t); } catch (UnresolvedControlThrowable ct) { throw ct.resolve(this, null); } ReturnBuffer rbuf = context.getReturnBuffer(); rbuf.setTo(rbuf.get0(), rbuf.get1(), rbuf.get2()); } else { ReturnBuffer rbuf = context.getReturnBuffer(); rbuf.setTo(NEXT, t, null); } }