01: package gnu.mapping;
02:
03: import gnu.lists.*;
04:
05: public abstract class CpsProcedure extends MethodProc {
06: public CpsProcedure(String n) {
07: setName(n);
08: }
09:
10: public CpsProcedure() {
11: }
12:
13: public abstract void apply(CallContext stack) throws Throwable;
14:
15: public Object applyN(Object[] args) throws Throwable {
16: int count = args.length;
17: checkArgCount(this , count);
18: CallContext stack = new CallContext();
19: stack.setArgsN(args);
20: stack.proc = this ;
21: return applyV(stack);
22: }
23:
24: // FIXME - only checks argument length.
25: public int match(CallContext ctx, Object[] args) {
26: int argCount = args.length;
27: int num = numArgs();
28: int min = num & 0xFFF;
29: if (argCount < min)
30: return NO_MATCH_TOO_FEW_ARGS | min;
31: if (num >= 0) {
32: int max = num >> 12;
33: if (argCount > max)
34: return NO_MATCH_TOO_MANY_ARGS | max;
35: }
36: ctx.setArgsN(args);
37: ctx.proc = this ;
38: return 0;
39: }
40:
41: public Object applyV(CallContext ctx) throws Throwable {
42: return ctx.runUntilValue();
43: }
44: }
|