Procedure4.java 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package gnu.mapping;
  2. /* #ifdef use:java.lang.invoke */
  3. import java.lang.invoke.MethodHandle;
  4. /* #else */
  5. // import gnu.mapping.CallContext.MethodHandle;
  6. /* #endif */
  7. /**
  8. * Abstract class for 4-argument Scheme procedures.
  9. * @author Per Bothner
  10. */
  11. public abstract class Procedure4 extends Procedure
  12. {
  13. public Procedure4() {
  14. super(false, Procedure4.applyToObject);
  15. }
  16. public Procedure4(String name) {
  17. super(false, Procedure4.applyToObject, name);
  18. }
  19. public int numArgs() { return 0x4004; }
  20. public Object apply0 ()
  21. {
  22. throw new WrongArguments(this, 0);
  23. }
  24. public Object apply1 (Object arg1)
  25. {
  26. throw new WrongArguments(this, 1);
  27. }
  28. public Object apply2 (Object arg1, Object arg2)
  29. {
  30. throw new WrongArguments(this, 2);
  31. }
  32. public Object apply3 (Object arg1, Object arg2, Object arg3)
  33. {
  34. throw new WrongArguments(this, 3);
  35. }
  36. public abstract Object apply4(Object arg1,Object arg2,
  37. Object arg3,Object arg4) throws Throwable;
  38. public Object applyN (Object[] args) throws Throwable
  39. {
  40. if (args.length != 4)
  41. throw new WrongArguments(this, args.length);
  42. return apply4 (args[0], args[1], args[2], args[3]);
  43. }
  44. public static Object applyToObject(Procedure proc, CallContext ctx)
  45. throws Throwable {
  46. Object arg0 = ctx.getNextArg();
  47. Object arg1 = ctx.getNextArg();
  48. Object arg2 = ctx.getNextArg();
  49. Object arg3 = ctx.getNextArg();
  50. if (ctx.checkDone() == 0)
  51. return proc.apply4(arg0, arg1, arg2, arg3);
  52. return ctx;
  53. }
  54. public static final MethodHandle applyToObject
  55. = lookupApplyHandle(Procedure4.class, "applyToObject");
  56. }