encaps.e 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. #
  2. ; $Id$
  3. ; (c) copyright 1983 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. ;
  5. ; This product is part of the Amsterdam Compiler Kit.
  6. ;
  7. ; Permission to use, sell, duplicate or disclose this software must be
  8. ; obtained in writing. Requests for such permissions may be sent to
  9. ;
  10. ; Dr. Andrew S. Tanenbaum
  11. ; Wiskundig Seminarium
  12. ; Vrije Universiteit
  13. ; Postbox 7161
  14. ; 1007 MC Amsterdam
  15. ; The Netherlands
  16. ;
  17. mes 2,EM_WSIZE,EM_PSIZE
  18. ; procedure encaps(procedure p; procedure(q(n:integer));
  19. ; {call q if a trap occurs during the execution of p}
  20. ; {if q returns, continue execution of p}
  21. inp $handler
  22. #define PIISZ 2*EM_PSIZE
  23. #define PARG 0
  24. #define QARG PIISZ
  25. #define E_ELB -EM_PSIZE
  26. #define E_EHA -2*EM_PSIZE
  27. ; encaps is called with two parameters:
  28. ; - procedure instance identifier of q (QARG)
  29. ; - procedure instance identifier of p (PARG)
  30. ; and two local variables:
  31. ; - the lb of the previous encaps (E_ELB)
  32. ; - the procedure identifier of the previous handler (E_EHA)
  33. ;
  34. ; One static variable:
  35. ; - the lb of the currently active encaps (enc_lb)
  36. enc_lb
  37. bss EM_PSIZE,0,0
  38. exp $encaps
  39. pro $encaps,PIISZ
  40. ; save lb of previous encaps
  41. lae enc_lb
  42. loi EM_PSIZE
  43. lal E_ELB
  44. sti EM_PSIZE
  45. ; set new lb
  46. lxl 0
  47. lae enc_lb
  48. sti EM_PSIZE
  49. ; save old handler id while setting up the new handler
  50. lpi $handler
  51. sig
  52. lal E_EHA
  53. sti EM_PSIZE
  54. ; handler is ready, p can be called
  55. ; p doesn't expect parameters except possibly the static link
  56. ; always passing the link won't hurt
  57. lal PARG
  58. loi PIISZ
  59. cai
  60. asp EM_PSIZE
  61. ; reinstate old handler
  62. lal E_ELB
  63. loi EM_PSIZE
  64. lae enc_lb
  65. sti EM_PSIZE
  66. lal E_EHA
  67. loi EM_PSIZE
  68. sig
  69. asp EM_PSIZE
  70. ret 0
  71. end ?
  72. #define TRAP 0
  73. #define H_ELB -EM_PSIZE
  74. ; handler is called with one parameter:
  75. ; - trap number (TRAP)
  76. ; one local variable
  77. ; - the current LB of the enclosing encaps (H_ELB)
  78. pro $handler,EM_PSIZE
  79. ; save LB of nearest encaps
  80. lae enc_lb
  81. loi EM_PSIZE
  82. lal H_ELB
  83. sti EM_PSIZE
  84. ; fetch setting for previous encaps via LB of nearest
  85. lal H_ELB
  86. loi EM_PSIZE
  87. adp E_ELB
  88. loi EM_PSIZE ; LB of previous encaps
  89. lae enc_lb
  90. sti EM_PSIZE
  91. lal H_ELB
  92. loi EM_PSIZE
  93. adp E_EHA
  94. loi EM_PSIZE ; previous handler
  95. sig
  96. asp EM_PSIZE
  97. ; previous handler is re-instated, time to call Q
  98. lol TRAP ; the one and only real parameter
  99. lal H_ELB
  100. loi EM_PSIZE
  101. lpb ; argument base of enclosing encaps
  102. adp QARG
  103. loi PIISZ
  104. exg EM_PSIZE
  105. dup EM_PSIZE ; The static link is now on top
  106. zer EM_PSIZE
  107. cmp
  108. zeq *1
  109. ; non-zero LB
  110. exg EM_PSIZE
  111. cai
  112. asp EM_WSIZE+EM_PSIZE
  113. bra *2
  114. 1
  115. ; zero LB
  116. asp EM_PSIZE
  117. cai
  118. asp EM_WSIZE
  119. 2
  120. ; now reinstate handler for continued execution of p
  121. lal H_ELB
  122. loi EM_PSIZE
  123. lae enc_lb
  124. sti EM_PSIZE
  125. lpi $handler
  126. sig
  127. asp EM_PSIZE
  128. rtt
  129. end ?