Changeset 11497


Ignore:
Timestamp:
12/28/08 20:47:22 (12 years ago)
Author:
ehuelsmann
Message:

Factor out some code to load a local variable onto the stack.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/compiler-pass2.lisp

    r11494 r11497  
    434434  (emit 'aload *thread*))
    435435
     436(defun local-variable-p (variable)
     437  "Return non-NIL if `variable' is a local variable.
     438
     439Special variables are not considered local."
     440  (or (variable-register variable) ;; either register or index
     441      (variable-index variable)))  ;; is non-nil for local variables
     442
     443(defun emit-load-local-variable (variable)
     444  "Loads a local variable in the top stack position."
     445  (aver (local-variable-p variable))
     446  (if (variable-register variable)
     447      (emit 'aload (variable-register variable))
     448      (progn
     449        (emit 'aload (compiland-argument-register *current-compiland*))
     450        (emit-push-constant-int (variable-index variable))
     451        (emit 'aaload))))
     452
    436453(defknown generate-instanceof-type-check-for-variable (t t) t)
    437454(defun generate-instanceof-type-check-for-variable (variable expected-type)
     455  "Generate a type check for `variable'.
     456
     457The stack pointer is returned to the position from
     458before the emitted code: the code is 'stack-neutral'."
    438459  (declare (type symbol expected-type))
     460  (unless (local-variable-p variable)
     461    (return-from generate-instanceof-type-check-for-variable))
    439462  (let ((instanceof-class (ecase expected-type
    440463                            (SYMBOL     +lisp-symbol-class+)
     
    450473                                          (t
    451474                                           (symbol-name expected-type))))
    452         (LABEL1 (gensym))
    453         register
    454         index)
    455     (cond ((setf register (variable-register variable))
    456            (emit 'aload register)
    457            (emit 'instanceof instanceof-class)
    458            (emit 'ifne LABEL1)
    459            (emit 'aload register)) ; datum
    460           ((setf index (variable-index variable))
    461            (let ((argument-register (compiland-argument-register *current-compiland*)))
    462              (aver (not (null argument-register)))
    463              (emit 'aload argument-register)
    464              (emit-push-constant-int index)
    465              (emit 'aaload)
    466              (emit 'instanceof instanceof-class)
    467              (emit 'ifne LABEL1)
    468              (emit 'aload argument-register)
    469              (emit-push-constant-int index)
    470              (emit 'aaload))) ; datum
    471           (t
    472            (return-from generate-instanceof-type-check-for-variable)))
    473     (emit 'getstatic +lisp-symbol-class+ expected-type-java-symbol-name +lisp-symbol+)
     475        (LABEL1 (gensym)))
     476    (emit-load-variable variable)
     477    (emit 'instanceof instanceof-class)
     478    (emit 'ifne LABEL1)
     479    (emit-load-variable variable)
     480    (emit 'getstatic +lisp-symbol-class+ expected-type-java-symbol-name
     481          +lisp-symbol+)
    474482    (emit-invokestatic +lisp-class+ "type_error"
    475483                       (lisp-object-arg-types 2) +lisp-object+)
Note: See TracChangeset for help on using the changeset viewer.