Changeset 12984
- Timestamp:
- 10/30/10 00:15:58 (12 years ago)
- Location:
- branches/invokedynamic/abcl/src/org/armedbear/lisp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/invokedynamic/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r12983 r12984 205 205 (defun emit-invokestatic (class-name method-name arg-types return-type) 206 206 (let* ((stack-effect (apply #'descriptor-stack-effect return-type arg-types)) 207 (index (constant-index (pool-add-method-ref 208 *pool* class-name 209 method-name (cons return-type arg-types)))) 210 (instruction (apply #'%emit 'invokestatic (u2 index)))) 207 (method (pool-add-method-ref 208 *pool* class-name 209 method-name (cons return-type arg-types))) 210 (instruction (%emit 'invokestatic method))) 211 (when (string= method-name "recall") 212 (sys::%format t "RECALL!!! ~S ~S~%" (cons return-type arg-types) method)) 211 213 (setf (instruction-stack instruction) stack-effect))) 212 214 … … 227 229 (defun emit-invokevirtual (class-name method-name arg-types return-type) 228 230 (let* ((stack-effect (apply #'descriptor-stack-effect return-type arg-types)) 229 ( index (constant-index(pool-add-method-ref230 231 method-name (cons return-type arg-types))))232 (instruction ( apply #'%emit 'invokevirtual (u2 index))))231 (method (pool-add-method-ref 232 *pool* class-name 233 method-name (cons return-type arg-types))) 234 (instruction (%emit 'invokevirtual method))) 233 235 (declare (type (signed-byte 8) stack-effect)) 234 236 (let ((explain *explain*)) … … 245 247 (defun emit-invokespecial-init (class-name arg-types) 246 248 (let* ((stack-effect (apply #'descriptor-stack-effect :void arg-types)) 247 ( index (constant-index(pool-add-method-ref248 249 "<init>" (cons nil arg-types))))250 (instruction ( apply #'%emit 'invokespecial (u2 index))))249 (method (pool-add-method-ref 250 *pool* class-name 251 "<init>" (cons nil arg-types))) 252 (instruction (%emit 'invokespecial method))) 251 253 (declare (type (signed-byte 8) stack-effect)) 252 254 (setf (instruction-stack instruction) (1- stack-effect)))) … … 288 290 (defun emit-getstatic (class-name field-name type) 289 291 (let ((ref (pool-add-field-ref *pool* class-name field-name type))) 290 ( apply #'%emit 'getstatic (u2 (constant-index ref)))))292 (%emit 'getstatic ref))) 291 293 292 294 (defknown emit-putstatic (t t t) t) 293 295 (defun emit-putstatic (class-name field-name type) 294 296 (let ((ref (pool-add-field-ref *pool* class-name field-name type))) 295 ( apply #'%emit 'putstatic (u2 (constant-index ref)))))297 (%emit 'putstatic ref))) 296 298 297 299 (declaim (inline emit-getfield emit-putfield)) … … 299 301 (defun emit-getfield (class-name field-name type) 300 302 (let* ((ref (pool-add-field-ref *pool* class-name field-name type))) 301 ( apply #'%emit 'getfield (u2 (constant-index ref)))))303 (%emit 'getfield ref))) 302 304 303 305 (defknown emit-putfield (t t t) t) 304 306 (defun emit-putfield (class-name field-name type) 305 307 (let* ((ref (pool-add-field-ref *pool* class-name field-name type))) 306 ( apply #'%emit 'putfield (u2 (constant-index ref)))))308 (%emit 'putfield ref))) 307 309 308 310 … … 310 312 (declaim (inline emit-new emit-anewarray emit-checkcast emit-instanceof)) 311 313 (defun emit-new (class-name) 312 (apply #'%emit 'new (u2 (constant-index (pool-class class-name))))) 314 (let ((class (pool-class class-name))) 315 (%emit 'new class))) 313 316 314 317 (defknown emit-anewarray (t) t) 315 318 (defun emit-anewarray (class-name) 316 (apply #'%emit 'anewarray (u2 (constant-index (pool-class class-name))))) 319 (let ((class (pool-class class-name))) 320 (%emit 'anewarray class))) 317 321 318 322 (defknown emit-checkcast (t) t) 319 323 (defun emit-checkcast (class-name) 320 (apply #'%emit 'checkcast (u2 (constant-index (pool-class class-name))))) 324 (let ((class (pool-class class-name))) 325 (%emit 'checkcast class))) 321 326 322 327 (defknown emit-instanceof (t) t) 323 328 (defun emit-instanceof (class-name) 324 (apply #'%emit 'instanceof (u2 (constant-index (pool-class class-name))))) 329 (let ((class (pool-class class-name))) 330 (%emit 'instanceof class))) 325 331 326 332 … … 3800 3806 :if-exists :supersede))) 3801 3807 (with-class-file class-file 3802 (make-constructor class-file)3803 3808 (let ((*current-compiland* compiland)) 3804 3809 (with-saved-compiler-policy … … 4559 4564 (fix-boxing representation nil) 4560 4565 (emit-move-from-stack target representation)))) 4561 4562 (defun p2-make-array (form target representation)4563 ;; In safe code, we want to make sure the requested length does not exceed4564 ;; ARRAY-DIMENSION-LIMIT.4565 (cond ((and (< *safety* 3)4566 (= (length form) 2)4567 (fixnum-type-p (derive-compiler-type (second form)))4568 (null representation))4569 (let ((arg (second form)))4570 (emit-new +lisp-simple-vector+)4571 (emit 'dup)4572 (compile-forms-and-maybe-emit-clear-values arg 'stack :int)4573 (emit-invokespecial-init +lisp-simple-vector+ '(:int))4574 (emit-move-from-stack target representation)))4575 (t4576 (compile-function-call form target representation))))4577 4578 ;; make-sequence result-type size &key initial-element => sequence4579 (define-inlined-function p2-make-sequence (form target representation)4580 ;; In safe code, we want to make sure the requested length does not exceed4581 ;; ARRAY-DIMENSION-LIMIT.4582 ((and (< *safety* 3)4583 (= (length form) 3)4584 (null representation)))4585 (let* ((args (cdr form))4586 (arg1 (first args))4587 (arg2 (second args)))4588 (when (and (consp arg1)4589 (= (length arg1) 2)4590 (eq (first arg1) 'QUOTE))4591 (let* ((result-type (second arg1))4592 (class4593 (case result-type4594 ((STRING SIMPLE-STRING)4595 (setf class +lisp-simple-string+))4596 ((VECTOR SIMPLE-VECTOR)4597 (setf class +lisp-simple-vector+)))))4598 (when class4599 (emit-new class)4600 (emit 'dup)4601 (compile-forms-and-maybe-emit-clear-values arg2 'stack :int)4602 (emit-invokespecial-init class '(:int))4603 (emit-move-from-stack target representation)4604 (return-from p2-make-sequence)))))4605 (compile-function-call form target representation))4606 4607 (defun p2-make-string (form target representation)4608 ;; In safe code, we want to make sure the requested length does not exceed4609 ;; ARRAY-DIMENSION-LIMIT.4610 (cond ((and (< *safety* 3)4611 (= (length form) 2)4612 (null representation))4613 (let ((arg (second form)))4614 (emit-new +lisp-simple-string+)4615 (emit 'dup)4616 (compile-forms-and-maybe-emit-clear-values arg 'stack :int)4617 (emit-invokespecial-init +lisp-simple-string+ '(:int))4618 (emit-move-from-stack target representation)))4619 (t4620 (compile-function-call form target representation))))4621 4622 (defun p2-%make-structure (form target representation)4623 (cond ((and (check-arg-count form 2)4624 (eq (derive-type (%cadr form)) 'SYMBOL))4625 (emit-new +lisp-structure-object+)4626 (emit 'dup)4627 (compile-form (%cadr form) 'stack nil)4628 (emit-checkcast +lisp-symbol+)4629 (compile-form (%caddr form) 'stack nil)4630 (maybe-emit-clear-values (%cadr form) (%caddr form))4631 (emit-invokevirtual +lisp-object+ "copyToArray"4632 nil +lisp-object-array+)4633 (emit-invokespecial-init +lisp-structure-object+4634 (list +lisp-symbol+ +lisp-object-array+))4635 (emit-move-from-stack target representation))4636 (t4637 (compile-function-call form target representation))))4638 4639 (defun p2-make-structure (form target representation)4640 (let* ((args (cdr form))4641 (slot-forms (cdr args))4642 (slot-count (length slot-forms)))4643 (cond ((and (<= 1 slot-count 6)4644 (eq (derive-type (%car args)) 'SYMBOL))4645 (emit-new +lisp-structure-object+)4646 (emit 'dup)4647 (compile-form (%car args) 'stack nil)4648 (emit-checkcast +lisp-symbol+)4649 (dolist (slot-form slot-forms)4650 (compile-form slot-form 'stack nil))4651 (apply 'maybe-emit-clear-values args)4652 (emit-invokespecial-init +lisp-structure-object+4653 (append (list +lisp-symbol+)4654 (make-list slot-count :initial-element +lisp-object+)))4655 (emit-move-from-stack target representation))4656 (t4657 (compile-function-call form target representation)))))4658 4659 (defun p2-make-hash-table (form target representation)4660 (cond ((= (length form) 1) ; no args4661 (emit-new +lisp-eql-hash-table+)4662 (emit 'dup)4663 (emit-invokespecial-init +lisp-eql-hash-table+ nil)4664 (fix-boxing representation nil)4665 (emit-move-from-stack target representation))4666 (t4667 (compile-function-call form target representation))))4668 4566 4669 4567 (defknown p2-stream-element-type (t t t) t) … … 6853 6751 :flags '(:final :public))) 6854 6752 (code (method-add-code method)) 6855 (*code-locals* (code-computed-locals code)) ;;TODO in this and other cases, use with-code-to-method6856 (*code-stack* (code-computed-stack code))6857 6753 (*current-code-attribute* code) 6858 6754 (*code* ()) … … 6863 6759 (*thread* nil) 6864 6760 (*initialize-thread-var* nil) 6865 (label-START (gensym)) 6866 prologue) 6761 (label-START (gensym))) 6867 6762 6868 6763 (class-add-method class-file method) 6764 6765 (setf (abcl-class-file-superclass class-file) 6766 (if (or *hairy-arglist-p* 6767 (and *child-p* *closure-variables*)) 6768 +lisp-compiled-closure+ 6769 +lisp-primitive+)) 6770 6771 (make-constructor class-file) 6772 6869 6773 (when (fixnump *source-line-number*) 6870 6774 (let ((table (make-line-numbers-attribute))) … … 6876 6780 (dolist (var (compiland-free-specials compiland)) 6877 6781 (push var *visible-variables*)) 6878 6879 ;;Prologue6880 (let ((arity (compiland-arity compiland)))6881 (when arity6882 (generate-arg-count-check arity)))6883 6884 (when *hairy-arglist-p*6885 (aload 0) ; this6886 (aver (not (null (compiland-argument-register compiland))))6887 (aload (compiland-argument-register compiland)) ; arg vector6888 (cond ((or (memq '&OPTIONAL args) (memq '&KEY args))6889 (ensure-thread-var-initialized)6890 (maybe-initialize-thread-var)6891 (emit-push-current-thread)6892 (emit-invokevirtual *this-class* "processArgs"6893 (list +lisp-object-array+ +lisp-thread+)6894 +lisp-object-array+))6895 (t6896 (emit-invokevirtual *this-class* "fastProcessArgs"6897 (list +lisp-object-array+)6898 +lisp-object-array+)))6899 (astore (compiland-argument-register compiland)))6900 6901 (unless (and *hairy-arglist-p*6902 (or (memq '&OPTIONAL args) (memq '&KEY args)))6903 (maybe-initialize-thread-var))6904 6905 (setf prologue *code*6906 *code* ())6907 ;;;;6908 6782 6909 6783 (when *using-arg-array* … … 7050 6924 7051 6925 ;; Go back and fill in prologue. 7052 #+nil(let ((code *code*))6926 (let ((code *code*)) 7053 6927 (setf *code* ()) 7054 6928 (let ((arity (compiland-arity compiland))) … … 7077 6951 (maybe-initialize-thread-var)) 7078 6952 (setf *code* (nconc code *code*))) 7079 7080 (setf *code* (nconc prologue *code*))7081 7082 (setf (abcl-class-file-superclass class-file)7083 (if (or *hairy-arglist-p*7084 (and *child-p* *closure-variables*))7085 +lisp-compiled-closure+7086 +lisp-primitive+))7087 6953 7088 6954 (setf (abcl-class-file-lambda-list class-file) args) … … 7133 6999 7134 7000 (with-class-file (compiland-class-file compiland) 7135 (make-constructor *class-file*)7136 7001 (with-saved-compiler-policy 7137 7002 (p2-compiland compiland) … … 7375 7240 progn)) 7376 7241 (install-p2-handler '%ldb 'p2-%ldb) 7377 (install-p2-handler '%make-structure 'p2-%make-structure)7378 7242 (install-p2-handler '* 'p2-times) 7379 7243 (install-p2-handler '+ 'p2-plus) … … 7430 7294 (install-p2-handler 'lognot 'p2-lognot) 7431 7295 (install-p2-handler 'logxor 'p2-logxor) 7432 (install-p2-handler 'make-array 'p2-make-array)7433 (install-p2-handler 'make-hash-table 'p2-make-hash-table)7434 (install-p2-handler 'make-sequence 'p2-make-sequence)7435 (install-p2-handler 'make-string 'p2-make-string)7436 (install-p2-handler 'make-structure 'p2-make-structure)7437 7296 (install-p2-handler 'max 'p2-min/max) 7438 7297 (install-p2-handler 'memq 'p2-memq) … … 7495 7354 (values (compile nil function))))) 7496 7355 7497 (setf sys:*enable-autocompile* t)7356 (setf sys:*enable-autocompile* nil) 7498 7357 7499 7358 (provide "COMPILER-PASS2") -
branches/invokedynamic/abcl/src/org/armedbear/lisp/jvm-class-file.lisp
r12983 r12984 230 230 (princ #\) s) 231 231 (princ ret-string s)) 232 ;(sys::%format t "descriptor ~S ~S -> ~S~%" return-type argument-types str) 232 233 str) 233 234 ;; (format nil "(~{~A~})~A" … … 356 357 make-constant-name/type (index 357 358 name 359 type 358 360 descriptor)) 359 361 (:include constant … … 362 364 constant pool; this type of element is used by 'member-ref' type items." 363 365 name 366 type 364 367 descriptor) 365 368 … … 494 497 (let ((n (pool-add-utf8 pool name)) 495 498 (i-t (pool-add-utf8 pool internal-type))) 496 (setf entry (make-constant-name/type (incf (pool-index pool)) n i-t) 499 (setf entry (make-constant-name/type 500 (incf (pool-index pool)) n type i-t) 497 501 (gethash (cons name type) (pool-entries pool)) entry)) 498 502 (push entry (pool-entries-list pool))) … … 757 761 ((5 6) (sys::%format t "d/l: ~a~%" (constant-double/long-value entry))) 758 762 ((9 10 11) (sys::%format t "ref: ~a,~a~%" 759 (constant-member-ref-class -indexentry)763 (constant-member-ref-class entry) 760 764 (constant-member-ref-name/type entry))) 761 765 (12 (sys::%format t "n/t: ~a,~a~%" … … 977 981 ;; these are used for handling nested WITH-CODE-TO-METHOD blocks 978 982 (current-local 0) 979 computed-locals 980 computed-stack) 983 computed-locals) 981 984 982 985 … … 1011 1014 (multiple-value-bind 1012 1015 (c labels stack-map-table) 1013 (resolve-code c class parent compute-stack-map-table-p)1016 (resolve-code code c class parent compute-stack-map-table-p) 1014 1017 (setf (code-code code) c 1015 1018 (code-labels code) labels) … … 1090 1093 (code-exception-handlers code))) 1091 1094 1092 (defun resolve-code (code class method compute-stack-map-table-p)1095 (defun resolve-code (code-attr code class method compute-stack-map-table-p) 1093 1096 "Walks the code, replacing symbolic labels with numeric offsets, and optionally computing the stack map table." 1094 1097 (declare (ignore class)) 1095 1098 (let* ((length 0) 1096 1099 labels ;; alist 1097 stack-map-table) 1100 stack-map-table 1101 (computing-stack-map-table compute-stack-map-table-p) 1102 (*code-locals* (code-computed-locals code-attr)) 1103 *code-stack*) 1098 1104 #|| (*basic-block* (when compute-stack-map-table-p 1099 1105 (make-basic-block … … 1103 1109 (root-block *basic-block*) 1104 1110 *basic-blocks*)||# 1105 compute-stack-map-table-p :todo1106 1111 (declare (type (unsigned-byte 16) length)) 1107 ;; Pass 1: calculate label offsets and overall length. 1112 ;; Pass 1: calculate label offsets and overall length and, if 1113 ;; compute-stack-map-table-p is true, also simulate the effect of the 1114 ;; instructions on the stack and locals. 1108 1115 (dotimes (i (length code)) 1109 1116 (declare (type (unsigned-byte 16) i)) … … 1111 1118 (opcode (instruction-opcode instruction))) 1112 1119 (setf (instruction-offset instruction) length) 1120 ;;(sys::format t "simulating instruction ~S ~S stack ~S locals ~S ~%" 1121 ;;opcode (mapcar #'type-of (instruction-args instruction)) 1122 ;;(length *code-stack*) (length *code-locals*)) 1123 (if computing-stack-map-table 1124 (progn 1125 (when (= opcode 202) ;;label: simulate a jump 1126 (record-jump-to-label (car (instruction-args instruction)))) 1127 (simulate-instruction-effect instruction) 1128 ;;Simulation must be stopped if we encounter a goto, it will be 1129 ;;resumed by the next label that is the target of a jump 1130 (setf computing-stack-map-table (not (unconditional-jump-p opcode)))) 1131 (when (and (= opcode 202) ; LABEL 1132 (get (first (instruction-args instruction)) 1133 'jump-target-p)) 1134 (simulate-instruction-effect instruction) 1135 (setf computing-stack-map-table t))) 1113 1136 (if (= opcode 202) ; LABEL 1114 1137 (let ((label (car (instruction-args instruction)))) … … 1128 1151 (symbol-value (the symbol label))) 1129 1152 index))) 1153 (unless (get label 'jump-target-p) 1154 (sys::%format "error - label not target of a jump ~S~%" label)) 1130 1155 (setf (instruction-args instruction) (s2 offset)))) 1131 1156 (unless (= (instruction-opcode instruction) 202) ; LABEL … … 1142 1167 (incf index) 1143 1168 (dolist (arg (instruction-args instruction)) 1144 (setf (svref bytes index) 1145 (if (constant-p arg) (constant-index arg) arg)) 1146 (incf index))))) 1169 (if (constant-p arg) 1170 (let ((idx (constant-index arg)) 1171 (opcode (instruction-opcode instruction))) 1172 ;;(sys::%format t "constant ~A ~A index-size ~A index ~A~%" (type-of arg) idx (constant-index-size arg) index) 1173 (if (or (<= 178 opcode 187) 1174 (= opcode 189) 1175 (= opcode 192) 1176 (= opcode 193)) 1177 (let ((idx (u2 idx))) 1178 (setf (svref bytes index) (car idx) 1179 (svref bytes (1+ index)) (cadr idx)) 1180 (incf index 2)) 1181 (progn 1182 (setf (svref bytes index) idx) 1183 (incf index)))) 1184 (progn 1185 (setf (svref bytes index) arg) 1186 (incf index))))))) 1187 (sys::%format t "~%~%~%BYTES ~S~%~%~%" bytes) 1147 1188 (values bytes labels stack-map-table)))) 1148 1189 1149 (defun ends-basic-block-p (opcode) 1150 (or (branch-p opcode) 1151 (>= 172 opcode 177))) ;;return variants 1190 (defun unconditional-jump-p (opcode) 1191 (= opcode 167)) 1152 1192 1153 1193 (defstruct exception … … 1235 1275 (*pool* (class-file-constants ,class-file)) 1236 1276 (*code* (code-code ,c)) 1237 (*code-locals* (code-computed-locals ,c))1238 (*code-stack* (code-computed-stack ,c))1239 1277 (*registers-allocated* (code-max-locals ,c)) 1240 1278 (*register* (code-current-local ,c)) … … 1243 1281 (setf (code-code ,c) *code* 1244 1282 (code-current-local ,c) *register* 1245 (code-max-locals ,c) *registers-allocated* 1246 (code-computed-locals ,c) *code-locals* 1247 (code-computed-stack ,c) *code-stack*)) 1283 (code-max-locals ,c) *registers-allocated*)) 1248 1284 (when *current-code-attribute* 1249 1285 (restore-code-specials *current-code-attribute*))))) -
branches/invokedynamic/abcl/src/org/armedbear/lisp/jvm-instructions.lisp
r12983 r12984 61 61 (declare (ignorable instruction)) 62 62 ,@body)))) 63 64 (defun record-jump-to-label (label) 65 "Records a jump to a label appearing further down in the code." 66 ;;TODO: check that multiple jumps are compatible 67 (setf (get label 'jump-target-p) 68 t 69 (get label '*code-locals*) 70 *code-locals* 71 (get label '*code-stack*) 72 *code-stack*)) 63 73 64 74 ;; name number size stack-effect (nil if unknown) … … 126 136 (defun iaf-store-effect (arg) 127 137 (let ((t1 (smf-pop))) 128 (sys::%format t "iaf-store ~S~%" (list arg t1))129 138 (smf-set arg t1) 130 139 (when (> arg 0) … … 261 270 (define-opcode lxor 131 1 -2 (smf-popn 4) (smf-push :long)) 262 271 (define-opcode iinc 132 3 0 263 (sys::%format t "AAAAAAAAAAAA ~A~%" (instruction-args instruction))264 272 (smf-set (car (instruction-args instruction)) :int)) 265 273 (define-opcode i2l 133 1 1 (smf-pop) (smf-push :long)) … … 283 291 (define-opcode dcmpl 151 1 -3 (smf-popn 4) (smf-push :int)) 284 292 (define-opcode dcmpg 152 1 -3 (smf-popn 4) (smf-push :int)) 285 (define-opcode ifeq 153 3 -1 (smf-pop)) 286 (define-opcode ifne 154 3 -1 (smf-pop)) 287 (define-opcode iflt 155 3 -1 (smf-pop)) 288 (define-opcode ifge 156 3 -1 (smf-pop)) 289 (define-opcode ifgt 157 3 -1 (smf-pop)) 290 (define-opcode ifle 158 3 -1 (smf-pop)) 293 (define-opcode ifeq 153 3 -1 294 (smf-pop) 295 (record-jump-to-label (first (instruction-args instruction)))) 296 (define-opcode ifne 154 3 -1 297 (smf-pop) 298 (record-jump-to-label (first (instruction-args instruction)))) 299 (define-opcode iflt 155 3 -1 300 (smf-pop) 301 (record-jump-to-label (first (instruction-args instruction)))) 302 (define-opcode ifge 156 3 -1 303 (smf-pop) 304 (record-jump-to-label (first (instruction-args instruction)))) 305 (define-opcode ifgt 157 3 -1 306 (smf-pop) 307 (record-jump-to-label (first (instruction-args instruction)))) 308 (define-opcode ifle 158 3 -1 309 (smf-pop) 310 (record-jump-to-label (first (instruction-args instruction)))) 291 311 (define-opcode if_icmpeq 159 3 -2 (smf-popn 2)) 292 312 (define-opcode if_icmpne 160 3 -2 (smf-popn 2)) … … 297 317 (define-opcode if_acmpeq 165 3 -2 (smf-popn 2)) 298 318 (define-opcode if_acmpne 166 3 -2 (smf-popn 2)) 299 (define-opcode goto 167 3 0) 319 (define-opcode goto 167 3 0 320 (record-jump-to-label (first (instruction-args instruction)))) 300 321 ;;(define-opcode jsr 168 3 1) Don't use these 2 opcodes: deprecated 301 322 ;;(define-opcode ret 169 2 0) their use results in JVM verifier errors … … 309 330 (define-opcode return 177 1 0) 310 331 (define-opcode getstatic 178 3 1 311 (sys::%format t "GETSTATIC ~A~%" (third (instruction-args instruction))) 312 ;;TODO!!! 313 (smf-push (third (instruction-args instruction)))) 332 (let ((field-type 333 (constant-name/type-type 334 (constant-member-ref-name/type (first (instruction-args instruction)))))) 335 (smf-push field-type))) 314 336 (define-opcode putstatic 179 3 -1 315 (sys::%format t "PUTSTATIC ~A~%" (third (instruction-args instruction))) 316 (smf-popt (third (instruction-args instruction)))) 337 (let ((field-type 338 (constant-name/type-type 339 (constant-member-ref-name/type (first (instruction-args instruction)))))) 340 (smf-popt field-type))) 317 341 (define-opcode getfield 180 3 0 318 342 (smf-pop) 319 (smf-push (third (instruction-args instruction)))) 343 (let ((field-type 344 (constant-name/type-type 345 (constant-member-ref-name/type (first (instruction-args instruction)))))) 346 (smf-push field-type))) 320 347 (define-opcode putfield 181 3 -2 321 (smf-popt (third (instruction-args instruction))) 348 (let ((field-type 349 (constant-name/type-type 350 (constant-member-ref-name/type (first (instruction-args instruction)))))) 351 (smf-popt field-type)) 322 352 (smf-pop)) 323 353 (define-opcode invokevirtual 182 3 nil 324 (smf-popt (third (instruction-args instruction))) 325 (smf-pop) 326 (smf-push (third (instruction-args instruction)))) 354 (let ((method-return-and-arg-types 355 (constant-name/type-type 356 (constant-member-ref-name/type (first (instruction-args instruction)))))) 357 ;;(sys::%format t "invokevirtual ~S~%" method-return-and-arg-types) 358 (map nil #'smf-popt (cdr method-return-and-arg-types)) 359 (smf-pop) 360 (smf-push (car method-return-and-arg-types)))) 327 361 (define-opcode invokespecial 183 3 nil 328 (smf-popt (third (instruction-args instruction))) 329 (smf-pop) 330 (smf-push (third (instruction-args instruction)))) 362 (let ((method-return-and-arg-types 363 (constant-name/type-type 364 (constant-member-ref-name/type (first (instruction-args instruction)))))) 365 ;;(sys::%format t "invokespecial ~S~%" method-return-and-arg-types) 366 (map nil #'smf-popt (cdr method-return-and-arg-types)) 367 (smf-pop) 368 (smf-push (car method-return-and-arg-types)))) 331 369 (define-opcode invokestatic 184 3 nil 332 (sys::%format t "invokestatic ~S~%" (instruction-args instruction)) 333 (smf-popt (third (instruction-args instruction))) 334 (smf-push (third (instruction-args instruction)))) 370 (let ((method-return-and-arg-types 371 (constant-name/type-type 372 (constant-member-ref-name/type (first (instruction-args instruction)))))) 373 ;;(sys::%format t "invokestatic ~S~%" method-return-and-arg-types) 374 (map nil #'smf-popt (cdr method-return-and-arg-types)) 375 (smf-push (car method-return-and-arg-types)))) 335 376 (define-opcode invokeinterface 185 5 nil 336 377 (smf-popt (third (instruction-args instruction))) … … 366 407 (define-opcode goto_w 200 5 nil) 367 408 ;; (define-opcode jsr_w 201 5 nil) Don't use: deprecated 368 (define-opcode label 202 0 0) ;; virtual: does not exist in the JVM 409 (define-opcode label 202 0 0 ;; virtual: does not exist in the JVM 410 (if (get (first (instruction-args instruction)) 'jump-target-p) 411 ;;This label is the target of a jump emitted earlier 412 (setf *code-locals* 413 (get (first (instruction-args instruction)) '*code-locals*) 414 *code-stack* 415 (get (first (instruction-args instruction)) '*code-stack*)) 416 ;;Else simulate a jump to self to store locals and stack 417 (record-jump-to-label (first (instruction-args instruction))))) 369 418 ;; (define-opcode push-value 203 nil 1) 370 419 ;; (define-opcode store-value 204 nil -1) … … 411 460 412 461 (defun smf-set (pos type) 462 (when (null type) 463 (sys::%format t "smf-set null! pos ~A ~S~%" pos 42 #+nil(subseq (sys::backtrace-as-list) 2 10))) 413 464 (if (< pos (length *code-locals*)) 414 465 (setf (nth pos *code-locals*) type) … … 424 475 425 476 (defun smf-pop () 426 ;(sys::%format t "smf-pop ~A~%" *code-stack*)427 477 (pop *code-stack*)) 428 478 429 479 (defun smf-popt (type) 430 (declare (ignore type)) ;TODO 431 (pop *code-stack*)) 480 (pop *code-stack*) 481 (when (or (eq type :long) (eq type :double)) ;TODO 482 (pop *code-stack*))) 432 483 433 484 (defun smf-popn (n) … … 466 517 (when (memq :wide-prefix args) 467 518 (setf (inst-wide inst) t)) 468 (setf (instruction-input-locals inst) *code-locals*)469 (setf (instruction-input-stack inst) *code-stack*)470 519 inst)) 471 520 … … 523 572 (symbolp (cadr instr))) 524 573 (setf instr (opcode-number (cadr instr)))) 525 ( let ((instruction (gensym)))526 `(let ((,instruction527 ,(if (fixnump instr)528 `(%%emit ,instr ,@args) 529 `(%emit ,instr ,@args))))530 ;(sys::%format t "EMIT ~S ~S~%" ',instr ',args)531 (funcall (opcode-effect-function (instruction-opcode ,instruction))532 ,instruction)533 (setf (instruction-output-locals ,instruction) *code-locals*)534 (setf (instruction-output-stack ,instruction) *code-stack*)535 ,instruction)))536 574 (if (fixnump instr) 575 `(%%emit ,instr ,@args) 576 `(%emit ,instr ,@args))) 577 578 (defun simulate-instruction-effect (instruction) 579 (setf (instruction-input-locals instruction) *code-locals*) 580 (setf (instruction-input-stack instruction) *code-stack*) 581 (funcall (opcode-effect-function (instruction-opcode instruction)) 582 instruction) 583 (setf (instruction-output-locals instruction) *code-locals*) 584 (setf (instruction-output-stack instruction) *code-stack*) 585 instruction) 537 586 538 587 ;; Helper routines … … 620 669 (inst 'aload (car (instruction-args instruction))) 621 670 (inst 'aconst_null) 622 (inst 'putfield (u2 (constant-index 623 (pool-field +lisp-thread+ "_values" 624 +lisp-object-array+)))))) 671 (inst 'putfield (pool-field +lisp-thread+ "_values" 672 +lisp-object-array+)))) 625 673 (vector-push-extend instruction vector))) 626 674 (t
Note: See TracChangeset
for help on using the changeset viewer.