| 1 package kawa.standard; 2 import kawa.lang.*; 3 import gnu.mapping.*; 4 5 10 11 public class callcc extends MethodProc 12 { 13 public static final callcc callcc = new callcc(); 14 15 public int numArgs() { return 0x1001; } 16 17 public int match1 (Object proc, CallContext ctx) 18 { 19 if (! (proc instanceof Procedure)) 20 return NO_MATCH_BAD_TYPE; 21 return super.match1(proc, ctx); 22 } 23 24 public void apply (CallContext ctx) throws Throwable  25 { 26 Procedure proc = (Procedure) ctx.value1; 27 Continuation cont = new Continuation(ctx); 28 proc.check1(cont, ctx); 29 proc = ctx.proc; 30 ctx.proc = null; 31 try 32 { 33 proc.apply(ctx); 34 ctx.runUntilDone(); 35 } 36 catch (CalledContinuation ex) 37 { 38 if (ex.continuation != cont) 39 throw ex; 40 Object [] values = ex.values; 41 int nvalues = values.length; 42 for (int i = 0; i < nvalues; i++) 43 ctx.consumer.writeObject(ex.values[i]); 44 } 45 finally 46 { 47 cont.invoked = true; 48 } 49 } 50 51 60 } 61 62 77 | Popular Tags |