home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / pcl / src-16f.lha / compiler / sparc / nlx.lisp < prev    next >
Encoding:
Text File  |  1991-11-06  |  8.4 KB  |  274 lines

  1. ;;; -*- Package: SPARC -*-
  2. ;;;
  3. ;;; **********************************************************************
  4. ;;; This code was written as part of the Spice Lisp project at
  5. ;;; Carnegie-Mellon University, and has been placed in the public domain.
  6. ;;; If you want to use this code or any part of Spice Lisp, please contact
  7. ;;; Scott Fahlman (FAHLMAN@CMUC). 
  8. ;;; **********************************************************************
  9. ;;;
  10. ;;; $Header: nlx.lisp,v 1.4 91/08/31 22:11:00 wlott Exp $
  11. ;;;
  12. ;;;    This file contains the definitions of VOPs used for non-local exit
  13. ;;; (throw, lexical exit, etc.)
  14. ;;;
  15. ;;; Written by Rob MacLachlan
  16. ;;;
  17. (in-package "SPARC")
  18.  
  19. ;;; MAKE-NLX-SP-TN  --  Interface
  20. ;;;
  21. ;;;    Make an environment-live stack TN for saving the SP for NLX entry.
  22. ;;;
  23. (def-vm-support-routine make-nlx-sp-tn (env)
  24.   (environment-live-tn
  25.    (make-representation-tn *fixnum-primitive-type* immediate-arg-scn)
  26.    env))
  27.  
  28.  
  29.  
  30. ;;; Save and restore dynamic environment.
  31. ;;;
  32. ;;;    These VOPs are used in the reentered function to restore the appropriate
  33. ;;; dynamic environment.  Currently we only save the Current-Catch and binding
  34. ;;; stack pointer.  We don't need to save/restore the current unwind-protect,
  35. ;;; since unwind-protects are implicitly processed during unwinding.  If there
  36. ;;; were any additional stacks, then this would be the place to restore the top
  37. ;;; pointers.
  38.  
  39.  
  40. ;;; Make-Dynamic-State-TNs  --  Interface
  41. ;;;
  42. ;;;    Return a list of TNs that can be used to snapshot the dynamic state for
  43. ;;; use with the Save/Restore-Dynamic-Environment VOPs.
  44. ;;;
  45. (def-vm-support-routine make-dynamic-state-tns ()
  46.   (make-n-tns 4 *any-primitive-type*))
  47.  
  48. (define-vop (save-dynamic-state)
  49.   (:results (catch :scs (descriptor-reg))
  50.         (nfp :scs (descriptor-reg))
  51.         (nsp :scs (descriptor-reg))
  52.         (eval :scs (descriptor-reg)))
  53.   (:vop-var vop)
  54.   (:generator 13
  55.     (load-symbol-value catch lisp::*current-catch-block*)
  56.     (let ((cur-nfp (current-nfp-tn vop)))
  57.       (when cur-nfp
  58.     (move nfp cur-nfp)))
  59.     (move nsp nsp-tn)
  60.     (load-symbol-value eval lisp::*eval-stack-top*)))
  61.  
  62. (define-vop (restore-dynamic-state)
  63.   (:args (catch :scs (descriptor-reg))
  64.      (nfp :scs (descriptor-reg))
  65.      (nsp :scs (descriptor-reg))
  66.      (eval :scs (descriptor-reg)))
  67.   (:vop-var vop)
  68.   (:generator 10
  69.     (store-symbol-value catch lisp::*current-catch-block*)
  70.     (store-symbol-value eval lisp::*eval-stack-top*)
  71.     (let ((cur-nfp (current-nfp-tn vop)))
  72.       (when cur-nfp
  73.     (move cur-nfp nfp)))
  74.     (move nsp-tn nsp)))
  75.  
  76. (define-vop (current-stack-pointer)
  77.   (:results (res :scs (any-reg descriptor-reg)))
  78.   (:generator 1
  79.     (move res csp-tn)))
  80.  
  81. (define-vop (current-binding-pointer)
  82.   (:results (res :scs (any-reg descriptor-reg)))
  83.   (:generator 1
  84.     (move res bsp-tn)))
  85.  
  86.  
  87.  
  88. ;;;; Unwind block hackery:
  89.  
  90. ;;; Compute the address of the catch block from its TN, then store into the
  91. ;;; block the current Fp, Env, Unwind-Protect, and the entry PC.
  92. ;;;
  93. (define-vop (make-unwind-block)
  94.   (:args (tn))
  95.   (:info entry-label)
  96.   (:results (block :scs (any-reg)))
  97.   (:temporary (:scs (descriptor-reg)) temp)
  98.   (:temporary (:scs (non-descriptor-reg)) ndescr)
  99.   (:generator 22
  100.     (inst add block cfp-tn (* (tn-offset tn) vm:word-bytes))
  101.     (load-symbol-value temp lisp::*current-unwind-protect-block*)
  102.     (storew temp block vm:unwind-block-current-uwp-slot)
  103.     (storew cfp-tn block vm:unwind-block-current-cont-slot)
  104.     (storew code-tn block vm:unwind-block-current-code-slot)
  105.     (inst compute-lra-from-code temp code-tn entry-label ndescr)
  106.     (storew temp block vm:catch-block-entry-pc-slot)))
  107.  
  108.  
  109. ;;; Like Make-Unwind-Block, except that we also store in the specified tag, and
  110. ;;; link the block into the Current-Catch list.
  111. ;;;
  112. (define-vop (make-catch-block)
  113.   (:args (tn)
  114.      (tag :scs (descriptor-reg)))
  115.   (:info entry-label)
  116.   (:results (block :scs (any-reg)))
  117.   (:temporary (:scs (descriptor-reg)) temp)
  118.   (:temporary (:scs (descriptor-reg) :target block :to (:result 0)) result)
  119.   (:temporary (:scs (non-descriptor-reg)) ndescr)
  120.   (:generator 44
  121.     (inst add result cfp-tn (* (tn-offset tn) vm:word-bytes))
  122.     (load-symbol-value temp lisp::*current-unwind-protect-block*)
  123.     (storew temp result vm:catch-block-current-uwp-slot)
  124.     (storew cfp-tn result vm:catch-block-current-cont-slot)
  125.     (storew code-tn result vm:catch-block-current-code-slot)
  126.     (inst compute-lra-from-code temp code-tn entry-label ndescr)
  127.     (storew temp result vm:catch-block-entry-pc-slot)
  128.  
  129.     (storew tag result vm:catch-block-tag-slot)
  130.     (load-symbol-value temp lisp::*current-catch-block*)
  131.     (storew temp result vm:catch-block-previous-catch-slot)
  132.     (store-symbol-value result lisp::*current-catch-block*)
  133.  
  134.     (move block result)))
  135.  
  136.  
  137. ;;; Just set the current unwind-protect to TN's address.  This instantiates an
  138. ;;; unwind block as an unwind-protect.
  139. ;;;
  140. (define-vop (set-unwind-protect)
  141.   (:args (tn))
  142.   (:temporary (:scs (descriptor-reg)) new-uwp)
  143.   (:generator 7
  144.     (inst add new-uwp cfp-tn (* (tn-offset tn) vm:word-bytes))
  145.     (store-symbol-value new-uwp lisp::*current-unwind-protect-block*)))
  146.  
  147.  
  148. (define-vop (unlink-catch-block)
  149.   (:temporary (:scs (any-reg)) block)
  150.   (:policy :fast-safe)
  151.   (:translate %catch-breakup)
  152.   (:generator 17
  153.     (load-symbol-value block lisp::*current-catch-block*)
  154.     (loadw block block vm:catch-block-previous-catch-slot)
  155.     (store-symbol-value block lisp::*current-catch-block*)))
  156.  
  157. (define-vop (unlink-unwind-protect)
  158.   (:temporary (:scs (any-reg)) block)
  159.   (:policy :fast-safe)
  160.   (:translate %unwind-protect-breakup)
  161.   (:generator 17
  162.     (load-symbol-value block lisp::*current-unwind-protect-block*)
  163.     (loadw block block vm:unwind-block-current-uwp-slot)
  164.     (store-symbol-value block lisp::*current-unwind-protect-block*)))
  165.  
  166.  
  167. ;;;; NLX entry VOPs:
  168.  
  169.  
  170. (define-vop (nlx-entry)
  171.   (:args (sp) ; Note: we can't list an sc-restriction, 'cause any load vops
  172.           ; would be inserted before the LRA.
  173.      (start)
  174.      (count))
  175.   (:results (values :more t))
  176.   (:temporary (:scs (descriptor-reg)) move-temp)
  177.   (:info label nvals)
  178.   (:save-p :force-to-stack)
  179.   (:generator 30
  180.     (emit-return-pc label)
  181.     (cond ((zerop nvals))
  182.       ((= nvals 1)
  183.        (let ((no-values (gen-label)))
  184.          (inst cmp count)
  185.          (inst b :eq no-values)
  186.          (move (tn-ref-tn values) null-tn)
  187.          (loadw (tn-ref-tn values) start)
  188.          (emit-label no-values)))
  189.       (t
  190.        (collect ((defaults))
  191.          (inst subcc count (fixnum 1))
  192.          (do ((i 0 (1+ i))
  193.           (tn-ref values (tn-ref-across tn-ref)))
  194.          ((null tn-ref))
  195.            (let ((default-lab (gen-label))
  196.              (tn (tn-ref-tn tn-ref)))
  197.          (defaults (cons default-lab tn))
  198.          
  199.          (inst b :lt default-lab)
  200.          (inst subcc count (fixnum 1))
  201.          (sc-case tn
  202.               ((descriptor-reg any-reg)
  203.                (loadw tn start i))
  204.               (control-stack
  205.                (loadw move-temp start i)
  206.                (store-stack-tn tn move-temp)))))
  207.          
  208.          (let ((defaulting-done (gen-label)))
  209.            
  210.            (emit-label defaulting-done)
  211.            
  212.            (assemble (*elsewhere*)
  213.          (dolist (def (defaults))
  214.            (emit-label (car def))
  215.            (let ((tn (cdr def)))
  216.              (sc-case tn
  217.                   ((descriptor-reg any-reg)
  218.                    (move tn null-tn))
  219.                   (control-stack
  220.                    (store-stack-tn tn null-tn)))))
  221.          (inst b defaulting-done)
  222.          (inst nop))))))
  223.     (load-stack-tn csp-tn sp)))
  224.  
  225.  
  226. (define-vop (nlx-entry-multiple)
  227.   (:args (top :target result) (src) (count))
  228.   ;; Again, no SC restrictions for the args, 'cause the loading would
  229.   ;; happen before the entry label.
  230.   (:info label)
  231.   (:temporary (:scs (any-reg)) dst)
  232.   (:temporary (:scs (descriptor-reg)) temp)
  233.   (:results (result :scs (any-reg) :from (:argument 0))
  234.         (num :scs (any-reg) :from (:argument 0)))
  235.   (:save-p :force-to-stack)
  236.   (:generator 30
  237.     (emit-return-pc label)
  238.     (let ((loop (gen-label))
  239.       (done (gen-label)))
  240.  
  241.       ;; Setup results, and test for the zero value case.
  242.       (load-stack-tn result top)
  243.       (inst cmp count)
  244.       (inst b :eq done)
  245.       (inst li num 0)
  246.  
  247.       ;; Compute dst as one slot down from result, because we inc the index
  248.       ;; before we use it.
  249.       (inst sub dst result 4)
  250.  
  251.       ;; Copy stuff down the stack.
  252.       (emit-label loop)
  253.       (inst ld temp src num)
  254.       (inst add num (fixnum 1))
  255.       (inst cmp num count)
  256.       (inst b :ne loop)
  257.       (inst st temp dst num)
  258.  
  259.       ;; Reset the CSP.
  260.       (emit-label done)
  261.       (inst add csp-tn result num))))
  262.  
  263.  
  264. ;;; This VOP is just to force the TNs used in the cleanup onto the stack.
  265. ;;;
  266. (define-vop (uwp-entry)
  267.   (:info label)
  268.   (:save-p :force-to-stack)
  269.   (:results (block) (start) (count))
  270.   (:ignore block start count)
  271.   (:generator 0
  272.     (emit-return-pc label)))
  273.  
  274.