Changeset 11866
- Timestamp:
- 05/15/09 09:30:10 (14 years ago)
- Location:
- trunk/abcl/src/org/armedbear/lisp
- Files:
-
- 4 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/abcl/src/org/armedbear/lisp/ClosureTemplateFunction.java
r11711 r11866 38 38 { 39 39 40 public LispObject[] ctx;40 public ClosureBinding[] ctx; 41 41 42 42 public ClosureTemplateFunction(LispObject lambdaList) … … 46 46 } 47 47 48 final public ClosureTemplateFunction setContext( LispObject[] context)48 final public ClosureTemplateFunction setContext(ClosureBinding[] context) 49 49 { 50 50 ctx = context; … … 157 157 158 158 // Zero args. 159 public LispObject _execute( LispObject[] context) throws ConditionThrowable159 public LispObject _execute(ClosureBinding[] context) throws ConditionThrowable 160 160 { 161 161 LispObject[] args = new LispObject[0]; … … 164 164 165 165 // One arg. 166 public LispObject _execute( LispObject[] context, LispObject first)166 public LispObject _execute(ClosureBinding[] context, LispObject first) 167 167 throws ConditionThrowable 168 168 { … … 173 173 174 174 // Two args. 175 public LispObject _execute( LispObject[] context, LispObject first,175 public LispObject _execute(ClosureBinding[] context, LispObject first, 176 176 LispObject second) 177 177 throws ConditionThrowable … … 184 184 185 185 // Three args. 186 public LispObject _execute( LispObject[] context, LispObject first,186 public LispObject _execute(ClosureBinding[] context, LispObject first, 187 187 LispObject second, LispObject third) 188 188 throws ConditionThrowable … … 196 196 197 197 // Four args. 198 public LispObject _execute( LispObject[] context, LispObject first,198 public LispObject _execute(ClosureBinding[] context, LispObject first, 199 199 LispObject second, LispObject third, 200 200 LispObject fourth) … … 210 210 211 211 // Five args. 212 public LispObject _execute( LispObject[] context, LispObject first,212 public LispObject _execute(ClosureBinding[] context, LispObject first, 213 213 LispObject second, LispObject third, 214 214 LispObject fourth, LispObject fifth) … … 225 225 226 226 // Six args. 227 public LispObject _execute( LispObject[] context, LispObject first,227 public LispObject _execute(ClosureBinding[] context, LispObject first, 228 228 LispObject second, LispObject third, 229 229 LispObject fourth, LispObject fifth, … … 242 242 243 243 // Seven args. 244 public LispObject _execute( LispObject[] context, LispObject first,244 public LispObject _execute(ClosureBinding[] context, LispObject first, 245 245 LispObject second, LispObject third, 246 246 LispObject fourth, LispObject fifth, … … 260 260 261 261 // Eight args. 262 public LispObject _execute( LispObject[] context, LispObject first,262 public LispObject _execute(ClosureBinding[] context, LispObject first, 263 263 LispObject second, LispObject third, 264 264 LispObject fourth, LispObject fifth, … … 280 280 281 281 // Arg array. 282 public LispObject _execute( LispObject[] context, LispObject[] args)282 public LispObject _execute(ClosureBinding[] context, LispObject[] args) 283 283 throws ConditionThrowable 284 284 { -
trunk/abcl/src/org/armedbear/lisp/CompiledClosure.java
r11514 r11866 37 37 { 38 38 private final ClosureTemplateFunction ctf; 39 private final LispObject[] context;39 private final ClosureBinding[] context; 40 40 41 public CompiledClosure(ClosureTemplateFunction ctf, LispObject[] context)41 public CompiledClosure(ClosureTemplateFunction ctf, ClosureBinding[] context) 42 42 { 43 43 super(ctf.getLambdaName(), ctf.getLambdaList()); -
trunk/abcl/src/org/armedbear/lisp/Lisp.java
r11777 r11866 1187 1187 1188 1188 public static final LispObject makeCompiledClosure(LispObject template, 1189 LispObject[] context)1189 ClosureBinding[] context) 1190 1190 throws ConditionThrowable 1191 1191 { -
trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp
r11857 r11866 206 206 (defconstant +lisp-object+ "Lorg/armedbear/lisp/LispObject;") 207 207 (defconstant +lisp-object-array+ "[Lorg/armedbear/lisp/LispObject;") 208 (defconstant +closure-binding-array+ "[Lorg/armedbear/lisp/ClosureBinding;") 209 (defconstant +closure-binding+ "Lorg/armedbear/lisp/ClosureBinding;") 210 (defconstant +closure-binding-class+ "org/armedbear/lisp/ClosureBinding") 208 211 (defconstant +lisp-symbol-class+ "org/armedbear/lisp/Symbol") 209 212 (defconstant +lisp-symbol+ "Lorg/armedbear/lisp/Symbol;") … … 2989 2992 (emit-move-from-stack target)) 2990 2993 2991 (defun save-variables (variables) 2992 (let ((saved-vars '())) 2993 (dolist (variable variables) 2994 (when (variable-closure-index variable) 2995 (let ((register (allocate-register))) 2996 (aload (compiland-closure-register *current-compiland*)) 2997 (emit-push-constant-int (variable-closure-index variable)) 2998 (emit 'aaload) 2999 (astore register) 3000 (push (cons variable register) saved-vars)))) 3001 saved-vars)) 3002 3003 (defun restore-variables (saved-vars) 3004 (dolist (saved-var saved-vars) 3005 (let ((variable (car saved-var)) 3006 (register (cdr saved-var))) 3007 (aload (compiland-closure-register *current-compiland*)) 3008 (emit-push-constant-int (variable-closure-index variable)) 3009 (aload register) 3010 (emit 'aastore)))) 2994 2995 (defun duplicate-closure-array (compiland) 2996 (let* ((*register* *register*) 2997 (register (allocate-register))) 2998 (aload (compiland-closure-register compiland)) ;; src 2999 (emit-push-constant-int 0) ;; srcPos 3000 (emit-push-constant-int (length *closure-variables*)) 3001 (emit 'anewarray "org/armedbear/lisp/ClosureBinding") ;; dest 3002 (emit 'dup) 3003 (astore register) ;; save dest value 3004 (emit-push-constant-int 0) ;; destPos 3005 (emit-push-constant-int (length *closure-variables*)) ;; length 3006 (emit-invokestatic "java/lang/System" "arraycopy" 3007 (list "Ljava/lang/Object;" "I" 3008 "Ljava/lang/Object;" "I" "I") nil) 3009 (aload register))) ;; reload dest value 3010 3011 3011 3012 3012 3013 (defknown compile-local-function-call (t t t) t) … … 3020 3021 (args (cdr form)) 3021 3022 (local-function (find-local-function op)) 3022 (*register* *register*) 3023 (saved-vars '()) 3024 (label-START (gensym)) 3025 (label-END (gensym)) 3026 (label-EXIT (gensym))) 3023 (*register* *register*)) 3027 3024 (cond ((local-function-variable local-function) 3028 3025 ;; LABELS 3029 3026 (dformat t "compile-local-function-call LABELS case variable = ~S~%" 3030 3027 (variable-name (local-function-variable local-function))) 3031 (unless (null (compiland-parent compiland))3032 (setf saved-vars3033 (save-variables (intersection3034 (compiland-arg-vars (local-function-compiland local-function))3035 *visible-variables*))))3036 ;; (emit 'var-ref (local-function-variable local-function) 'stack)3037 (when saved-vars3038 (label label-START))3039 3028 (compile-var-ref (make-var-ref (local-function-variable local-function)) 'stack nil)) 3040 3029 (t … … 3046 3035 (when *closure-variables* 3047 3036 (emit 'checkcast +lisp-ctf-class+) 3048 ( aload (compiland-closure-register compiland))3037 (duplicate-closure-array compiland) 3049 3038 (emit-invokestatic +lisp-class+ "makeCompiledClosure" 3050 (list +lisp-object+ + lisp-object-array+)3039 (list +lisp-object+ +closure-binding-array+) 3051 3040 +lisp-object+))))) 3052 3041 (process-args args) 3053 3042 (emit-call-execute (length args)) 3054 3043 (fix-boxing representation nil) 3055 (emit-move-from-stack target representation) 3056 (when saved-vars 3057 (emit 'goto label-EXIT) 3058 (label label-END) 3059 (restore-variables saved-vars) 3060 (emit 'athrow) 3061 (label label-EXIT) 3062 (restore-variables saved-vars) 3063 (push (make-handler :from label-START 3064 :to label-END 3065 :code label-END 3066 :catch-type 0) *handlers*))) 3044 (emit-move-from-stack target representation)) 3067 3045 t) 3068 3046 … … 3919 3897 (emit-invokevirtual +lisp-thread-class+ "bindSpecial" 3920 3898 (list +lisp-symbol+ +lisp-object+) nil)) 3921 ((variable-closure-index variable) 3899 ((variable-closure-index variable) ;; stack: 3900 (emit 'new "org/armedbear/lisp/ClosureBinding") ;; value c-b 3901 (emit 'dup_x1) ;; c-b value c-b 3902 (emit 'swap) ;; c-b c-b value 3903 (emit-invokespecial-init "org/armedbear/lisp/ClosureBinding" 3904 (list +lisp-object+)) ;; c-b 3922 3905 (aload (compiland-closure-register *current-compiland*)) 3923 (emit 'swap) ; array value 3906 ;; c-b array 3907 (emit 'swap) ;; array c-b 3924 3908 (emit-push-constant-int (variable-closure-index variable)) 3909 ;; array c-b int 3925 3910 (emit 'swap) ; array index value 3926 3911 (emit 'aastore)) … … 4196 4181 ((variable-closure-index variable) 4197 4182 (aload (compiland-closure-register *current-compiland*)) 4183 (emit-push-constant-int (variable-closure-index variable)) 4184 (emit 'aaload) 4198 4185 (emit-swap representation nil) 4199 (emit-push-constant-int (variable-closure-index variable)) 4200 (emit-swap representation :int) 4201 (emit-array-store (variable-representation variable))) 4186 (emit 'putfield "org/armedbear/lisp/ClosureBinding" "value" 4187 "Lorg/armedbear/lisp/LispObject;")) 4202 4188 (t 4203 4189 ;;###FIXME: We might want to address the "temp-register" case too. … … 4205 4191 4206 4192 (defun emit-push-variable (variable) 4207 (flet ((emit-array- store(representation)4193 (flet ((emit-array-load (representation) 4208 4194 (emit (ecase representation 4209 4195 ((:int :boolean :char) … … 4225 4211 (aload (compiland-argument-register *current-compiland*)) 4226 4212 (emit-push-constant-int (variable-index variable)) 4227 (emit-array- store(variable-representation variable)))4213 (emit-array-load (variable-representation variable))) 4228 4214 ((variable-closure-index variable) 4229 4215 (aload (compiland-closure-register *current-compiland*)) 4230 4216 (emit-push-constant-int (variable-closure-index variable)) 4231 (emit-array-store (variable-representation variable))) 4217 (emit 'aaload) 4218 (emit 'getfield "org/armedbear/lisp/ClosureBinding" "value" 4219 "Lorg/armedbear/lisp/LispObject;")) 4232 4220 (t ;;###FIXME: We might want to address the "temp-register" case too. 4233 4221 (assert nil))))) … … 4868 4856 (compiland-closure-register parent)) 4869 4857 (emit 'checkcast +lisp-ctf-class+) 4870 ( aload (compiland-closure-register parent))4858 (duplicate-closure-array parent) 4871 4859 (emit-invokestatic +lisp-class+ "makeCompiledClosure" 4872 (list +lisp-object+ + lisp-object-array+)4860 (list +lisp-object+ +closure-binding-array+) 4873 4861 +lisp-object+))) 4874 4862 (emit-move-to-variable (local-function-variable local-function))) … … 5016 5004 (cond ((null *closure-variables*)) ; Nothing to do. 5017 5005 ((compiland-closure-register *current-compiland*) 5018 ( aload (compiland-closure-register *current-compiland*))5006 (duplicate-closure-array *current-compiland*) 5019 5007 (emit-invokestatic +lisp-class+ "makeCompiledClosure" 5020 (list +lisp-object+ + lisp-object-array+)5008 (list +lisp-object+ +closure-binding-array+) 5021 5009 +lisp-object+) 5022 5010 (emit 'checkcast +lisp-compiled-closure-class+)) ; Stack: compiled-closure … … 5048 5036 (when (compiland-closure-register *current-compiland*) 5049 5037 (emit 'checkcast +lisp-ctf-class+) 5050 ( aload (compiland-closure-register *current-compiland*))5038 (duplicate-closure-array *current-compiland*) 5051 5039 (emit-invokestatic +lisp-class+ "makeCompiledClosure" 5052 (list +lisp-object+ + lisp-object-array+)5040 (list +lisp-object+ +closure-binding-array+) 5053 5041 +lisp-object+))))) 5054 5042 (emit-move-from-stack target)) … … 7887 7875 (return-from analyze-args 7888 7876 (if *closure-variables* 7889 (get-descriptor (list +lisp-object-array+ +lisp-object-array+) 7890 +lisp-object+) 7877 (get-descriptor (list +closure-binding-array+ 7878 +lisp-object-array+) 7879 +lisp-object+) 7891 7880 (get-descriptor (list +lisp-object-array+) 7892 7881 +lisp-object+)))) 7893 7882 (cond (*closure-variables* 7894 7883 (return-from analyze-args 7895 7884 (cond ((<= arg-count call-registers-limit) 7896 (get-descriptor (list* + lisp-object-array+7885 (get-descriptor (list* +closure-binding-array+ 7897 7886 (lisp-object-arg-types arg-count)) 7898 7887 +lisp-object+)) 7899 7888 (t (setf *using-arg-array* t) 7900 7889 (setf (compiland-arity compiland) arg-count) 7901 (get-descriptor (list + lisp-object-array+ +lisp-object-array+) ;; FIXME7890 (get-descriptor (list +closure-binding-array+ +lisp-object-array+) ;; FIXME 7902 7891 +lisp-object+))))) 7903 7892 (t … … 8033 8022 (closure-args (intersection *closure-variables* 8034 8023 (compiland-arg-vars compiland))) 8024 (local-closure-vars 8025 (find compiland *closure-variables* :key #'variable-compiland)) 8035 8026 (body (cddr p1-result)) 8036 8027 (*using-arg-array* nil) … … 8094 8085 (compiland-closure-register compiland))) 8095 8086 8087 (when *closure-variables* 8088 (cond 8089 ((not *child-p*) 8090 ;; if we're the ultimate parent: create the closure array 8091 (emit-push-constant-int (length *closure-variables*)) 8092 (emit 'anewarray "org/armedbear/lisp/ClosureBinding")) 8093 (local-closure-vars 8094 (duplicate-closure-array compiland)))) 8095 8096 8096 ;; Move args from their original registers to the closure variables array 8097 8097 (when (or closure-args … … 8099 8099 (dformat t "~S moving arguments to closure array~%" 8100 8100 (compiland-name compiland)) 8101 (cond (*child-p* 8102 (aver (eql (compiland-closure-register compiland) 1)) 8103 (aload (compiland-closure-register compiland))) 8104 (t ;; if we're the ultimate parent: create the closure array 8105 (emit-push-constant-int (length *closure-variables*)) 8106 (dformat t "p2-compiland ~S anewarray 1~%" 8107 (compiland-name compiland)) 8108 (emit 'anewarray "org/armedbear/lisp/LispObject"))) 8109 (dolist (variable closure-args) 8110 (dformat t "moving variable ~S~%" (variable-name variable)) 8111 (cond ((variable-register variable) 8101 (dotimes (i (length *closure-variables*)) 8102 ;; Loop over all slots, setting their value 8103 ;; unconditionally if we're the parent creating it (using null 8104 ;; values if no real value is available) 8105 ;; or selectively if we're a child binding certain slots. 8106 (let ((variable (find i closure-args 8107 :key #'variable-closure-index 8108 :test #'eql))) 8109 (when (or (not *child-p*) variable) 8110 ;; we're the parent, or we have a variable to set. 8111 (emit 'dup) ; array 8112 (emit-push-constant-int i) 8113 (emit 'new "org/armedbear/lisp/ClosureBinding") 8114 (emit 'dup) 8115 (cond 8116 ((null variable) 8117 (assert (not *child-p*)) 8118 (emit 'aconst_null)) 8119 ((variable-register variable) 8112 8120 (assert (not (eql (variable-register variable) 8113 8121 (compiland-closure-register compiland)))) 8114 (emit 'dup) ; array8115 (emit-push-constant-int (variable-closure-index variable))8116 8122 (aload (variable-register variable)) 8117 (emit 'aastore)8118 8123 (setf (variable-register variable) nil)) 8119 8124 ((variable-index variable) 8120 (emit 'dup) ; array8121 (emit-push-constant-int (variable-closure-index variable))8122 8125 (aload (compiland-argument-register compiland)) 8123 8126 (emit-push-constant-int (variable-index variable)) 8124 8127 (emit 'aaload) 8125 (emit 'aastore) 8126 (setf (variable-index variable) nil)))) 8127 8128 (setf (variable-index variable) nil)) 8129 (t 8130 (assert (not "Can't happen!!")))) 8131 (emit-invokespecial-init "org/armedbear/lisp/ClosureBinding" 8132 (list +lisp-object+)) 8133 (emit 'aastore))))) 8134 8135 (when (or local-closure-vars (and *closure-variables* (not *child-p*))) 8128 8136 (aver (not (null (compiland-closure-register compiland)))) 8129 (cond (*child-p* 8130 (emit 'pop)) 8131 (t 8132 (astore (compiland-closure-register compiland)))) 8137 (astore (compiland-closure-register compiland)) 8133 8138 (dformat t "~S done moving arguments to closure array~%" 8134 8139 (compiland-name compiland)))
Note: See TracChangeset
for help on using the changeset viewer.