Procedure1.java 1.5 KB

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