Changeset 13025
- Timestamp:
- 11/16/10 19:40:03 (13 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r13022 r13025 525 525 (when (fixnum-type-p declared-type) 'FIXNUM) 526 526 (find-if #'(lambda (type) (eq type declared-type)) 527 528 (find-if #'(lambda (type) (subtypep declared-type type)) 529 527 '(SYMBOL CHARACTER CONS HASH-TABLE)) 528 (find-if #'(lambda (type) (subtypep declared-type type)) 529 '(STRING VECTOR STREAM))))) 530 530 531 531 532 532 (defknown generate-type-check-for-variable (t) t) 533 533 (defun generate-type-check-for-variable (variable) 534 (let ((type-to-use 535 534 (let ((type-to-use 535 (find-type-for-type-check (variable-declared-type variable)))) 536 536 (when type-to-use 537 537 (generate-instanceof-type-check-for-variable variable type-to-use)))) … … 641 641 (defun compile-forms-and-maybe-emit-clear-values (&rest forms-and-compile-args) 642 642 (let ((forms-for-emit-clear 643 644 645 643 (loop for (form arg1 arg2) on forms-and-compile-args by #'cdddr 644 do (compile-form form arg1 arg2) 645 collecting form))) 646 646 (apply #'maybe-emit-clear-values forms-for-emit-clear))) 647 647 … … 749 749 (args (cdr form)) 750 750 (ok (if minimum 751 752 751 (>= (length args) n) 752 (= (length args) n)))) 753 753 (declare (type boolean ok)) 754 754 (unless ok … … 796 796 (defun make-constructor (class) 797 797 (let* ((*compiler-debug* nil) 798 (method (make-method :constructor :void nil 799 :flags '(:public))) 800 ;; We don't normally need to see debugging output for constructors. 798 801 (super (class-file-superclass class)) 799 802 (lambda-name (abcl-class-file-lambda-name class)) 800 803 (args (abcl-class-file-lambda-list class)) 801 ;; We don't normally need to see debugging output for constructors.802 (method (make-method :constructor :void nil803 :flags '(:public)))804 (code (method-add-code method))805 804 req-params-register 806 805 opt-params-register … … 808 807 rest-p 809 808 keys-p 810 more-keys-p 811 (*code* ()) 812 (*current-code-attribute* code)) 813 (setf (code-max-locals code) 1) 814 (unless (eq super +lisp-compiled-primitive+) 815 (multiple-value-bind 816 (req opt key key-p rest 817 allow-other-keys-p) 818 (parse-lambda-list args) 819 (setf rest-p rest 820 more-keys-p allow-other-keys-p 821 keys-p key-p) 822 (macrolet 823 ((parameters-to-array ((param params register) &body body) 824 (let ((count-sym (gensym))) 825 `(progn 826 (emit-push-constant-int (length ,params)) 827 (emit-anewarray +lisp-closure-parameter+) 828 (astore (setf ,register (code-max-locals code))) 829 (incf (code-max-locals code)) 830 (do* ((,count-sym 0 (1+ ,count-sym)) 831 (,params ,params (cdr ,params)) 832 (,param (car ,params) (car ,params))) 833 ((endp ,params)) 834 (declare (ignorable ,param)) 835 (aload ,register) 836 (emit-push-constant-int ,count-sym) 837 (emit-new +lisp-closure-parameter+) 838 (emit 'dup) 839 ,@body 840 (emit 'aastore)))))) 841 ;; process required args 842 (parameters-to-array (ignore req req-params-register) 843 (emit-push-t) ;; we don't need the actual symbol 844 (emit-invokespecial-init +lisp-closure-parameter+ 845 (list +lisp-symbol+))) 846 847 (parameters-to-array (param opt opt-params-register) 848 (emit-push-t) ;; we don't need the actual variable-symbol 849 (emit-read-from-string (second param)) ;; initform 850 (if (null (third param)) ;; supplied-p 851 (emit-push-nil) 852 (emit-push-t)) ;; we don't need the actual supplied-p symbol 853 (emit-getstatic +lisp-closure+ "OPTIONAL" :int) 854 (emit-invokespecial-init +lisp-closure-parameter+ 855 (list +lisp-symbol+ +lisp-object+ 856 +lisp-object+ :int))) 857 858 (parameters-to-array (param key key-params-register) 859 (let ((keyword (fourth param))) 860 (if (keywordp keyword) 861 (progn 862 (emit 'ldc (pool-string (symbol-name keyword))) 863 (emit-invokestatic +lisp+ "internKeyword" 864 (list +java-string+) +lisp-symbol+)) 865 ;; symbol is not really a keyword; yes, that's allowed! 866 (progn 867 (emit 'ldc (pool-string (symbol-name keyword))) 868 (emit 'ldc (pool-string 869 (package-name (symbol-package keyword)))) 870 (emit-invokestatic +lisp+ "internInPackage" 871 (list +java-string+ +java-string+) 872 +lisp-symbol+)))) 873 (emit-push-t) ;; we don't need the actual variable-symbol 874 (emit-read-from-string (second (car key))) 875 (if (null (third param)) 876 (emit-push-nil) 877 (emit-push-t)) ;; we don't need the actual supplied-p symbol 878 (emit-invokespecial-init +lisp-closure-parameter+ 879 (list +lisp-symbol+ +lisp-symbol+ 880 +lisp-object+ +lisp-object+)))))) 881 (aload 0) ;; this 882 (cond ((eq super +lisp-compiled-primitive+) 883 (emit-constructor-lambda-name lambda-name) 884 (emit-constructor-lambda-list args) 885 (emit-invokespecial-init super (lisp-object-arg-types 2))) 886 ((equal super +lisp-compiled-closure+) ;;### only needs EQ when SUPER is guaranteed to be CLASS-NAME 887 (aload req-params-register) 888 (aload opt-params-register) 889 (aload key-params-register) 890 (if keys-p 891 (emit-push-t) 892 (emit-push-nil-symbol)) 893 (if rest-p 894 (emit-push-t) 895 (emit-push-nil-symbol)) 896 (if more-keys-p 897 (emit-push-t) 898 (emit-push-nil-symbol)) 899 (emit-invokespecial-init super 900 (list +lisp-closure-parameter-array+ 901 +lisp-closure-parameter-array+ 902 +lisp-closure-parameter-array+ 903 +lisp-symbol+ 904 +lisp-symbol+ +lisp-symbol+))) 905 (t 906 (aver nil))) 907 (setf *code* (append *static-code* *code*)) 908 (emit 'return) 909 (setf (code-code code) *code*) 809 more-keys-p) 810 (with-code-to-method (class method) 811 (allocate-register) 812 (unless (eq super +lisp-compiled-primitive+) 813 (multiple-value-bind 814 (req opt key key-p rest 815 allow-other-keys-p) 816 (parse-lambda-list args) 817 (setf rest-p rest 818 more-keys-p allow-other-keys-p 819 keys-p key-p) 820 (macrolet 821 ((parameters-to-array ((param params register) &body body) 822 (let ((count-sym (gensym))) 823 `(progn 824 (emit-push-constant-int (length ,params)) 825 (emit-anewarray +lisp-closure-parameter+) 826 (astore (setf ,register *registers-allocated*)) 827 (allocate-register) 828 (do* ((,count-sym 0 (1+ ,count-sym)) 829 (,params ,params (cdr ,params)) 830 (,param (car ,params) (car ,params))) 831 ((endp ,params)) 832 (declare (ignorable ,param)) 833 (aload ,register) 834 (emit-push-constant-int ,count-sym) 835 (emit-new +lisp-closure-parameter+) 836 (emit 'dup) 837 ,@body 838 (emit 'aastore)))))) 839 ;; process required args 840 (parameters-to-array (ignore req req-params-register) 841 (emit-push-t) ;; we don't need the actual symbol 842 (emit-invokespecial-init +lisp-closure-parameter+ 843 (list +lisp-symbol+))) 844 845 (parameters-to-array (param opt opt-params-register) 846 (emit-push-t) ;; we don't need the actual variable-symbol 847 (emit-read-from-string (second param)) ;; initform 848 (if (null (third param)) ;; supplied-p 849 (emit-push-nil) 850 (emit-push-t)) ;; we don't need the actual supplied-p symbol 851 (emit-getstatic +lisp-closure+ "OPTIONAL" :int) 852 (emit-invokespecial-init +lisp-closure-parameter+ 853 (list +lisp-symbol+ +lisp-object+ 854 +lisp-object+ :int))) 855 856 (parameters-to-array (param key key-params-register) 857 (let ((keyword (fourth param))) 858 (if (keywordp keyword) 859 (progn 860 (emit 'ldc (pool-string (symbol-name keyword))) 861 (emit-invokestatic +lisp+ "internKeyword" 862 (list +java-string+) +lisp-symbol+)) 863 ;; symbol is not really a keyword; yes, that's allowed! 864 (progn 865 (emit 'ldc (pool-string (symbol-name keyword))) 866 (emit 'ldc (pool-string 867 (package-name (symbol-package keyword)))) 868 (emit-invokestatic +lisp+ "internInPackage" 869 (list +java-string+ +java-string+) 870 +lisp-symbol+)))) 871 (emit-push-t) ;; we don't need the actual variable-symbol 872 (emit-read-from-string (second (car key))) 873 (if (null (third param)) 874 (emit-push-nil) 875 (emit-push-t)) ;; we don't need the actual supplied-p symbol 876 (emit-invokespecial-init +lisp-closure-parameter+ 877 (list +lisp-symbol+ +lisp-symbol+ 878 +lisp-object+ +lisp-object+)))))) 879 (aload 0) ;; this 880 (cond ((eq super +lisp-compiled-primitive+) 881 (emit-constructor-lambda-name lambda-name) 882 (emit-constructor-lambda-list args) 883 (emit-invokespecial-init super (lisp-object-arg-types 2))) 884 ((equal super +lisp-compiled-closure+) ;;### only needs EQ when SUPER is guaranteed to be CLASS-NAME 885 (aload req-params-register) 886 (aload opt-params-register) 887 (aload key-params-register) 888 (if keys-p 889 (emit-push-t) 890 (emit-push-nil-symbol)) 891 (if rest-p 892 (emit-push-t) 893 (emit-push-nil-symbol)) 894 (if more-keys-p 895 (emit-push-t) 896 (emit-push-nil-symbol)) 897 (emit-invokespecial-init super 898 (list +lisp-closure-parameter-array+ 899 +lisp-closure-parameter-array+ 900 +lisp-closure-parameter-array+ 901 +lisp-symbol+ 902 +lisp-symbol+ +lisp-symbol+))) 903 (t 904 (sys::%format t "unhandled superclass ~A for ~A~%" 905 super 906 (abcl-class-file-class-name class)) 907 (aver nil)))) 910 908 method)) 911 909 910 (defun make-static-initializer (class) 911 (let ((*compiler-debug* nil) 912 (method (make-method :static-initializer 913 :void nil :flags '(:public :static)))) 914 ;; We don't normally need to see debugging output for <clinit>. 915 (with-code-to-method (class method) 916 (setf (code-max-locals *current-code-attribute*) 0) 917 (emit 'return) 918 method))) 912 919 913 920 (defvar *source-line-number* nil) … … 919 926 The compiler calls this function to indicate it doesn't want to 920 927 extend the class any further." 921 (class-add-method class (make-constructor class)) 928 (with-code-to-method (class (abcl-class-file-constructor class)) 929 (emit 'return)) 922 930 (finalize-class-file class) 923 931 (write-class-file class stream)) … … 951 959 952 960 (defmacro declare-with-hashtable (declared-item hashtable hashtable-var 953 961 item-var &body body) 954 962 `(let* ((,hashtable-var ,hashtable) 955 963 (,item-var (gethash1 ,declared-item ,hashtable-var))) 956 964 (declare (type hash-table ,hashtable-var)) 957 965 (unless ,item-var … … 1087 1095 on the equality indicator in the `serialization-table'. 1088 1096 1089 Code to restore the serialized object is inserted into `*code'or1090 `*static-code*'if `*declare-inline*' is non-nil.1097 Code to restore the serialized object is inserted into the current method or 1098 the constructor if `*declare-inline*' is non-nil. 1091 1099 " 1092 1100 ;; TODO: rewrite to become EMIT-LOAD-EXTERNALIZED-OBJECT which … … 1118 1126 (cond 1119 1127 ((not *file-compilation*) 1120 (let ((*code* *static-code*)) 1128 (with-code-to-method 1129 (*class-file* (abcl-class-file-constructor *class-file*)) 1121 1130 (remember field-name object) 1122 1131 (emit 'ldc (pool-string field-name)) … … 1125 1134 (when (not (eq field-type +lisp-object+)) 1126 1135 (emit-checkcast field-type)) 1127 (emit-putstatic *this-class* field-name field-type) 1128 (setf *static-code* *code*))) 1136 (emit-putstatic *this-class* field-name field-type))) 1129 1137 (*declare-inline* 1130 1138 (funcall dispatch-fn object) 1131 1139 (emit-putstatic *this-class* field-name field-type)) 1132 1140 (t 1133 (let ((*code* *static-code*)) 1141 (with-code-to-method 1142 (*class-file* (abcl-class-file-constructor *class-file*)) 1134 1143 (funcall dispatch-fn object) 1135 (emit-putstatic *this-class* field-name field-type) 1136 (setf *static-code* *code*)))) 1144 (emit-putstatic *this-class* field-name field-type)))) 1137 1145 1138 1146 (emit-getstatic *this-class* field-name field-type) … … 1164 1172 (declare-object symbol)) 1165 1173 class *this-class*)) 1166 (let (saved-code) 1167 (let ((*code* (if *declare-inline* *code* *static-code*))) 1168 (if (eq class *this-class*) 1169 (progn ;; generated by the DECLARE-OBJECT*'s above 1170 (emit-getstatic class name +lisp-object+) 1171 (emit-checkcast +lisp-symbol+)) 1172 (emit-getstatic class name +lisp-symbol+)) 1173 (emit-invokevirtual +lisp-symbol+ 1174 (if setf 1175 "getSymbolSetfFunctionOrDie" 1176 "getSymbolFunctionOrDie") 1177 nil +lisp-object+) 1178 ;; make sure we're not cacheing a proxied function 1179 ;; (AutoloadedFunctionProxy) by allowing it to resolve itself 1180 (emit-invokevirtual +lisp-object+ 1181 "resolve" nil +lisp-object+) 1182 (emit-putstatic *this-class* f +lisp-object+) 1183 (if *declare-inline* 1184 (setf saved-code *code*) 1185 (setf *static-code* *code*)) 1186 (setf (gethash symbol ht) f)) 1187 (when *declare-inline* 1188 (setf *code* saved-code)) 1189 f)))) 1174 (with-code-to-method (*class-file* 1175 (if *declare-inline* *method* 1176 (abcl-class-file-constructor *class-file*))) 1177 (if (eq class *this-class*) 1178 (progn ;; generated by the DECLARE-OBJECT*'s above 1179 (emit-getstatic class name +lisp-object+) 1180 (emit-checkcast +lisp-symbol+)) 1181 (emit-getstatic class name +lisp-symbol+)) 1182 (emit-invokevirtual +lisp-symbol+ 1183 (if setf 1184 "getSymbolSetfFunctionOrDie" 1185 "getSymbolFunctionOrDie") 1186 nil +lisp-object+) 1187 ;; make sure we're not cacheing a proxied function 1188 ;; (AutoloadedFunctionProxy) by allowing it to resolve itself 1189 (emit-invokevirtual +lisp-object+ 1190 "resolve" nil +lisp-object+) 1191 (emit-putstatic *this-class* f +lisp-object+) 1192 (setf (gethash symbol ht) f)) 1193 f))) 1190 1194 1191 1195 (defknown declare-setf-function (name) string) … … 1199 1203 local-function *declared-functions* ht g 1200 1204 (setf g (symbol-name (gensym "LFUN"))) 1201 (let *((class-name (abcl-class-file-class-name1202 (local-function-class-file local-function)))1203 (*code* *static-code*))1204 ;; fixme *declare-inline*1205 (declare-field g +lisp-object+)1206 (emit-new class-name)1207 (emit 'dup)1208 (emit-invokespecial-init class-name '())1209 (emit-putstatic *this-class* g +lisp-object+)1210 (setf *static-code* *code*)1211 (setf (gethash local-function ht) g))))1205 (let ((class-name (abcl-class-file-class-name 1206 (local-function-class-file local-function)))) 1207 (with-code-to-method 1208 (*class-file* (abcl-class-file-constructor *class-file*)) 1209 ;; fixme *declare-inline* 1210 (declare-field g +lisp-object+) 1211 (emit-new class-name) 1212 (emit 'dup) 1213 (emit-invokespecial-init class-name '()) 1214 (emit-putstatic *this-class* g +lisp-object+) 1215 (setf (gethash local-function ht) g))))) 1212 1216 1213 1217 … … 1222 1226 ;; EMIT-LOAD-EXTERNALIZED-OBJECT, which serializes *and* 1223 1227 ;; emits the right loading code (not just de-serialization anymore) 1224 (let (saved-code 1225 (g (symbol-name (gensym "OBJSTR")))) 1226 (let* ((s (with-output-to-string (stream) (dump-form obj stream))) 1227 (*code* (if *declare-inline* *code* *static-code*))) 1228 (let ((g (symbol-name (gensym "OBJSTR"))) 1229 (s (with-output-to-string (stream) (dump-form obj stream)))) 1230 (with-code-to-method 1231 (*class-file* 1232 (if *declare-inline* *method* 1233 (abcl-class-file-constructor *class-file*))) 1228 1234 ;; strings may contain evaluated bits which may depend on 1229 1235 ;; previous statements … … 1232 1238 (emit-invokestatic +lisp+ "readObjectFromString" 1233 1239 (list +java-string+) +lisp-object+) 1234 (emit-putstatic *this-class* g +lisp-object+) 1235 (if *declare-inline* 1236 (setf saved-code *code*) 1237 (setf *static-code* *code*))) 1238 (when *declare-inline* 1239 (setf *code* saved-code)) 1240 (emit-putstatic *this-class* g +lisp-object+)) 1240 1241 g)) 1241 1242 1242 1243 (defun declare-load-time-value (obj) 1243 1244 (let ((g (symbol-name (gensym "LTV"))) 1244 saved-code) 1245 (let* ((s (with-output-to-string (stream) (dump-form obj stream))) 1246 (*code* (if *declare-inline* *code* *static-code*))) 1247 ;; The readObjectFromString call may require evaluation of 1248 ;; lisp code in the string (think #.() syntax), of which the outcome 1249 ;; may depend on something which was declared inline 1250 (declare-field g +lisp-object+) 1251 (emit 'ldc (pool-string s)) 1252 (emit-invokestatic +lisp+ "readObjectFromString" 1253 (list +java-string+) +lisp-object+) 1254 (emit-invokestatic +lisp+ "loadTimeValue" 1255 (lisp-object-arg-types 1) +lisp-object+) 1256 (emit-putstatic *this-class* g +lisp-object+) 1257 (if *declare-inline* 1258 (setf saved-code *code*) 1259 (setf *static-code* *code*))) 1260 (when *declare-inline* 1261 (setf *code* saved-code)) 1262 g)) 1245 (s (with-output-to-string (stream) (dump-form obj stream)))) 1246 (with-code-to-method 1247 (*class-file* 1248 (if *declare-inline* *method* 1249 (abcl-class-file-constructor *class-file*))) 1250 ;; The readObjectFromString call may require evaluation of 1251 ;; lisp code in the string (think #.() syntax), of which the outcome 1252 ;; may depend on something which was declared inline 1253 (declare-field g +lisp-object+) 1254 (emit 'ldc (pool-string s)) 1255 (emit-invokestatic +lisp+ "readObjectFromString" 1256 (list +java-string+) +lisp-object+) 1257 (emit-invokestatic +lisp+ "loadTimeValue" 1258 (lisp-object-arg-types 1) +lisp-object+) 1259 (emit-putstatic *this-class* g +lisp-object+)) 1260 g)) 1263 1261 1264 1262 (declaim (ftype (function (t) string) declare-object)) … … 1271 1269 ;; fixme *declare-inline*? 1272 1270 (remember g obj) 1273 (let* ((*code* *static-code*)) 1271 (with-code-to-method 1272 (*class-file* (abcl-class-file-constructor *class-file*)) 1274 1273 (declare-field g +lisp-object+) 1275 1274 (emit 'ldc (pool-string g)) 1276 1275 (emit-invokestatic +lisp+ "recall" 1277 1276 (list +java-string+) +lisp-object+) 1278 (emit-putstatic *this-class* g +lisp-object+) 1279 (setf *static-code* *code*) 1280 g))) 1277 (emit-putstatic *this-class* g +lisp-object+)) 1278 g)) 1281 1279 1282 1280 (defknown compile-constant (t t t) t) … … 1406 1404 (defmacro define-inlined-function (name params preamble-and-test &body body) 1407 1405 (let* ((test (second preamble-and-test)) 1408 1409 1406 (preamble (and test (first preamble-and-test))) 1407 (test (or test (first preamble-and-test)))) 1410 1408 `(defun ,name ,params 1411 1409 ,preamble 1412 1410 (unless ,test 1413 1414 1411 (compile-function-call ,@params) 1412 (return-from ,name)) 1415 1413 ,@body))) 1416 1414 … … 1424 1422 (cond ((and boxed-method-name unboxed-method-name) 1425 1423 (let ((arg (cadr form))) 1426 1424 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 1427 1425 (ecase representation 1428 1426 (:boolean … … 1462 1460 (let ((s (gethash1 op (the hash-table *unary-operators*)))) 1463 1461 (cond (s 1464 1462 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 1465 1463 (emit-invoke-method s target representation) 1466 1464 t) … … 1498 1496 (arg2 (cadr args))) 1499 1497 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 1500 1498 arg2 'stack nil) 1501 1499 (emit-invokevirtual +lisp-object+ op 1502 1500 (lisp-object-arg-types 1) +lisp-object+) 1503 1501 (fix-boxing representation nil) 1504 1502 (emit-move-from-stack target representation))) … … 1551 1549 (arg2 (%cadr args))) 1552 1550 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 1553 1551 arg2 'stack nil) 1554 1552 (let ((LABEL1 (gensym)) 1555 1553 (LABEL2 (gensym))) … … 1577 1575 (cond ((and (fixnum-type-p type1) 1578 1576 (fixnum-type-p type2)) 1579 1580 1577 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 1578 arg2 'stack :int) 1581 1579 (let ((label1 (gensym)) 1582 1580 (label2 (gensym))) … … 1588 1586 (label label2))) 1589 1587 ((fixnum-type-p type2) 1590 1591 1592 1588 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 1589 arg2 'stack :int) 1590 (emit-ifne-for-eql representation '(:int))) 1593 1591 ((fixnum-type-p type1) 1594 1595 1592 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 1593 arg2 'stack nil) 1596 1594 (emit 'swap) 1597 1595 (emit-ifne-for-eql representation '(:int))) 1598 1596 ((eq type2 'CHARACTER) 1599 1600 1601 1597 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 1598 arg2 'stack :char) 1599 (emit-ifne-for-eql representation '(:char))) 1602 1600 ((eq type1 'CHARACTER) 1603 1604 1601 (compile-forms-and-maybe-emit-clear-values arg1 'stack :char 1602 arg2 'stack nil) 1605 1603 (emit 'swap) 1606 1604 (emit-ifne-for-eql representation '(:char))) 1607 1605 (t 1608 1609 1606 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 1607 arg2 'stack nil) 1610 1608 (ecase representation 1611 1609 (:boolean … … 1695 1693 (arg2 (second args)) 1696 1694 (arg3 (third args))) 1697 1698 1699 1695 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 1696 arg2 'stack nil 1697 arg3 'stack nil) 1700 1698 (emit-invokestatic +lisp+ "getf" 1701 1699 (lisp-object-arg-types 3) +lisp-object+) … … 2062 2060 (let ((LABEL1 (gensym)) 2063 2061 (LABEL2 (gensym))) 2064 2062 (compile-forms-and-maybe-emit-clear-values 2065 2063 arg1 'stack common-rep 2066 2064 arg2 'stack common-rep) … … 2074 2072 (return-from p2-numeric-comparison)) 2075 2073 ((fixnump arg2) 2076 2074 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 2077 2075 (emit-push-constant-int arg2) 2078 2076 (emit-invokevirtual +lisp-object+ … … 2241 2239 `(let ((,tmpform ,form)) 2242 2240 (when (check-arg-count ,tmpform 1) 2243 2244 2245 2246 2247 2248 2241 (let ((arg (%cadr ,tmpform))) 2242 (cond ((fixnum-type-p (derive-compiler-type arg)) 2243 (compile-forms-and-maybe-emit-clear-values arg 'stack :int) 2244 ,@instructions) 2245 (t 2246 (p2-test-predicate ,tmpform ,predicate)))))))) 2249 2247 2250 2248 (defun p2-test-evenp (form) 2251 2249 (p2-test-integer-predicate form "evenp" 2252 2253 2254 2250 (emit-push-constant-int 1) 2251 (emit 'iand) 2252 'ifne)) 2255 2253 2256 2254 (defun p2-test-oddp (form) 2257 2255 (p2-test-integer-predicate form "oddp" 2258 2259 2260 2256 (emit-push-constant-int 1) 2257 (emit 'iand) 2258 'ifeq)) 2261 2259 2262 2260 (defun p2-test-floatp (form) … … 2271 2269 (arg-type (derive-compiler-type arg))) 2272 2270 (cond ((memq arg-type '(CONS LIST NULL)) 2273 2271 (compile-forms-and-maybe-emit-clear-values arg nil nil) 2274 2272 :consequent) 2275 2273 ((neq arg-type t) 2276 2274 (compile-forms-and-maybe-emit-clear-values arg nil nil) 2277 2275 :alternate) 2278 2276 (t … … 2341 2339 :alternate) 2342 2340 ((eq (derive-compiler-type test-form) 'BOOLEAN) 2343 2341 (compile-forms-and-maybe-emit-clear-values test-form 'stack :boolean) 2344 2342 'ifeq) 2345 2343 (t 2346 2344 (compile-forms-and-maybe-emit-clear-values test-form 'stack nil) 2347 2345 (emit-push-nil) 2348 2346 'if_acmpeq))) … … 2375 2373 (arg2 (%caddr form))) 2376 2374 (compile-forms-and-maybe-emit-clear-values arg1 'stack :char 2377 2375 arg2 'stack :char) 2378 2376 'if_icmpne))) 2379 2377 … … 2383 2381 (arg2 (%caddr form))) 2384 2382 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2385 2383 arg2 'stack nil) 2386 2384 'if_acmpne))) 2387 2385 … … 2412 2410 (type2 (derive-compiler-type arg2))) 2413 2411 (cond ((and (fixnum-type-p type1) (fixnum-type-p type2)) 2414 2415 2412 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 2413 arg2 'stack :int) 2416 2414 'if_icmpne) 2417 2415 ((and (eq type1 'CHARACTER) (eq type2 'CHARACTER)) 2418 2419 2416 (compile-forms-and-maybe-emit-clear-values arg1 'stack :char 2417 arg2 'stack :char) 2420 2418 'if_icmpne) 2421 2419 ((eq type2 'CHARACTER) 2422 2423 2420 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2421 arg2 'stack :char) 2424 2422 (emit-invokevirtual +lisp-object+ "eql" '(:char) :boolean) 2425 2423 'ifeq) 2426 2424 ((eq type1 'CHARACTER) 2427 2428 2425 (compile-forms-and-maybe-emit-clear-values arg1 'stack :char 2426 arg2 'stack nil) 2429 2427 (emit 'swap) 2430 2428 (emit-invokevirtual +lisp-object+ "eql" '(:char) :boolean) 2431 2429 'ifeq) 2432 2430 ((fixnum-type-p type2) 2433 2434 2431 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2432 arg2 'stack :int) 2435 2433 (emit-invokevirtual +lisp-object+ "eql" '(:int) :boolean) 2436 2434 'ifeq) 2437 2435 ((fixnum-type-p type1) 2438 2439 2436 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 2437 arg2 'stack nil) 2440 2438 (emit 'swap) 2441 2439 (emit-invokevirtual +lisp-object+ "eql" '(:int) :boolean) 2442 2440 'ifeq) 2443 2441 (t 2444 2445 2442 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2443 arg2 'stack nil) 2446 2444 (emit-invokevirtual +lisp-object+ "eql" 2447 2445 (lisp-object-arg-types 1) :boolean) … … 2457 2455 (arg2 (%caddr form))) 2458 2456 (cond ((fixnum-type-p (derive-compiler-type arg2)) 2459 2460 2457 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2458 arg2 'stack :int) 2461 2459 (emit-invokevirtual +lisp-object+ 2462 2460 translated-op 2463 2461 '(:int) :boolean)) 2464 2462 (t 2465 2466 2463 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2464 arg2 'stack nil) 2467 2465 (emit-invokevirtual +lisp-object+ 2468 2466 translated-op … … 2475 2473 (arg2 (%caddr form))) 2476 2474 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2477 2475 arg2 'stack nil) 2478 2476 (emit-invokevirtual +lisp-object+ "typep" 2479 2477 (lisp-object-arg-types 1) +lisp-object+) … … 2486 2484 (arg2 (%caddr form))) 2487 2485 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2488 2486 arg2 'stack nil) 2489 2487 (emit-invokestatic +lisp+ "memq" 2490 2488 (lisp-object-arg-types 2) :boolean) … … 2496 2494 (arg2 (%caddr form))) 2497 2495 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2498 2496 arg2 'stack nil) 2499 2497 (emit-invokestatic +lisp+ "memql" 2500 2498 (lisp-object-arg-types 2) :boolean) … … 2511 2509 ((and (fixnum-type-p type1) 2512 2510 (fixnum-type-p type2)) 2513 2514 2511 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 2512 arg2 'stack :int) 2515 2513 'if_icmpeq) 2516 2514 ((fixnum-type-p type2) 2517 2518 2515 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2516 arg2 'stack :int) 2519 2517 (emit-invokevirtual +lisp-object+ "isNotEqualTo" '(:int) :boolean) 2520 2518 'ifeq) … … 2522 2520 ;; FIXME Compile the args in reverse order and avoid the swap if 2523 2521 ;; either arg is a fixnum or a lexical variable. 2524 2525 2522 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 2523 arg2 'stack nil) 2526 2524 (emit 'swap) 2527 2525 (emit-invokevirtual +lisp-object+ "isNotEqualTo" '(:int) :boolean) 2528 2526 'ifeq) 2529 2527 (t 2530 2531 2528 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2529 arg2 'stack nil) 2532 2530 (emit-invokevirtual +lisp-object+ "isNotEqualTo" 2533 2531 (lisp-object-arg-types 1) :boolean) … … 2546 2544 (if (funcall op arg1 arg2) :consequent :alternate)) 2547 2545 ((and (fixnum-type-p type1) (fixnum-type-p type2)) 2548 2549 2546 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 2547 arg2 'stack :int) 2550 2548 (ecase op 2551 2549 (< 'if_icmpge) … … 2555 2553 (= 'if_icmpne))) 2556 2554 ((and (java-long-type-p type1) (java-long-type-p type2)) 2557 2558 2555 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 2556 arg2 'stack :long) 2559 2557 (emit 'lcmp) 2560 2558 (ecase op … … 2565 2563 (= 'ifne))) 2566 2564 ((fixnum-type-p type2) 2567 2568 2565 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2566 arg2 'stack :int) 2569 2567 (emit-invokevirtual +lisp-object+ 2570 2568 (ecase op … … 2579 2577 ;; FIXME We can compile the args in reverse order and avoid 2580 2578 ;; the swap if either arg is a fixnum or a lexical variable. 2581 2582 2579 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 2580 arg2 'stack nil) 2583 2581 (emit 'swap) 2584 2582 (emit-invokevirtual +lisp-object+ … … 2592 2590 'ifeq) 2593 2591 (t 2594 2595 2592 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2593 arg2 'stack nil) 2596 2594 (emit-invokevirtual +lisp-object+ 2597 2595 (ecase op … … 2624 2622 (let ((arg1 (second arg)) 2625 2623 (arg2 (third arg))) 2626 2627 2624 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 2625 arg2 'stack nil) 2628 2626 (emit 'if_acmpeq LABEL1))) 2629 2627 ((eq (derive-compiler-type arg) 'BOOLEAN) 2630 2628 (compile-forms-and-maybe-emit-clear-values arg 'stack :boolean) 2631 2629 (emit 'ifne LABEL1)) 2632 2630 (t 2633 2631 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 2634 2632 (emit-push-nil) 2635 2633 (emit 'if_acmpne LABEL1)))) … … 2656 2654 (t 2657 2655 (dolist (arg args) 2658 (compile-forms-and-maybe-emit-clear-values arg 'stack :boolean) 2659 (emit 'ifeq LABEL1) 2660 ) 2656 (compile-forms-and-maybe-emit-clear-values arg 'stack :boolean) 2657 (emit 'ifeq LABEL1)) 2661 2658 (compile-form consequent target representation) 2662 2659 (emit 'goto LABEL2) … … 2682 2679 (let ((type (derive-compiler-type arg))) 2683 2680 (cond ((eq type 'BOOLEAN) 2684 2681 (compile-forms-and-maybe-emit-clear-values arg 'stack :boolean) 2685 2682 (emit 'ifeq LABEL1)) 2686 2683 (t 2687 2684 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 2688 2685 (emit-push-nil) 2689 2686 (emit 'if_acmpeq LABEL1))))) … … 2708 2705 (compile-form consequent target representation)) 2709 2706 ((equal (derive-compiler-type test) +true-type+) 2710 2707 (compile-forms-and-maybe-emit-clear-values test nil nil) 2711 2708 (compile-form consequent target representation)) 2712 2709 ((and (consp test) (eq (car test) 'OR)) … … 2908 2905 (defun restore-environment-and-make-handler (register label-START) 2909 2906 (let ((label-END (gensym)) 2910 2907 (label-EXIT (gensym))) 2911 2908 (emit 'goto label-EXIT) 2912 2909 (label label-END) … … 2945 2942 (aver (= (length vars) (length variables))) 2946 2943 (cond ((= (length vars) 1) 2947 2944 (compile-forms-and-maybe-emit-clear-values (third form) 'stack nil) 2948 2945 (compile-binding (car variables))) 2949 2946 (t … … 3481 3478 (enclosed-by-environment-setting-block-p tag-block)) 3482 3479 ;; If there's a dynamic environment to restore, do it. 3483 3480 (restore-dynamic-environment (environment-register-to-restore tag-block))) 3484 3481 (maybe-generate-interrupt-check) 3485 3482 (emit 'goto (tag-label tag)) … … 3525 3522 (let ((arg (%cadr form))) 3526 3523 (cond ((null target) 3527 3524 (compile-forms-and-maybe-emit-clear-values arg nil nil)) 3528 3525 (t 3529 3526 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 3530 3527 (emit-instanceof java-class) 3531 3528 (convert-representation :boolean representation) … … 3678 3675 (emit-invoke-method "cadr" target representation)) 3679 3676 (t 3680 3677 (emit-car/cdr arg target representation "car"))))) 3681 3678 3682 3679 (define-inlined-function p2-cdr (form target representation) … … 3693 3690 (arg2 (%cadr args))) 3694 3691 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 3695 3692 arg2 'stack nil)) 3696 3693 (emit-invokespecial-init +lisp-cons+ (lisp-object-arg-types 2)) 3697 3694 (emit-move-from-stack target)) … … 3843 3840 (when (compiland-closure-register parent) 3844 3841 (dformat t "(compiland-closure-register parent) = ~S~%" 3845 3842 (compiland-closure-register parent)) 3846 3843 (emit-checkcast +lisp-compiled-closure+) 3847 3844 (duplicate-closure-array parent) 3848 3845 (emit-invokestatic +lisp+ "makeCompiledClosure" 3849 3850 3846 (list +lisp-object+ +closure-binding-array+) 3847 +lisp-object+))) 3851 3848 (emit-move-to-variable (local-function-variable local-function))) 3852 3849 … … 4003 4000 g +lisp-object+))))) ; Stack: template-function 4004 4001 ((and (member name *functions-defined-in-current-file* :test #'equal) 4005 4002 (not (notinline-p name))) 4006 4003 (emit-getstatic *this-class* 4007 4004 (declare-setf-function name) +lisp-object+) … … 4084 4081 ((and (fixnum-type-p type1) 4085 4082 low2 high2 (<= -31 low2 high2 0)) ; Negative shift. 4086 4087 4083 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4084 arg2 'stack :int) 4088 4085 (emit 'ineg) 4089 4086 (emit 'ishr) … … 4094 4091 (java-long-type-p type1) 4095 4092 (java-long-type-p result-type)) 4096 4097 4093 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 4094 arg2 'stack :int) 4098 4095 (emit 'lshl) 4099 4096 (convert-representation :long representation)) … … 4101 4098 (java-long-type-p type1) 4102 4099 (java-long-type-p result-type)) 4103 4104 4100 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 4101 arg2 'stack :int) 4105 4102 (emit 'ineg) 4106 4103 (emit 'lshr) 4107 4104 (convert-representation :long representation)) 4108 4105 (t 4109 4110 4106 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4107 arg2 'stack :int) 4111 4108 (emit-invokevirtual +lisp-object+ "ash" '(:int) +lisp-object+) 4112 4109 (fix-boxing representation result-type))) … … 4128 4125 (compile-constant (logand arg1 arg2) target representation)) 4129 4126 ((and (integer-type-p type1) (eql arg2 0)) 4130 4127 (compile-forms-and-maybe-emit-clear-values arg1 nil nil) 4131 4128 (compile-constant 0 target representation)) 4132 4129 ((eql (fixnum-constant-value type1) -1) 4133 4134 4130 (compile-forms-and-maybe-emit-clear-values arg1 nil nil 4131 arg2 target representation)) 4135 4132 ((eql (fixnum-constant-value type2) -1) 4136 4137 4133 (compile-forms-and-maybe-emit-clear-values arg1 target representation 4134 arg2 nil nil)) 4138 4135 ((and (fixnum-type-p type1) (fixnum-type-p type2)) 4139 4136 ;; Both arguments are fixnums. 4140 4141 4137 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4138 arg2 'stack :int) 4142 4139 (emit 'iand) 4143 4140 (convert-representation :int representation) … … 4148 4145 (compiler-subtypep type2 'unsigned-byte))) 4149 4146 ;; One of the arguments is a positive fixnum. 4150 4151 4147 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4148 arg2 'stack :int) 4152 4149 (emit 'iand) 4153 4150 (convert-representation :int representation) … … 4155 4152 ((and (java-long-type-p type1) (java-long-type-p type2)) 4156 4153 ;; Both arguments are longs. 4157 4158 4154 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 4155 arg2 'stack :long) 4159 4156 (emit 'land) 4160 4157 (convert-representation :long representation) … … 4165 4162 (compiler-subtypep type2 'unsigned-byte))) 4166 4163 ;; One of the arguments is a positive long. 4167 4168 4164 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 4165 arg2 'stack :long) 4169 4166 (emit 'land) 4170 4167 (convert-representation :long representation) 4171 4168 (emit-move-from-stack target representation)) 4172 4169 ((fixnum-type-p type2) 4173 4174 4170 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4171 arg2 'stack :int) 4175 4172 (emit-invokevirtual +lisp-object+ "LOGAND" '(:int) +lisp-object+) 4176 4173 (fix-boxing representation result-type) … … 4178 4175 ((fixnum-type-p type1) 4179 4176 ;; arg1 is a fixnum, but arg2 is not 4180 4181 4177 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4178 arg2 'stack nil) 4182 4179 ;; swap args 4183 4180 (emit 'swap) … … 4186 4183 (emit-move-from-stack target representation)) 4187 4184 (t 4188 4189 4185 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4186 arg2 'stack nil) 4190 4187 (emit-invokevirtual +lisp-object+ "LOGAND" 4191 4188 (lisp-object-arg-types 1) +lisp-object+) … … 4203 4200 (1 4204 4201 (let ((arg (%car args))) 4205 4202 (compile-forms-and-maybe-emit-clear-values arg target representation))) 4206 4203 (2 4207 4204 (let* ((arg1 (%car args)) … … 4218 4215 result-type (derive-compiler-type form)) 4219 4216 (cond ((and (fixnum-constant-value type1) (fixnum-constant-value type2)) 4220 4221 4217 (compile-forms-and-maybe-emit-clear-values arg1 nil nil 4218 arg2 nil nil) 4222 4219 (compile-constant (logior (fixnum-constant-value type1) 4223 4220 (fixnum-constant-value type2)) 4224 4221 target representation)) 4225 4222 ((and (fixnum-type-p type1) (fixnum-type-p type2)) 4226 4227 4223 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4224 arg2 'stack :int) 4228 4225 (emit 'ior) 4229 4226 (convert-representation :int representation) 4230 4227 (emit-move-from-stack target representation)) 4231 4228 ((and (eql (fixnum-constant-value type1) 0) (< *safety* 3)) 4232 4233 4229 (compile-forms-and-maybe-emit-clear-values arg1 nil nil 4230 arg2 target representation)) 4234 4231 ((and (eql (fixnum-constant-value type2) 0) (< *safety* 3)) 4235 4236 4232 (compile-forms-and-maybe-emit-clear-values arg1 target representation 4233 arg2 nil nil)) 4237 4234 ((or (eq representation :long) 4238 4235 (and (java-long-type-p type1) (java-long-type-p type2))) 4239 4240 4236 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 4237 arg2 'stack :long) 4241 4238 (emit 'lor) 4242 4239 (convert-representation :long representation) 4243 4240 (emit-move-from-stack target representation)) 4244 4241 ((fixnum-type-p type2) 4245 4246 4242 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4243 arg2 'stack :int) 4247 4244 (emit-invokevirtual +lisp-object+ "LOGIOR" '(:int) +lisp-object+) 4248 4245 (fix-boxing representation result-type) … … 4250 4247 ((fixnum-type-p type1) 4251 4248 ;; arg1 is of fixnum type, but arg2 is not 4252 4253 4249 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4250 arg2 'stack nil) 4254 4251 ;; swap args 4255 4252 (emit 'swap) … … 4258 4255 (emit-move-from-stack target representation)) 4259 4256 (t 4260 4261 4257 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4258 arg2 'stack nil) 4262 4259 (emit-invokevirtual +lisp-object+ "LOGIOR" 4263 4260 (lisp-object-arg-types 1) +lisp-object+) … … 4278 4275 (1 4279 4276 (let ((arg (%car args))) 4280 4277 (compile-forms-and-maybe-emit-clear-values arg target representation))) 4281 4278 (2 4282 4279 (let* ((arg1 (%car args)) … … 4293 4290 result-type (derive-compiler-type form)) 4294 4291 (cond ((eq representation :int) 4295 4296 4292 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4293 arg2 'stack :int) 4297 4294 (emit 'ixor)) 4298 4295 ((and (fixnum-type-p type1) (fixnum-type-p type2)) 4299 4300 4296 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4297 arg2 'stack :int) 4301 4298 (emit 'ixor) 4302 4299 (convert-representation :int representation)) 4303 4300 ((and (java-long-type-p type1) (java-long-type-p type2)) 4304 4305 4301 (compile-forms-and-maybe-emit-clear-values arg1 'stack :long 4302 arg2 'stack :long) 4306 4303 (emit 'lxor) 4307 4304 (convert-representation :long representation)) 4308 4305 ((fixnum-type-p type2) 4309 4310 4306 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4307 arg2 'stack :int) 4311 4308 (emit-invokevirtual +lisp-object+ "LOGXOR" '(:int) +lisp-object+) 4312 4309 (fix-boxing representation result-type)) 4313 4310 (t 4314 4315 4311 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4312 arg2 'stack nil) 4316 4313 (emit-invokevirtual +lisp-object+ "LOGXOR" 4317 4314 (lisp-object-arg-types 1) +lisp-object+) … … 4328 4325 (cond ((and (fixnum-type-p (derive-compiler-type form))) 4329 4326 (let ((arg (%cadr form))) 4330 4327 (compile-forms-and-maybe-emit-clear-values arg 'stack :int) 4331 4328 (emit 'iconst_m1) 4332 4329 (emit 'ixor) … … 4335 4332 (t 4336 4333 (let ((arg (%cadr form))) 4337 4334 (compile-forms-and-maybe-emit-clear-values arg 'stack nil)) 4338 4335 (emit-invokevirtual +lisp-object+ "LOGNOT" nil +lisp-object+) 4339 4336 (fix-boxing representation nil) … … 4356 4353 ;; need an unboxed fixnum result. 4357 4354 (cond ((eql size 0) 4358 4359 4360 4355 (compile-forms-and-maybe-emit-clear-values size-arg nil nil 4356 position-arg nil nil 4357 arg3 nil nil) 4361 4358 (compile-constant 0 target representation)) 4362 4359 ((and size position) 4363 4360 (cond ((<= (+ position size) 31) 4364 4365 4366 4361 (compile-forms-and-maybe-emit-clear-values size-arg nil nil 4362 position-arg nil nil 4363 arg3 'stack :int) 4367 4364 (unless (zerop position) 4368 4365 (emit-push-constant-int position) … … 4373 4370 (emit-move-from-stack target representation)) 4374 4371 ((<= (+ position size) 63) 4375 4376 4377 4372 (compile-forms-and-maybe-emit-clear-values size-arg nil nil 4373 position-arg nil nil 4374 arg3 'stack :long) 4378 4375 (unless (zerop position) 4379 4376 (emit-push-constant-int position) … … 4390 4387 (emit-move-from-stack target representation)) 4391 4388 (t 4392 4389 (compile-forms-and-maybe-emit-clear-values arg3 'stack nil) 4393 4390 (emit-push-constant-int size) 4394 4391 (emit-push-constant-int position) … … 4398 4395 ((and (fixnum-type-p size-type) 4399 4396 (fixnum-type-p position-type)) 4400 4401 4402 4397 (compile-forms-and-maybe-emit-clear-values size-arg 'stack :int 4398 position-arg 'stack :int 4399 arg3 'stack nil) 4403 4400 (emit 'dup_x2) ;; use not supported by emit-dup: 3 values involved 4404 4401 (emit 'pop) … … 4420 4417 (fixnum-type-p type1) 4421 4418 (fixnum-type-p type2)) 4422 4423 4419 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 4420 arg2 'stack :int) 4424 4421 (emit-invokestatic +lisp+ "mod" '(:int :int) :int) 4425 4422 (emit-move-from-stack target representation)) 4426 4423 ((fixnum-type-p type2) 4427 4428 4424 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4425 arg2 'stack :int) 4429 4426 (emit-invokevirtual +lisp-object+ "MOD" '(:int) +lisp-object+) 4430 4427 (fix-boxing representation nil) ; FIXME use derived result type 4431 4428 (emit-move-from-stack target representation)) 4432 4429 (t 4433 4434 4430 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4431 arg2 'stack nil) 4435 4432 (emit-invokevirtual +lisp-object+ "MOD" 4436 4433 (lisp-object-arg-types 1) +lisp-object+) … … 4445 4442 (type (derive-compiler-type arg))) 4446 4443 (cond ((fixnum-type-p type) 4447 4444 (compile-forms-and-maybe-emit-clear-values arg 'stack :int) 4448 4445 (let ((LABEL1 (gensym)) 4449 4446 (LABEL2 (gensym))) … … 4464 4461 (emit-move-from-stack target representation))) 4465 4462 ((java-long-type-p type) 4466 4463 (compile-forms-and-maybe-emit-clear-values arg 'stack :long) 4467 4464 (emit 'lconst_0) 4468 4465 (emit 'lcmp) … … 4477 4474 (emit-move-from-stack target representation))) 4478 4475 (t 4479 4476 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 4480 4477 (emit-invoke-method "ZEROP" target representation))))) 4481 4478 … … 4507 4504 (2 4508 4505 (let ((arg2 (second args))) 4509 4510 4506 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4507 arg2 'stack :boolean) 4511 4508 (emit-invokestatic +lisp-class+ "findClass" 4512 4509 (list +lisp-object+ :boolean) +lisp-object+) … … 4525 4522 (2 4526 4523 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4527 4524 arg2 'stack nil) 4528 4525 (emit 'swap) 4529 4526 (cond (target … … 4545 4542 (arg2 (second args))) 4546 4543 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4547 4544 arg2 'stack nil) 4548 4545 (emit-invokevirtual +lisp-object+ "SLOT_VALUE" 4549 4546 (lisp-object-arg-types 1) +lisp-object+) … … 4562 4559 (value-register (when target (allocate-register)))) 4563 4560 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 4564 4565 4561 arg2 'stack nil 4562 arg3 'stack nil) 4566 4563 (when value-register 4567 4564 (emit 'dup) … … 4579 4576 (let ((arg (%cadr form))) 4580 4577 (cond ((eq (derive-compiler-type arg) 'STREAM) 4581 4578 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 4582 4579 (emit-checkcast +lisp-stream+) 4583 4580 (emit-invokevirtual +lisp-stream+ "getElementType" … … 4626 4623 (type1 (derive-compiler-type arg1))) 4627 4624 (cond ((compiler-subtypep type1 'stream) 4628 4625 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 4629 4626 (emit-checkcast +lisp-stream+) 4630 4627 (emit-push-constant-int 1) … … 4640 4637 (arg2 (%cadr args))) 4641 4638 (cond ((and (compiler-subtypep type1 'stream) (null arg2)) 4642 4639 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 4643 4640 (emit-checkcast +lisp-stream+) 4644 4641 (emit-push-constant-int 0) … … 4934 4931 (defun derive-compiler-types (args op) 4935 4932 (flet ((combine (x y) 4936 4933 (derive-type-numeric-op op x y))) 4937 4934 (reduce #'combine (cdr args) :key #'derive-compiler-type 4938 4935 :initial-value (derive-compiler-type (car args))))) 4939 4936 4940 4937 (defknown derive-type-minus (t) t) … … 5226 5223 (defun cons-for-list/list* (form target representation &optional list-star-p) 5227 5224 (let* ((args (cdr form)) 5228 5229 5230 5231 5225 (length (length args)) 5226 (cons-heads (if list-star-p 5227 (butlast args 1) 5228 args))) 5232 5229 (cond ((>= 4 length 1) 5233 (dolist (cons-head cons-heads) 5234 (emit-new +lisp-cons+) 5235 (emit 'dup) 5236 (compile-form cons-head 'stack nil)) 5237 (if list-star-p 5238 (compile-form (first (last args)) 'stack nil) 5239 (progn 5240 (emit-invokespecial-init 5241 +lisp-cons+ (lisp-object-arg-types 1)) 5242 (pop cons-heads))) ; we've handled one of the args, so remove it 5243 (dolist (cons-head cons-heads) 5244 (declare (ignore cons-head)) 5245 (emit-invokespecial-init 5246 +lisp-cons+ (lisp-object-arg-types 2))) 5247 (if list-star-p 5248 (progn 5249 (apply #'maybe-emit-clear-values args) 5250 (emit-move-from-stack target representation)) 5251 (progn 5252 (unless (every 'single-valued-p args) 5253 (emit-clear-values)) 5254 (emit-move-from-stack target)))) 5255 (t 5256 (compile-function-call form target representation))))) 5257 5258 5230 (dolist (cons-head cons-heads) 5231 (emit-new +lisp-cons+) 5232 (emit 'dup) 5233 (compile-form cons-head 'stack nil)) 5234 (if list-star-p 5235 (compile-form (first (last args)) 'stack nil) 5236 (progn 5237 (emit-invokespecial-init 5238 +lisp-cons+ (lisp-object-arg-types 1)) 5239 (pop cons-heads))) ; we've handled one of the args, so remove it 5240 (dolist (cons-head cons-heads) 5241 (declare (ignore cons-head)) 5242 (emit-invokespecial-init 5243 +lisp-cons+ (lisp-object-arg-types 2))) 5244 (if list-star-p 5245 (progn 5246 (apply #'maybe-emit-clear-values args) 5247 (emit-move-from-stack target representation)) 5248 (progn 5249 (unless (every 'single-valued-p args) 5250 (emit-clear-values)) 5251 (emit-move-from-stack target)))) 5252 (t 5253 (compile-function-call form target representation))))) 5259 5254 5260 5255 (defun p2-list (form target representation) … … 5269 5264 (list-form (third form))) 5270 5265 (compile-forms-and-maybe-emit-clear-values index-form 'stack :int 5271 5266 list-form 'stack nil) 5272 5267 (emit 'swap) 5273 5268 (emit-invokevirtual +lisp-object+ "NTH" '(:int) +lisp-object+) … … 5306 5301 (sys::format t "p2-times: unsupported rep case")))) 5307 5302 (convert-representation result-rep representation) 5308 5303 (emit-move-from-stack target representation)) 5309 5304 ((fixnump arg2) 5310 5305 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 5311 5306 (emit-push-int arg2) 5312 5307 (emit-invokevirtual +lisp-object+ "multiplyBy" '(:int) +lisp-object+) … … 5393 5388 (compile-constant (+ arg1 arg2) target representation)) 5394 5389 ((and (numberp arg1) (eql arg1 0)) 5395 5396 5390 (compile-forms-and-maybe-emit-clear-values arg1 nil nil 5391 arg2 'stack representation) 5397 5392 (emit-move-from-stack target representation)) 5398 5393 ((and (numberp arg2) (eql arg2 0)) 5399 5400 5394 (compile-forms-and-maybe-emit-clear-values arg1 'stack representation 5395 arg2 nil nil) 5401 5396 (emit-move-from-stack target representation)) 5402 5397 (result-rep … … 5417 5412 (emit-move-from-stack target representation)) 5418 5413 ((eql arg2 1) 5419 5414 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 5420 5415 (emit-invoke-method "incr" target representation)) 5421 5416 ((eql arg1 1) 5422 5417 (compile-forms-and-maybe-emit-clear-values arg2 'stack nil) 5423 5418 (emit-invoke-method "incr" target representation)) 5424 5419 ((or (fixnum-type-p type1) (fixnum-type-p type2)) 5425 5420 (compile-forms-and-maybe-emit-clear-values 5426 5421 arg1 'stack (when (fixnum-type-p type1) :int) 5427 5422 arg2 'stack (when (null (fixnum-type-p type1)) :int)) … … 5466 5461 (emit-move-from-stack target representation)) 5467 5462 (t 5468 5463 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 5469 5464 (emit-invokevirtual +lisp-object+ "negate" 5470 5465 nil +lisp-object+) … … 5481 5476 (compile-constant (- arg1 arg2) target representation)) 5482 5477 (result-rep 5483 5478 (compile-forms-and-maybe-emit-clear-values 5484 5479 arg1 'stack result-rep 5485 5480 arg2 'stack result-rep) … … 5496 5491 (emit-move-from-stack target representation)) 5497 5492 ((fixnum-type-p type2) 5498 5493 (compile-forms-and-maybe-emit-clear-values 5499 5494 arg1 'stack nil 5500 5495 arg2 'stack :int) … … 5541 5536 (emit-move-from-stack target representation)) 5542 5537 ((fixnum-type-p type2) 5543 5544 5538 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5539 arg2 'stack :int) 5545 5540 (emit-invokevirtual +lisp-object+ 5546 5541 (symbol-name op) ;; "CHAR" or "SCHAR" … … 5596 5591 (let ((arg1 (%cadr form)) 5597 5592 (arg2 (%caddr form))) 5598 5599 5593 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5594 arg2 'stack :int) 5600 5595 (emit-invokevirtual +lisp-object+ "SVREF" '(:int) +lisp-object+) 5601 5596 (fix-boxing representation nil) … … 5668 5663 (ecase representation 5669 5664 (:int 5670 5671 5665 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5666 arg2 'stack :int) 5672 5667 (emit-invokevirtual +lisp-object+ "aref" '(:int) :int)) 5673 5668 (:long 5674 5675 5669 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5670 arg2 'stack :int) 5676 5671 (emit-invokevirtual +lisp-object+ "aref_long" '(:int) :long)) 5677 5672 (:char … … 5684 5679 "charAt" '(:int) :char)) 5685 5680 (t 5686 5687 5681 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5682 arg2 'stack :int) 5688 5683 (emit-invokevirtual +lisp-object+ "AREF" '(:int) +lisp-object+) 5689 5684 (emit-unbox-character)))) … … 5691 5686 ;;###FIXME for float and double, we probably want 5692 5687 ;; separate java methods to retrieve the values. 5693 5694 5688 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5689 arg2 'stack :int) 5695 5690 (emit-invokevirtual +lisp-object+ "AREF" '(:int) +lisp-object+) 5696 5691 (convert-representation nil representation))) … … 5748 5743 (cond ((and (fixnump arg2) 5749 5744 (null representation)) 5750 5745 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 5751 5746 (case arg2 5752 5747 (0 … … 5768 5763 (emit-move-from-stack target representation)) 5769 5764 ((fixnump arg2) 5770 5765 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 5771 5766 (emit-push-constant-int arg2) 5772 5767 (ecase representation … … 5797 5792 (let* ((*register* *register*) 5798 5793 (value-register (when target (allocate-register)))) 5799 5800 5794 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil 5795 arg3 'stack nil) 5801 5796 (when value-register 5802 5797 (emit 'dup) … … 5839 5834 ((and (consp arg) 5840 5835 (memq (%car arg) '(NOT NULL))) 5841 5836 (compile-forms-and-maybe-emit-clear-values (second arg) 'stack nil) 5842 5837 (emit-push-nil) 5843 5838 (let ((LABEL1 (gensym)) … … 5850 5845 (label LABEL2))) 5851 5846 ((eq representation :boolean) 5852 5847 (compile-forms-and-maybe-emit-clear-values arg 'stack :boolean) 5853 5848 (emit 'iconst_1) 5854 5849 (emit 'ixor)) 5855 5850 ((eq (derive-compiler-type arg) 'BOOLEAN) 5856 5851 (compile-forms-and-maybe-emit-clear-values arg 'stack :boolean) 5857 5852 (let ((LABEL1 (gensym)) 5858 5853 (LABEL2 (gensym))) … … 5864 5859 (label LABEL2))) 5865 5860 (t 5866 5861 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 5867 5862 (let ((LABEL1 (gensym)) 5868 5863 (LABEL2 (gensym))) … … 5882 5877 (arg2 (%cadr args))) 5883 5878 (cond ((fixnum-type-p (derive-compiler-type arg1)) 5884 5885 5879 (compile-forms-and-maybe-emit-clear-values arg1 'stack :int 5880 arg2 'stack nil) 5886 5881 (emit 'swap) 5887 5882 (emit-invokevirtual +lisp-object+ "nthcdr" '(:int) +lisp-object+) … … 5905 5900 (FAIL (gensym)) 5906 5901 (DONE (gensym))) 5907 5902 (compile-forms-and-maybe-emit-clear-values arg1 'stack :boolean) 5908 5903 (emit 'ifeq FAIL) 5909 5904 (ecase representation 5910 5905 (:boolean 5911 5906 (compile-forms-and-maybe-emit-clear-values arg2 'stack :boolean) 5912 5907 (emit 'goto DONE) 5913 5908 (label FAIL) … … 5939 5934 (LABEL1 (gensym)) 5940 5935 (LABEL2 (gensym))) 5941 5936 (compile-forms-and-maybe-emit-clear-values arg1 'stack nil) 5942 5937 (emit 'dup) 5943 5938 (emit-push-nil) … … 5965 5960 (1 5966 5961 (let ((arg (%car args))) 5967 5962 (compile-forms-and-maybe-emit-clear-values arg target representation))) 5968 5963 (2 5969 5964 (emit-push-current-thread) … … 6114 6109 (emit-push-current-thread) 6115 6110 (emit-load-externalized-object name) 6116 6111 (compile-forms-and-maybe-emit-clear-values (second value-form) 'stack nil) 6117 6112 (emit-invokevirtual +lisp-thread+ "pushSpecial" 6118 6113 (list +lisp-symbol+ +lisp-object+) +lisp-object+)) … … 6120 6115 (emit-push-current-thread) 6121 6116 (emit-load-externalized-object name) 6122 6117 (compile-forms-and-maybe-emit-clear-values value-form 'stack nil) 6123 6118 (emit-invokevirtual +lisp-thread+ "setSpecialVariable" 6124 6119 (list +lisp-symbol+ +lisp-object+) +lisp-object+))) … … 6130 6125 ;; If we never read the variable, we don't have to set it. 6131 6126 (cond (target 6132 6127 (compile-forms-and-maybe-emit-clear-values value-form 'stack nil) 6133 6128 (fix-boxing representation nil) 6134 6129 (emit-move-from-stack target representation)) … … 6199 6194 (cond ((check-arg-count form 1) 6200 6195 (let ((arg (%cadr form))) 6201 6196 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 6202 6197 (emit-invokevirtual +lisp-object+ "sxhash" nil :int) 6203 6198 (convert-representation :int representation) … … 6211 6206 (let ((arg (%cadr form))) 6212 6207 (cond ((and (eq (derive-compiler-type arg) 'SYMBOL) (< *safety* 3)) 6213 6208 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 6214 6209 (emit-checkcast +lisp-symbol+) 6215 6210 (emit-getfield +lisp-symbol+ "name" +lisp-simple-string+) … … 6223 6218 (let ((arg (%cadr form))) 6224 6219 (cond ((and (eq (derive-compiler-type arg) 'SYMBOL) (< *safety* 3)) 6225 6220 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 6226 6221 (emit-checkcast +lisp-symbol+) 6227 6222 (emit-invokevirtual +lisp-symbol+ "getPackage" … … 6237 6232 (let ((arg (%cadr form))) 6238 6233 (when (eq (derive-compiler-type arg) 'SYMBOL) 6239 6234 (compile-forms-and-maybe-emit-clear-values arg 'stack nil) 6240 6235 (emit-checkcast +lisp-symbol+) 6241 6236 (emit-push-current-thread) … … 6258 6253 (HASH-TABLE +lisp-hash-table+) 6259 6254 (FIXNUM +lisp-fixnum+) 6260 6255 (STREAM +lisp-stream+) 6261 6256 (STRING +lisp-abstract-string+) 6262 6257 (VECTOR +lisp-abstract-vector+))) … … 6314 6309 ;; we change the representation between the above and here 6315 6310 ;; ON PURPOSE! 6316 6311 (convert-representation :int representation) 6317 6312 (emit-move-from-stack target representation)) 6318 6313 (t … … 6322 6317 (define-inlined-function p2-java-jclass (form target representation) 6323 6318 ((and (= 2 (length form)) 6324 6319 (stringp (cadr form)))) 6325 6320 (let ((c (ignore-errors (java:jclass (cadr form))))) 6326 6321 (if c (compile-constant c target representation) … … 6331 6326 (define-inlined-function p2-java-jconstructor (form target representation) 6332 6327 ((and (< 1 (length form)) 6333 6328 (every #'stringp (cdr form)))) 6334 6329 (let ((c (ignore-errors (apply #'java:jconstructor (cdr form))))) 6335 6330 (if c (compile-constant c target representation) … … 6340 6335 (define-inlined-function p2-java-jmethod (form target representation) 6341 6336 ((and (< 1 (length form)) 6342 6337 (every #'stringp (cdr form)))) 6343 6338 (let ((m (ignore-errors (apply #'java:jmethod (cdr form))))) 6344 6339 (if m (compile-constant m target representation) … … 6349 6344 (define-inlined-function p2-java-jcall (form target representation) 6350 6345 ((and (> *speed* *safety*) 6351 6352 6353 6346 (< 1 (length form)) 6347 (eq 'jmethod (car (cadr form))) 6348 (every #'stringp (cdr (cadr form))))) 6354 6349 (let ((m (ignore-errors (eval (cadr form))))) 6355 (if m 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6350 (if m 6351 (let ((must-clear-values nil) 6352 (arg-types (raw-arg-types (jmethod-params m)))) 6353 (declare (type boolean must-clear-values)) 6354 (dolist (arg (cddr form)) 6355 (compile-form arg 'stack nil) 6356 (unless must-clear-values 6357 (unless (single-valued-p arg) 6358 (setf must-clear-values t)))) 6359 (when must-clear-values 6360 (emit-clear-values)) 6361 (dotimes (i (jarray-length raw-arg-types)) 6362 (push (jarray-ref raw-arg-types i) arg-types)) 6363 (emit-invokevirtual (jclass-name (jmethod-declaring-class m)) 6364 (jmethod-name m) 6365 (nreverse arg-types) 6366 (jmethod-return-type m))) 6372 6367 ;; delay resolving the method to run-time; it's unavailable now 6373 6368 (compile-function-call form target representation))))|# … … 6395 6390 (cond ((characterp arg1) 6396 6391 (emit-push-constant-int (char-code arg1)) 6397 6392 (compile-forms-and-maybe-emit-clear-values arg2 'stack :char)) 6398 6393 ((characterp arg2) 6399 6394 (compile-forms-and-maybe-emit-clear-values arg1 'stack :char) 6400 6395 (emit-push-constant-int (char-code arg2))) 6401 6396 (t 6402 6403 6397 (compile-forms-and-maybe-emit-clear-values arg1 'stack :char 6398 arg2 'stack :char))) 6404 6399 (let ((LABEL1 (gensym)) 6405 6400 (LABEL2 (gensym))) … … 6769 6764 (method (make-method "execute" +lisp-object+ arg-types 6770 6765 :flags '(:final :public))) 6771 (code (method-add-code method))6772 (*current-code-attribute* code)6773 (*code* ())6774 (*register* 1) ;; register 0: "this" pointer6775 (*registers-allocated* 1)6776 6766 (*visible-variables* *visible-variables*) 6777 6767 … … 6781 6771 6782 6772 (class-add-method class-file method) 6783 (when (fixnump *source-line-number*) 6784 (let ((table (make-line-numbers-attribute))) 6785 (method-add-attribute method table) 6786 (line-numbers-add-line table 0 *source-line-number*))) 6787 6788 (dolist (var (compiland-arg-vars compiland)) 6789 (push var *visible-variables*)) 6790 (dolist (var (compiland-free-specials compiland)) 6791 (push var *visible-variables*)) 6792 6793 (when *using-arg-array* 6794 (setf (compiland-argument-register compiland) (allocate-register))) 6795 6796 ;; Assign indices or registers, depending on where the args are 6797 ;; located: the arg-array or the call-stack 6798 (let ((index 0)) 6799 (dolist (variable (compiland-arg-vars compiland)) 6800 (aver (null (variable-register variable))) 6801 (aver (null (variable-index variable))) 6802 (if *using-arg-array* 6803 (setf (variable-index variable) index) 6804 (setf (variable-register variable) (allocate-register))) 6805 (incf index))) 6806 6807 ;; Reserve the next available slot for the thread register. 6808 (setf *thread* (allocate-register)) 6809 6810 (when *closure-variables* 6811 (setf (compiland-closure-register compiland) (allocate-register)) 6812 (dformat t "p2-compiland 2 closure register = ~S~%" 6813 (compiland-closure-register compiland))) 6814 6815 (when *closure-variables* 6816 (if (not *child-p*) 6817 (progn 6818 ;; if we're the ultimate parent: create the closure array 6819 (emit-push-constant-int (length *closure-variables*)) 6820 (emit-anewarray +lisp-closure-binding+)) 6821 (progn 6822 (aload 0) 6823 (emit-getfield +lisp-compiled-closure+ "ctx" 6824 +closure-binding-array+) 6825 (when local-closure-vars 6826 ;; in all other cases, it gets stored in the register below 6827 (emit 'astore (compiland-closure-register compiland)) 6828 (duplicate-closure-array compiland))))) 6829 6830 ;; Move args from their original registers to the closure variables array 6831 (when (or closure-args 6832 (and *closure-variables* (not *child-p*))) 6833 (dformat t "~S moving arguments to closure array~%" 6834 (compiland-name compiland)) 6835 (dotimes (i (length *closure-variables*)) 6836 ;; Loop over all slots, setting their value 6837 ;; unconditionally if we're the parent creating it (using null 6838 ;; values if no real value is available) 6839 ;; or selectively if we're a child binding certain slots. 6840 (let ((variable (find i closure-args 6841 :key #'variable-closure-index 6842 :test #'eql))) 6843 (when (or (not *child-p*) variable) 6844 ;; we're the parent, or we have a variable to set. 6845 (emit 'dup) ; array 6846 (emit-push-constant-int i) 6847 (emit-new +lisp-closure-binding+) 6848 (emit 'dup) 6849 (cond 6850 ((null variable) 6851 (assert (not *child-p*)) 6852 (emit 'aconst_null)) 6853 ((variable-register variable) 6854 (assert (not (eql (variable-register variable) 6855 (compiland-closure-register compiland)))) 6856 (aload (variable-register variable)) 6857 (setf (variable-register variable) nil)) 6858 ((variable-index variable) 6859 (aload (compiland-argument-register compiland)) 6860 (emit-push-constant-int (variable-index variable)) 6861 (emit 'aaload) 6862 (setf (variable-index variable) nil)) 6863 (t 6864 (assert (not "Can't happen!!")))) 6865 (emit-invokespecial-init +lisp-closure-binding+ 6866 (list +lisp-object+)) 6867 (emit 'aastore))))) 6868 6869 (when *closure-variables* 6870 (aver (not (null (compiland-closure-register compiland)))) 6871 (astore (compiland-closure-register compiland)) 6872 (dformat t "~S done moving arguments to closure array~%" 6873 (compiland-name compiland))) 6874 6875 ;; If applicable, move args from arg array to registers. 6876 (when *using-arg-array* 6877 (dolist (variable (compiland-arg-vars compiland)) 6878 (unless (or (variable-special-p variable) 6879 (null (variable-index variable)) ;; not in the array anymore 6880 (< (+ (variable-reads variable) 6881 (variable-writes variable)) 2)) 6882 (let ((register (allocate-register))) 6883 (aload (compiland-argument-register compiland)) 6884 (emit-push-constant-int (variable-index variable)) 6885 (emit 'aaload) 6886 (astore register) 6887 (setf (variable-register variable) register) 6888 (setf (variable-index variable) nil))))) 6889 6890 (p2-compiland-process-type-declarations body) 6891 (generate-type-checks-for-variables (compiland-arg-vars compiland)) 6892 6893 ;; Unbox variables. 6894 (dolist (variable (compiland-arg-vars compiland)) 6895 (p2-compiland-unbox-variable variable)) 6896 6897 ;; Establish dynamic bindings for any variables declared special. 6898 (when (some #'variable-special-p (compiland-arg-vars compiland)) 6899 ;; Save the dynamic environment 6900 (setf (compiland-environment-register compiland) 6901 (allocate-register)) 6902 (save-dynamic-environment (compiland-environment-register compiland)) 6903 (label label-START) 6904 (dolist (variable (compiland-arg-vars compiland)) 6905 (when (variable-special-p variable) 6906 (setf (variable-binding-register variable) (allocate-register)) 6907 (emit-push-current-thread) 6908 (emit-push-variable-name variable) 6909 (cond ((variable-register variable) 6773 6774 (setf (abcl-class-file-lambda-list class-file) args) 6775 (setf (abcl-class-file-superclass class-file) 6776 (if (or *hairy-arglist-p* 6777 (and *child-p* *closure-variables*)) 6778 +lisp-compiled-closure+ 6779 +lisp-compiled-primitive+)) 6780 6781 (let ((constructor (make-constructor class-file))) 6782 (setf (abcl-class-file-constructor class-file) constructor) 6783 (class-add-method class-file constructor)) 6784 #+enable-when-generating-clinit 6785 (let ((clinit (make-static-initializer class-file))) 6786 (setf (abcl-class-file-static-initializer class-file) clinit) 6787 (class-add-method class-file clinit)) 6788 6789 (with-code-to-method (class-file method) 6790 (setf *register* 1 ;; register 0: "this" pointer 6791 *registers-allocated* 1) 6792 6793 (when (fixnump *source-line-number*) 6794 (let ((table (make-line-numbers-attribute))) 6795 (method-add-attribute method table) 6796 (line-numbers-add-line table 0 *source-line-number*))) 6797 6798 (dolist (var (compiland-arg-vars compiland)) 6799 (push var *visible-variables*)) 6800 (dolist (var (compiland-free-specials compiland)) 6801 (push var *visible-variables*)) 6802 6803 (when *using-arg-array* 6804 (setf (compiland-argument-register compiland) (allocate-register))) 6805 6806 ;; Assign indices or registers, depending on where the args are 6807 ;; located: the arg-array or the call-stack 6808 (let ((index 0)) 6809 (dolist (variable (compiland-arg-vars compiland)) 6810 (aver (null (variable-register variable))) 6811 (aver (null (variable-index variable))) 6812 (if *using-arg-array* 6813 (setf (variable-index variable) index) 6814 (setf (variable-register variable) (allocate-register))) 6815 (incf index))) 6816 6817 ;; Reserve the next available slot for the thread register. 6818 (setf *thread* (allocate-register)) 6819 6820 (when *closure-variables* 6821 (setf (compiland-closure-register compiland) (allocate-register)) 6822 (dformat t "p2-compiland 2 closure register = ~S~%" 6823 (compiland-closure-register compiland))) 6824 6825 (when *closure-variables* 6826 (if (not *child-p*) 6827 (progn 6828 ;; if we're the ultimate parent: create the closure array 6829 (emit-push-constant-int (length *closure-variables*)) 6830 (emit-anewarray +lisp-closure-binding+)) 6831 (progn 6832 (aload 0) 6833 (emit-getfield +lisp-compiled-closure+ "ctx" 6834 +closure-binding-array+) 6835 (when local-closure-vars 6836 ;; in all other cases, it gets stored in the register below 6837 (emit 'astore (compiland-closure-register compiland)) 6838 (duplicate-closure-array compiland))))) 6839 6840 ;; Move args from their original registers to the closure variables array 6841 (when (or closure-args 6842 (and *closure-variables* (not *child-p*))) 6843 (dformat t "~S moving arguments to closure array~%" 6844 (compiland-name compiland)) 6845 (dotimes (i (length *closure-variables*)) 6846 ;; Loop over all slots, setting their value 6847 ;; unconditionally if we're the parent creating it (using null 6848 ;; values if no real value is available) 6849 ;; or selectively if we're a child binding certain slots. 6850 (let ((variable (find i closure-args 6851 :key #'variable-closure-index 6852 :test #'eql))) 6853 (when (or (not *child-p*) variable) 6854 ;; we're the parent, or we have a variable to set. 6855 (emit 'dup) ; array 6856 (emit-push-constant-int i) 6857 (emit-new +lisp-closure-binding+) 6858 (emit 'dup) 6859 (cond 6860 ((null variable) 6861 (assert (not *child-p*)) 6862 (emit 'aconst_null)) 6863 ((variable-register variable) 6864 (assert (not (eql (variable-register variable) 6865 (compiland-closure-register compiland)))) 6910 6866 (aload (variable-register variable)) 6911 6867 (setf (variable-register variable) nil)) … … 6914 6870 (emit-push-constant-int (variable-index variable)) 6915 6871 (emit 'aaload) 6916 (setf (variable-index variable) nil))) 6917 (emit-invokevirtual +lisp-thread+ "bindSpecial" 6918 (list +lisp-symbol+ +lisp-object+) 6919 +lisp-special-binding+) 6920 (astore (variable-binding-register variable))))) 6921 6922 (compile-progn-body body 'stack) 6923 6924 (when (compiland-environment-register compiland) 6925 (restore-dynamic-environment (compiland-environment-register compiland))) 6926 6927 (unless *code* 6928 (emit-push-nil)) 6929 (emit 'areturn) 6930 6931 ;; Warn if any unused args. (Is this the right place?) 6932 (check-for-unused-variables (compiland-arg-vars compiland)) 6933 6934 ;; Go back and fill in prologue. 6935 (let ((code *code*)) 6936 (setf *code* ()) 6937 (let ((arity (compiland-arity compiland))) 6938 (when arity 6939 (generate-arg-count-check arity))) 6940 6941 (when *hairy-arglist-p* 6942 (aload 0) ; this 6943 (aver (not (null (compiland-argument-register compiland)))) 6944 (aload (compiland-argument-register compiland)) ; arg vector 6945 (cond ((or (memq '&OPTIONAL args) (memq '&KEY args)) 6946 (ensure-thread-var-initialized) 6947 (maybe-initialize-thread-var) 6948 (emit-push-current-thread) 6949 (emit-invokevirtual *this-class* "processArgs" 6950 (list +lisp-object-array+ +lisp-thread+) 6951 +lisp-object-array+)) 6952 (t 6953 (emit-invokevirtual *this-class* "fastProcessArgs" 6954 (list +lisp-object-array+) 6955 +lisp-object-array+))) 6956 (astore (compiland-argument-register compiland))) 6957 6958 (unless (and *hairy-arglist-p* 6959 (or (memq '&OPTIONAL args) (memq '&KEY args))) 6960 (maybe-initialize-thread-var)) 6961 (setf *code* (nconc code *code*))) 6962 6963 (setf (abcl-class-file-superclass class-file) 6964 (if (or *hairy-arglist-p* 6965 (and *child-p* *closure-variables*)) 6966 +lisp-compiled-closure+ 6967 +lisp-compiled-primitive+)) 6968 6969 (setf (abcl-class-file-lambda-list class-file) args) 6970 (setf (code-max-locals code) *registers-allocated*) 6971 (setf (code-code code) *code*)) 6972 6973 6872 (setf (variable-index variable) nil)) 6873 (t 6874 (assert (not "Can't happen!!")))) 6875 (emit-invokespecial-init +lisp-closure-binding+ 6876 (list +lisp-object+)) 6877 (emit 'aastore))))) 6878 6879 (when *closure-variables* 6880 (aver (not (null (compiland-closure-register compiland)))) 6881 (astore (compiland-closure-register compiland)) 6882 (dformat t "~S done moving arguments to closure array~%" 6883 (compiland-name compiland))) 6884 6885 ;; If applicable, move args from arg array to registers. 6886 (when *using-arg-array* 6887 (dolist (variable (compiland-arg-vars compiland)) 6888 (unless (or (variable-special-p variable) 6889 (null (variable-index variable)) ;; not in the array anymore 6890 (< (+ (variable-reads variable) 6891 (variable-writes variable)) 2)) 6892 (let ((register (allocate-register))) 6893 (aload (compiland-argument-register compiland)) 6894 (emit-push-constant-int (variable-index variable)) 6895 (emit 'aaload) 6896 (astore register) 6897 (setf (variable-register variable) register) 6898 (setf (variable-index variable) nil))))) 6899 6900 (p2-compiland-process-type-declarations body) 6901 (generate-type-checks-for-variables (compiland-arg-vars compiland)) 6902 6903 ;; Unbox variables. 6904 (dolist (variable (compiland-arg-vars compiland)) 6905 (p2-compiland-unbox-variable variable)) 6906 6907 ;; Establish dynamic bindings for any variables declared special. 6908 (when (some #'variable-special-p (compiland-arg-vars compiland)) 6909 ;; Save the dynamic environment 6910 (setf (compiland-environment-register compiland) 6911 (allocate-register)) 6912 (save-dynamic-environment (compiland-environment-register compiland)) 6913 (label label-START) 6914 (dolist (variable (compiland-arg-vars compiland)) 6915 (when (variable-special-p variable) 6916 (setf (variable-binding-register variable) (allocate-register)) 6917 (emit-push-current-thread) 6918 (emit-push-variable-name variable) 6919 (cond ((variable-register variable) 6920 (aload (variable-register variable)) 6921 (setf (variable-register variable) nil)) 6922 ((variable-index variable) 6923 (aload (compiland-argument-register compiland)) 6924 (emit-push-constant-int (variable-index variable)) 6925 (emit 'aaload) 6926 (setf (variable-index variable) nil))) 6927 (emit-invokevirtual +lisp-thread+ "bindSpecial" 6928 (list +lisp-symbol+ +lisp-object+) 6929 +lisp-special-binding+) 6930 (astore (variable-binding-register variable))))) 6931 6932 (compile-progn-body body 'stack) 6933 6934 (when (compiland-environment-register compiland) 6935 (restore-dynamic-environment (compiland-environment-register compiland))) 6936 6937 (unless *code* 6938 (emit-push-nil)) 6939 (emit 'areturn) 6940 6941 ;; Warn if any unused args. (Is this the right place?) 6942 (check-for-unused-variables (compiland-arg-vars compiland)) 6943 6944 ;; Go back and fill in prologue. 6945 (let ((code *code*)) 6946 (setf *code* ()) 6947 (let ((arity (compiland-arity compiland))) 6948 (when arity 6949 (generate-arg-count-check arity))) 6950 6951 (when *hairy-arglist-p* 6952 (aload 0) ; this 6953 (aver (not (null (compiland-argument-register compiland)))) 6954 (aload (compiland-argument-register compiland)) ; arg vector 6955 (cond ((or (memq '&OPTIONAL args) (memq '&KEY args)) 6956 (ensure-thread-var-initialized) 6957 (maybe-initialize-thread-var) 6958 (emit-push-current-thread) 6959 (emit-invokevirtual *this-class* "processArgs" 6960 (list +lisp-object-array+ +lisp-thread+) 6961 +lisp-object-array+)) 6962 (t 6963 (emit-invokevirtual *this-class* "fastProcessArgs" 6964 (list +lisp-object-array+) 6965 +lisp-object-array+))) 6966 (astore (compiland-argument-register compiland))) 6967 6968 (unless (and *hairy-arglist-p* 6969 (or (memq '&OPTIONAL args) (memq '&KEY args))) 6970 (maybe-initialize-thread-var)) 6971 (setf *code* (nconc code *code*))) 6972 )) 6974 6973 t) 6975 6974 … … 6978 6977 (destructuring-bind (&optional target-var repr-var) (cadr form) 6979 6978 (eval `(let (,@(when target-var `((,target-var ,target))) 6980 6981 6979 ,@(when repr-var `((,repr-var ,representation)))) 6980 ,@(cddr form))))) 6982 6981 6983 6982 (defun compile-1 (compiland stream) -
trunk/abcl/src/org/armedbear/lisp/jvm-class-file.lisp
r12932 r13025 1140 1140 1141 1141 (defvar *current-code-attribute* nil) 1142 (defvar *method*) 1142 1143 1143 1144 (defun save-code-specials (code) … … 1159 1160 (save-code-specials *current-code-attribute*)) 1160 1161 (let* ((,m ,method) 1162 (*method* ,m) 1161 1163 (,c (method-ensure-code ,method)) 1162 1164 (*pool* (class-file-constants ,class-file)) -
trunk/abcl/src/org/armedbear/lisp/jvm.lisp
r12918 r13025 125 125 lambda-name 126 126 lambda-list ; as advertised 127 static-code 127 static-initializer 128 constructor 128 129 objects ;; an alist of externalized objects and their field names 129 130 (functions (make-hash-table :test 'equal)) ;; because of (SETF ...) functions … … 177 178 (*class-file* ,var) 178 179 (*pool* (abcl-class-file-constants ,var)) 179 (*static-code* (abcl-class-file-static-code ,var))180 180 (*externalized-objects* (abcl-class-file-objects ,var)) 181 181 (*declared-functions* (abcl-class-file-functions ,var))) 182 182 (progn ,@body) 183 (setf (abcl-class-file-static-code ,var) *static-code* 184 (abcl-class-file-objects ,var) *externalized-objects* 183 (setf (abcl-class-file-objects ,var) *externalized-objects* 185 184 (abcl-class-file-functions ,var) *declared-functions*)))) 186 185
Note: See TracChangeset
for help on using the changeset viewer.