Changeset 13154
- Timestamp:
- 01/17/11 21:19:33 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/unsafe-p-removal/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r13153 r13154 668 668 669 669 (declaim (special *saved-operands* *operand-representations*)) 670 (defmacro with-operand-accumulation ((&body argument-buildup-body) 671 &body funcall-body) 670 (defmacro with-operand-accumulation ((&body argument-accumulation-body) 671 &body call-body) 672 "Macro used to operand-stack-safely collect arguments in the 673 `argument-accumulation-body' to be available on the stack upon entry of the 674 `call-body'. The argument-accumulation-body code may not assume arguments 675 are actually on the stack while accumulating. 676 677 This macro closes over a code-generating block. Operands can be collected 678 using the `accumulate-operand', `compile-operand', `emit-variable-operand' 679 and `emit-load-externalized-object-operand'." 672 680 `(let (*saved-operands* 673 674 681 *operand-representations* 682 (*register* *register*) 675 683 ) ;; hmm can we do this?? either body 676 684 ;; could allocate registers ... 677 ,@argument- buildup-body685 ,@argument-accumulation-body 678 686 (load-saved-operands) 679 687 ,@funcall-body)) 688 689 (defmacro accumulate-operand ((representation &key unsafe-p) 690 &body body) 691 "Macro used to collect a single operand. 692 693 This macro closes over a code-generating block. The generated code should 694 leave a single operand on the stack, with representation `representation'. 695 The value `unsafe-p', when provided, is an expression evaluated at run time 696 to indicate if the body is opstack unsafe." 697 `(progn 698 ,@(when unsafe-p 699 `((when ,unsafe-p 700 (save-existing-operands)))) 701 ,@body 702 (save-operand ,representation))) 680 703 681 704 (defun load-saved-operands () … … 689 712 "If any operands have been compiled to the stack, 690 713 save them in registers." 691 (dolist (representation *operand-representations*) 714 (when (null *saved-operands*) 715 (dolist (representation *operand-representations*) 716 (let ((register (allocate-register))) 717 (push register *saved-operands*) 718 (emit-move-from-stack register representation))) 719 720 (setf *saved-operands* (nreverse *saved-operands*)))) 721 722 (defun save-operand (representation) 723 "Saves an operand from the stack (with `representation') to 724 a register and updates associated operand collection variables." 725 (push representation *operand-representations*) 726 727 (when *saved-operands* 692 728 (let ((register (allocate-register))) 693 729 (push register *saved-operands*) 694 (emit-move-from-stack register representation))) 695 696 (setf *saved-operands* (nreverse *saved-operands*))) 730 (emit-move-from-stack register representation)))) 697 731 698 732 (defun compile-operand (form representation &optional cast) 699 "Compiles `form ` into `representation`, storing the resulting value733 "Compiles `form' into `representation', storing the resulting value 700 734 on the operand stack, if it's safe to do so. Otherwise stores the value 701 735 in a register" 702 736 (let ((unsafe (or *saved-operands* 703 704 737 (some-nested-block #'node-opstack-unsafe-p 738 (find-enclosed-blocks form))))) 705 739 (when (and unsafe (null *saved-operands*)) 706 740 (save-existing-operands)) 707 741 708 742 (compile-form form 'stack representation) 709 743 (when cast … … 711 745 (when unsafe 712 746 (let ((register (allocate-register))) 713 714 715 747 (push register *saved-operands*) 748 (emit-move-from-stack register representation))) 749 716 750 (push representation *operand-representations*))) 717 751 … … 722 756 (cond 723 757 ((and *saved-operands* 724 758 (variable-register variable)) 725 759 ;; we're in 'safe mode' and the variable is in a register, 726 760 ;; instead of binding a new register, just load the existing one … … 730 764 (when *saved-operands* ;; safe-mode 731 765 (let ((register (allocate-register))) 732 (push register *saved-operands*) 733 (assert (null (variable-representation variable))) 734 (emit 'astore register)))))) 766 (push register *saved-operands*) 767 (emit-move-from-stack register (variable-representation variable))))))) 735 768 736 769 (defun emit-thread-operand () … … 739 772 (when *saved-operands* 740 773 (let ((register (allocate-register))) 741 (push register *saved-operands*) 742 (emit 'astore register)))) 743 774 (push register *saved-operands*) 775 (emit 'astore register)))) 744 776 745 777 (defun emit-load-externalized-object-operand (object) … … 748 780 (when *saved-operands* ;; safe-mode 749 781 (let ((register (allocate-register))) 750 751 782 (push register *saved-operands*) 783 (emit 'astore register)))) 752 784 753 785 (defknown emit-unbox-fixnum () t) … … 1929 1961 (setf must-clear-values t))))) 1930 1962 (t 1931 (let (;(*register* *register*) ;; ### FIXME: this doesn't work, but why not?1963 (let* ((*register* *register*) ;; ### FIXME: this doesn't work, but why not? 1932 1964 (array-register (allocate-register)) 1933 1965 saved-stack)
Note: See TracChangeset
for help on using the changeset viewer.