man_or_boy.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. var test = function (JS){
  2. function State(){
  3. this.f = null;
  4. this.k = 0;
  5. this.x1 = null;
  6. this.x2 = null;
  7. this.x3 = null;
  8. this.x4 = null;
  9. this.x5 = null;
  10. }
  11. var pB = null;
  12. function call(s/*PState*/){
  13. return s.f(s);
  14. }
  15. function makeEmptyState(f/*Function*/){
  16. var result = null;
  17. result = new State();
  18. result.f = f;
  19. return result;
  20. }
  21. function makeState(f/*Function*/, k/*INTEGER*/, x1/*PState*/, x2/*PState*/, x3/*PState*/, x4/*PState*/, x5/*PState*/){
  22. var result = null;
  23. result = makeEmptyState(f);
  24. result.k = k;
  25. result.x1 = x1;
  26. result.x2 = x2;
  27. result.x3 = x3;
  28. result.x4 = x4;
  29. result.x5 = x5;
  30. return result;
  31. }
  32. function F0(s/*PState*/){
  33. return 0;
  34. }
  35. function F1(s/*PState*/){
  36. return 1;
  37. }
  38. function Fn1(s/*PState*/){
  39. return -1;
  40. }
  41. function A(s/*PState*/){
  42. var res = 0;
  43. if (s.k <= 0){
  44. res = call(s.x4) + call(s.x5) | 0;
  45. }
  46. else {
  47. res = call(makeState(pB, s.k, s.x1, s.x2, s.x3, s.x4, s.x5));
  48. }
  49. return res;
  50. }
  51. function B(s/*PState*/){
  52. --s.k;
  53. return call(makeState(A, s.k, s, s.x1, s.x2, s.x3, s.x4));
  54. }
  55. pB = B;
  56. JS.alert(call(makeState(A, 10, makeEmptyState(F1), makeEmptyState(Fn1), makeEmptyState(Fn1), makeEmptyState(F1), makeEmptyState(F0))));
  57. }(this);