fast-binder.red 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. %
  2. % FAST-BINDER.RED - Fast binding and unbinding routines in LAP for Dec-20 PSL
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 12 July 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. on SysLisp;
  12. external WVar BndStkPtr, % The binding stack pointer
  13. BndStkLowerBound, % Bottom of the binding stack
  14. BndStkUpperBound; % Top of the binding stack
  15. % TAG( FastBind )
  16. lap '((!*Entry FastBind expr 0) % Bind IDs to values in registers
  17. %
  18. % FastBind is called with JSP T5, followed by
  19. % regnum,,idnum
  20. % ...
  21. %
  22. (!*MOVE (WVar BndStkPtr) (reg t2)) % load binding stack pointer
  23. Loop
  24. (!*MOVE (Indexed (reg t5) (WConst 0)) (reg t1)) % get next entry
  25. (tlnn (reg t1) 8#777000) % if it's not an instruction
  26. (!*JUMP (Label MoreLeft)) % keep binding
  27. (!*MOVE (reg t2) (WVar BndStkPtr)) % Otherwise store bind stack pointer
  28. (!*JUMP (MEMORY (reg t5) (WConst 0))) % and return
  29. MoreLeft
  30. (!*WPLUS2 (reg t2) (WConst 2)) % add 2 to binding stack pointer
  31. (caml (reg t2) (WVar BndStkUpperBound)) % if overflow occured
  32. (!*JCALL BStackOverflow) % then error
  33. (hlrz (reg t3) (reg t1)) % stick register number in t3
  34. (caile (reg t3) (WConst MaxRealRegs)) % is it a real register?
  35. (!*WPLUS2 (reg t3) % no, move to arg block
  36. (WConst (difference (WArray ArgumentBlock)
  37. (plus (WConst MaxRealRegs) 1))))
  38. (hrrzm (reg t1) (Indexed (reg t2) (WConst -1)))
  39. % store ID number in BndStk
  40. (!*MOVE (MEMORY (reg t1) (WConst SymVal)) (reg t4))
  41. % get old value for ID in t4
  42. (!*MOVE (reg t4) (MEMORY (reg t2) (WConst 0))) % store value in BndStk
  43. (!*MOVE (MEMORY (reg t3) (WConst 0)) (reg t3)) % get reg value in t3
  44. (!*MOVE (reg t3) (MEMORY (reg t1) (WConst SymVal)))
  45. % store in ID value cell
  46. (aoja (reg t5) Loop) % try again
  47. );
  48. % TAG( FastUnBind )
  49. lap '((!*Entry FastUnBind expr 0) % Unbind last N entries in bind stack
  50. %
  51. % FastUnBind is called with JSP T5, followed by word containing count to
  52. % unbind.
  53. %
  54. (!*MOVE (WVar BndStkPtr) (reg t1)) % get binding stack pointer in t1
  55. (!*MOVE (MEMORY (reg t5) (WConst 0)) (reg t2)) % count in t2
  56. Loop
  57. (!*JUMPWGREATERP (Label MoreLeft) (reg t2) (WConst 0))
  58. % continue if count is > zero
  59. (!*MOVE (reg t1) (WVar BndStkPtr)) % otherwise store bind stack pointer
  60. (!*JUMP (MEMORY (reg t5) (WConst 1))) % and return
  61. MoreLeft
  62. (camge (reg t1) (WVar BndStkLowerBound)) % check for underflow
  63. (!*JCALL BStackUnderflow)
  64. (dmove (reg t3) (Indexed (reg t1) -1)) % get ID # in t3, value in t4
  65. (!*MOVE (reg t4) (MEMORY (reg t3) (WConst SymVal)))
  66. % restore to value cell
  67. (!*WDIFFERENCE (reg t1) (WConst 2)) % adjust binding stack pointer -2
  68. (soja (reg t2) Loop) % and count down by 1, then try again
  69. );
  70. off SysLisp;
  71. END;