for.cpp 796 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // 'for' function
  2. #include "stdafx.h"
  3. #include "defs.h"
  4. #define A p3
  5. #define B p4
  6. #define I p5
  7. #define X p6
  8. void
  9. eval_for(void)
  10. {
  11. int i, j, k;
  12. // 1st arg (quoted)
  13. X = cadr(p1);
  14. if (!issymbol(X))
  15. stop("for: 1st arg?");
  16. // 2nd arg
  17. push(caddr(p1));
  18. eval();
  19. j = pop_integer();
  20. if (j == (int) 0x80000000)
  21. stop("for: 2nd arg?");
  22. // 3rd arg
  23. push(cadddr(p1));
  24. eval();
  25. k = pop_integer();
  26. if (k == (int) 0x80000000)
  27. stop("for: 3rd arg?");
  28. // remaining args
  29. p1 = cddddr(p1);
  30. B = get_binding(X);
  31. A = get_arglist(X);
  32. for (i = j; i <= k; i++) {
  33. push_integer(i);
  34. I = pop();
  35. set_binding(X, I);
  36. p2 = p1;
  37. while (iscons(p2)) {
  38. push(car(p2));
  39. eval();
  40. pop();
  41. p2 = cdr(p2);
  42. }
  43. }
  44. set_binding_and_arglist(X, B, A);
  45. // return value
  46. push_symbol(NIL);
  47. }