binding.red 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. %
  2. % BINDING.RED - Primitives to support Lambda binding
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 18 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % <PSL.KERNEL>BINDING.RED.2, 21-Dec-82 15:57:06, Edit by BENSON
  12. % Added call to %clear-catch-stack in ClearBindings
  13. % Support for binding in compiled code is in FAST-BINDER.RED
  14. on SysLisp;
  15. internal WConst BndStkSize = 2000;
  16. internal WArray BndStk[BndStkSize];
  17. % Only these WVars, which contain addresses rather than indexes, will be
  18. % used to access the binding stack
  19. exported WVar BndStkLowerBound = &BndStk[0],
  20. BndStkUpperBound = &BndStk[BndStkSize-1],
  21. BndStkPtr = &BndStk[0];
  22. % Only the macros BndStkID, BndStkVal and AdjustBndStkPtr will be used
  23. % to access or modify the binding stack and pointer.
  24. syslsp procedure BStackOverflow();
  25. << ChannelPrin2(LispVar ErrOUT!*,
  26. "***** Binding stack overflow, restarting...");
  27. ChannelWriteChar(LispVar ErrOUT!*,
  28. char EOL);
  29. Reset() >>;
  30. syslsp procedure BStackUnderflow();
  31. << ChannelPrin2(LispVar ErrOUT!*,
  32. "***** Binding stack underflow, restarting...");
  33. ChannelWriteChar(LispVar ErrOUT!*,
  34. char EOL);
  35. Reset() >>;
  36. syslsp procedure CaptureEnvironment(); %. Save bindings to be restored
  37. BndStkPtr;
  38. syslsp procedure RestoreEnvironment Ptr; %. Restore old bindings
  39. << if Ptr < BndStkLowerBound then BStackUnderflow()
  40. else while BndStkPtr > Ptr do
  41. << SymVal BndStkID BndStkPtr := BndStkVal BndStkPtr;
  42. BndStkPtr := AdjustBndStkPtr(BndStkPtr, -1) >> >>;
  43. syslsp procedure ClearBindings(); %. Restore bindings to top level
  44. << RestoreEnvironment BndStkLowerBound;
  45. !%clear!-catch!-stack() >>;
  46. syslsp procedure UnBindN N; %. Support for Lambda and Prog interp
  47. RestoreEnvironment AdjustBndStkPtr(BndStkPtr, -IntInf N);
  48. syslsp procedure LBind1(IDName, ValueToBind); %. Support for Lambda
  49. if not IDP IDName then
  50. NonIDError(IDName, "binding")
  51. else if null IDName or IDName eq 'T then
  52. StdError '"T and NIL cannot be rebound"
  53. else
  54. << BndStkPtr := AdjustBndStkPtr(BndStkPtr, 1);
  55. if BndStkPtr > BndStkUpperBound then BStackOverflow()
  56. else
  57. << IDName := IDInf IDName;
  58. BndStkID BndStkPtr := IDName;
  59. BndStkVal BndStkPtr := SymVal IDName;
  60. SymVal IDName := ValueToBind >> >>;
  61. syslsp procedure PBind1 IDName; %. Support for PROG
  62. LBind1(IDName, NIL);
  63. off SysLisp;
  64. END;