01: package gnu.jemacs.buffer;
02:
03: import gnu.mapping.*;
04: import gnu.expr.*;
05:
06: /** Represents a "mode instance" - a mode active for a specific {@link Buffer}. */
07:
08: public class Mode extends ModuleBody {
09: public Buffer buffer;
10: public Mode next;
11:
12: public Buffer getBuffer() {
13: return buffer;
14: }
15:
16: public Object apply0(ModuleMethod proc) {
17: return applyN(proc, Values.noArgs);
18: }
19:
20: public Object apply1(ModuleMethod proc, Object arg1) {
21: Object[] args = new Object[1];
22: args[0] = arg1;
23: return applyN(proc, args);
24: }
25:
26: public Object apply2(ModuleMethod proc, Object arg1, Object arg2) {
27: Object[] args = new Object[2];
28: args[0] = arg1;
29: args[1] = arg2;
30: return applyN(proc, args);
31: }
32:
33: public Object apply3(ModuleMethod proc, Object arg1, Object arg2,
34: Object arg3) {
35: Object[] args = new Object[3];
36: args[0] = arg1;
37: args[1] = arg2;
38: args[2] = arg3;
39: return applyN(proc, args);
40: }
41:
42: public Object apply4(ModuleMethod proc, Object arg1, Object arg2,
43: Object arg3, Object arg4) {
44: Object[] args = new Object[4];
45: args[0] = arg1;
46: args[1] = arg2;
47: args[2] = arg3;
48: args[3] = arg4;
49: return applyN(proc, args);
50: }
51:
52: public Object applyN(ModuleMethod proc, Object[] args) {
53: int count = args.length;
54: int num = proc.numArgs();
55: if (count >= (num & 0xFFF) && (num < 0 || count <= (num >> 12))) {
56: switch (count) {
57: case 0:
58: return apply0(proc);
59: case 1:
60: return apply1(proc, args[0]);
61: case 2:
62: return apply2(proc, args[0], args[1]);
63: case 3:
64: return apply3(proc, args[0], args[1], args[2]);
65: case 4:
66: return apply4(proc, args[0], args[1], args[2], args[3]);
67: }
68: }
69: throw new WrongArguments(proc, count);
70: }
71: }
|