Changeset 11540


Ignore:
Timestamp:
01/04/09 16:44:21 (12 years ago)
Author:
vvoutilainen
Message:

Helper macro for defining inlining functions.

File:
1 edited

Legend:

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

    r11534 r11540  
    21222122    g))
    21232123
     2124     
    21242125(defknown compile-constant (t t t) t)
    21252126(defun compile-constant (form target representation)
     
    22732274  (install-p2-handler name 'p2-predicate))
    22742275
     2276(defmacro define-inlined-function (name params preamble-and-test &body body)
     2277  (let* ((test (second preamble-and-test))
     2278   (preamble (and test (first preamble-and-test)))
     2279   (test (or test (first preamble-and-test))))
     2280    `(defun ,name ,params
     2281       ,preamble
     2282       (unless ,test
     2283   (compile-function-call ,@params)
     2284   (return-from ,name))
     2285       ,@body)))
     2286
    22752287(defknown p2-predicate (t t t) t)
    2276 (defun p2-predicate (form target representation)
    2277   (unless (= (length form) 2)
    2278     (compile-function-call form target representation)
    2279     (return-from p2-predicate))
     2288(define-inlined-function p2-predicate (form target representation)
     2289  ((= (length form) 2))
    22802290  (let* ((op (car form))
    22812291         (info (gethash op *predicates*))
     
    24012411
    24022412(defknown p2-eq/neq (t t t) t)
    2403 (defun p2-eq/neq (form target representation)
    2404   (aver (or (null representation) (eq representation :boolean)))
    2405   (unless (check-arg-count form 2)
    2406     (compile-function-call form target representation)
    2407     (return-from p2-eq/neq))
     2413(define-inlined-function p2-eq/neq (form target representation)
     2414  ((aver (or (null representation) (eq representation :boolean)))
     2415   (check-arg-count form 2))
    24082416  (let* ((op (%car form))
    24092417         (args (%cdr form))
     
    24382446
    24392447(defknown p2-eql (t t t) t)
    2440 (defun p2-eql (form target representation)
    2441   (aver (or (null representation) (eq representation :boolean)))
    2442   (unless (check-arg-count form 2)
    2443     (compile-function-call form target representation)
    2444     (return-from p2-eql))
     2448(define-inlined-function p2-eql (form target representation)
     2449  ((aver (or (null representation) (eq representation :boolean)))
     2450   (check-arg-count form 2))
    24452451  (let* ((arg1 (%cadr form))
    24462452         (arg2 (%caddr form))
     
    24902496
    24912497(defknown p2-memq (t t t) t)
    2492 (defun p2-memq (form target representation)
    2493 ;;   (format t "p2-memq representation = ~S~%" representation)
    2494   (unless (check-arg-count form 2)
    2495     (compile-function-call form target representation)
    2496     (return-from p2-memq))
     2498(define-inlined-function p2-memq (form target representation)
     2499  ((check-arg-count form 2))
    24972500  (cond ((eq representation :boolean)
    24982501         (let* ((args (cdr form))
     
    25082511
    25092512(defknown p2-memql (t t t) t)
    2510 (defun p2-memql (form target representation)
    2511   (unless (check-arg-count form 2)
    2512     (compile-function-call form target representation)
    2513     (return-from p2-memql))
     2513(define-inlined-function p2-memql (form target representation)
     2514  ((check-arg-count form 2))
    25142515  (cond ((eq representation :boolean)
    25152516         (let* ((args (cdr form))
     
    43574358
    43584359(defknown p2-atom (t t t) t)
    4359 (defun p2-atom (form target representation)
    4360   (aver (or (null representation) (eq representation :boolean)))
    4361   (unless (check-arg-count form 1)
    4362     (compile-function-call form target representation)
    4363     (return-from p2-atom))
     4360(define-inlined-function p2-atom (form target representation)
     4361  ((aver (or (null representation) (eq representation :boolean)))
     4362   (check-arg-count form 1))
    43644363  (compile-forms-and-maybe-emit-clear-values (cadr form) 'stack nil)
    43654364  (emit 'instanceof +lisp-cons-class+)
     
    44394438  (p2-instanceof-predicate form target representation +lisp-abstract-vector-class+))
    44404439
    4441 (defun p2-coerce-to-function (form target representation)
    4442   (unless (check-arg-count form 1)
    4443     (compile-function-call form target representation)
    4444     (return-from p2-coerce-to-function))
     4440(define-inlined-function p2-coerce-to-function (form target representation)
     4441  ((check-arg-count form 1))
    44454442  (compile-forms-and-maybe-emit-clear-values (%cadr form) 'stack nil)
    44464443  (emit-invokestatic +lisp-class+ "coerceToFunction"
     
    45674564  (emit-invoke-method field target representation))
    45684565
    4569 (defun p2-car (form target representation)
    4570   (unless (check-arg-count form 1)
    4571     (compile-function-call form target representation)
    4572     (return-from p2-car))
     4566(define-inlined-function p2-car (form target representation)
     4567  ((check-arg-count form 1))
    45734568  (let ((arg (%cadr form)))
    45744569    (cond ((and (null target) (< *safety* 3))
     
    45804575     (emit-car/cdr arg target representation "car")))))
    45814576
    4582 (defun p2-cdr (form target representation)
    4583   (unless (check-arg-count form 1)
    4584     (compile-function-call form target representation)
    4585     (return-from p2-cdr))
     4577(define-inlined-function p2-cdr (form target representation)
     4578  ((check-arg-count form 1))
    45864579  (let ((arg (%cadr form)))
    45874580    (emit-car/cdr arg target representation "cdr")))
    45884581
    4589 (defun p2-cons (form target representation)
    4590   (unless (check-arg-count form 2)
    4591     (compile-function-call form target representation)
    4592     (return-from p2-cons))
     4582(define-inlined-function p2-cons (form target representation)
     4583  ((check-arg-count form 2))
    45934584  (emit 'new +lisp-cons-class+)
    45944585  (emit 'dup)
     
    46884679           (compiler-unsupported "COMPILE-QUOTE: unsupported case: ~S" form)))))
    46894680
    4690 (defun p2-rplacd (form target representation)
    4691   (unless (check-arg-count form 2)
    4692     (compile-function-call form target representation)
    4693     (return-from p2-rplacd))
     4681(define-inlined-function p2-rplacd (form target representation)
     4682  ((check-arg-count form 2))
    46944683  (let ((args (cdr form)))
    46954684    (compile-form (first args) 'stack nil)
     
    47054694      (emit-move-from-stack target representation))))
    47064695
    4707 (defun p2-set-car/cdr (form target representation)
    4708   (unless (check-arg-count form 2)
    4709     (compile-function-call form target representation)
    4710     (return-from p2-set-car/cdr))
     4696(define-inlined-function p2-set-car/cdr (form target representation)
     4697  ((check-arg-count form 2))
    47114698  (let ((op (%car form))
    47124699        (args (%cdr form)))
     
    49894976
    49904977(defknown p2-ash (t t t) t)
    4991 (defun p2-ash (form target representation)
    4992   (unless (check-arg-count form 2)
    4993     (compile-function-call form target representation)
    4994     (return-from p2-ash))
     4978(define-inlined-function p2-ash (form target representation)
     4979  ((check-arg-count form 2))
    49954980  (let* ((args (%cdr form))
    49964981         (arg1 (%car args))
     
    53295314
    53305315(defknown p2-lognot (t t t) t)
    5331 (defun p2-lognot (form target representation)
    5332   (unless (check-arg-count form 1)
    5333     (compile-function-call form target representation)
    5334     (return-from p2-lognot))
     5316(define-inlined-function p2-lognot (form target representation)
     5317  ((check-arg-count form 1))
    53355318  (cond ((and (fixnum-type-p (derive-compiler-type form)))
    53365319         (let ((arg (%cadr form)))
     
    53505333;; %ldb size position integer => byte
    53515334(defknown p2-%ldb (t t t) t)
    5352 (defun p2-%ldb (form target representation)
    5353 ;;   (format t "~&p2-%ldb~%")
    5354   (unless (check-arg-count form 3)
    5355     (compile-function-call form target representation)
    5356     (return-from p2-%ldb))
     5335(define-inlined-function p2-%ldb (form target representation)
     5336  ((check-arg-count form 3))
    53575337  (let* ((args (cdr form))
    53585338         (size-arg (%car args))
     
    54235403
    54245404(defknown p2-mod (t t t) t)
    5425 (defun p2-mod (form target representation)
    5426   (unless (check-arg-count form 2)
    5427     (compile-function-call form target representation)
    5428     (return-from p2-mod))
     5405(define-inlined-function p2-mod (form target representation)
     5406  ((check-arg-count form 2))
    54295407  (let* ((args (cdr form))
    54305408         (arg1 (%car args))
     
    54845462
    54855463(defknown p2-zerop (t t t) t)
    5486 (defun p2-zerop (form target representation)
    5487   (aver (or (null representation) (eq representation :boolean)))
    5488   (unless (check-arg-count form 1)
    5489     (compile-function-call form target representation)
    5490     (return-from p2-zerop))
     5464(define-inlined-function p2-zerop (form target representation)
     5465  ((aver (or (null representation) (eq representation :boolean)))
     5466   (check-arg-count form 1))
    54915467  (let* ((arg (cadr form))
    54925468         (type (derive-compiler-type arg)))
     
    55865562
    55875563(defknown p2-std-slot-value (t t t) t)
    5588 (defun p2-std-slot-value (form target representation)
    5589   (unless (check-arg-count form 2)
    5590     (compile-function-call form target representation)
    5591     (return-from p2-std-slot-value))
     5564(define-inlined-function p2-std-slot-value (form target representation)
     5565  ((check-arg-count form 2))
    55925566  (let* ((args (cdr form))
    55935567         (arg1 (first args))
     
    56025576;; set-std-slot-value instance slot-name new-value => new-value
    56035577(defknown p2-set-std-slot-value (t t t) t)
    5604 (defun p2-set-std-slot-value (form target representation)
    5605   (unless (check-arg-count form 3)
    5606     (compile-function-call form target representation)
    5607     (return-from p2-set-std-slot-value))
     5578(define-inlined-function p2-set-std-slot-value (form target representation)
     5579  ((check-arg-count form 3))
    56085580  (let* ((args (cdr form))
    56095581         (arg1 (first args))
     
    56425614
    56435615;; make-sequence result-type size &key initial-element => sequence
    5644 (defun p2-make-sequence (form target representation)
     5616(define-inlined-function p2-make-sequence (form target representation)
    56455617  ;; In safe code, we want to make sure the requested length does not exceed
    56465618  ;; ARRAY-DIMENSION-LIMIT.
    5647   (unless (and (< *safety* 3)
     5619  ((and (< *safety* 3)
    56485620               (= (length form) 3)
    5649                (null representation))
    5650     (compile-function-call form target representation)
    5651     (return-from p2-make-sequence))
     5621               (null representation)))
    56525622  (let* ((args (cdr form))
    56535623         (arg1 (first args))
     
    57355705
    57365706(defknown p2-stream-element-type (t t t) t)
    5737 (defun p2-stream-element-type (form target representation)
    5738   (unless (check-arg-count form 1)
    5739     (compile-function-call form target representation)
    5740     (return-from p2-stream-element-type))
     5707(define-inlined-function p2-stream-element-type (form target representation)
     5708  ((check-arg-count form 1))
    57415709  (let ((arg (%cadr form)))
    57425710    (cond ((eq (derive-compiler-type arg) 'STREAM)
     
    57515719;; write-8-bits byte stream => nil
    57525720(defknown p2-write-8-bits (t t t) t)
    5753 (defun p2-write-8-bits (form target representation)
    5754   (unless (check-arg-count form 2)
    5755     (compile-function-call form target representation)
    5756     (return-from p2-write-8-bits))
     5721(define-inlined-function p2-write-8-bits (form target representation)
     5722  ((check-arg-count form 2))
    57575723  (let* ((arg1 (%cadr form))
    57585724         (arg2 (%caddr form))
     
    63266292  (compile-function-call form target representation))
    63276293
    6328 (defun p2-length (form target representation)
    6329   (unless (check-arg-count form 1)
    6330     (compile-function-call form target representation)
    6331     (return-from p2-length))
     6294(define-inlined-function p2-length (form target representation)
     6295  ((check-arg-count form 1))
    63326296  (let ((arg (cadr form)))
    63336297    (compile-forms-and-maybe-emit-clear-values arg 'stack nil)
     
    64446408           (compile-function-call form target representation)))))
    64456409
    6446 (defun compile-nth (form target representation)
    6447   (unless (check-arg-count form 2)
    6448     (compile-function-call form target representation)
    6449     (return-from compile-nth))
     6410(define-inlined-function compile-nth (form target representation)
     6411  ((check-arg-count form 2))
    64506412  (let ((index-form (second form))
    64516413        (list-form (third form)))
     
    67846746;; char/schar string index => character
    67856747(defknown p2-char/schar (t t t) t)
    6786 (defun p2-char/schar (form target representation)
    6787   (unless (check-arg-count form 2)
    6788     (compile-function-call form target representation)
    6789     (return-from p2-char/schar))
     6748(define-inlined-function p2-char/schar (form target representation)
     6749  ((check-arg-count form 2))
    67906750  (let* ((op (%car form))
    67916751         (args (%cdr form))
     
    68286788;; set-char/schar string index character => character
    68296789(defknown p2-set-char/schar (t t t) t)
    6830 (defun p2-set-char/schar (form target representation)
    6831 ;;   (format t "p2-set-char/schar~%")
    6832   (unless (check-arg-count form 3)
    6833     (compile-function-call form target representation)
    6834     (return-from p2-set-char/schar))
     6790(define-inlined-function p2-set-char/schar (form target representation)
     6791  ((check-arg-count form 3))
    68356792  (let* ((op (%car form))
    68366793         (args (%cdr form))
     
    70557012
    70567013(defknown p2-structure-ref (t t t) t)
    7057 (defun p2-structure-ref (form target representation)
    7058   (unless (check-arg-count form 2)
    7059     (compile-function-call form target representation)
    7060     (return-from p2-structure-ref))
     7014(define-inlined-function p2-structure-ref (form target representation)
     7015  ((check-arg-count form 2))
    70617016  (let* ((args (cdr form))
    70627017         (arg1 (first args))
     
    71107065
    71117066(defknown p2-structure-set (t t t) t)
    7112 (defun p2-structure-set (form target representation)
    7113   (unless (check-arg-count form 3)
    7114     (compile-function-call form target representation)
    7115     (return-from p2-structure-set))
     7067(define-inlined-function p2-structure-set (form target representation)
     7068  ((check-arg-count form 3))
    71167069  (let* ((args (cdr form))
    71177070         (arg1 (first args))
     
    71547107
    71557108
    7156 (defun p2-not/null (form target representation)
    7157   (aver (or (null representation) (eq representation :boolean)))
    7158   (unless (check-arg-count form 1)
    7159     (compile-function-call form target representation)
    7160     (return-from p2-not/null))
     7109(define-inlined-function p2-not/null (form target representation)
     7110  ((aver (or (null representation) (eq representation :boolean)))
     7111   (check-arg-count form 1))
    71617112  (let ((arg (second form)))
    71627113    (cond ((null arg)
     
    72037154  (emit-move-from-stack target representation))
    72047155
    7205 (defun p2-nthcdr (form target representation)
    7206   (unless (check-arg-count form 2)
    7207     (compile-function-call form target representation)
    7208     (return-from p2-nthcdr))
     7156(define-inlined-function p2-nthcdr (form target representation)
     7157  ((check-arg-count form 2))
    72097158  (let* ((args (%cdr form))
    72107159         (arg1 (%car args))
     
    76707619
    76717620(defknown p2-symbol-name (t t t) t)
    7672 (defun p2-symbol-name (form target representation)
    7673   (unless (check-arg-count form 1)
    7674     (compile-function-call form target representation)
    7675     (return-from p2-symbol-name))
     7621(define-inlined-function p2-symbol-name (form target representation)
     7622  ((check-arg-count form 1))
    76767623  (let ((arg (%cadr form)))
    76777624    (cond ((and (eq (derive-compiler-type arg) 'SYMBOL) (< *safety* 3))
     
    76847631
    76857632(defknown p2-symbol-package (t t t) t)
    7686 (defun p2-symbol-package (form target representation)
    7687   (unless (check-arg-count form 1)
    7688     (compile-function-call form target representation)
    7689     (return-from p2-symbol-package))
     7633(define-inlined-function p2-symbol-package (form target representation)
     7634  ((check-arg-count form 1))
    76907635  (let ((arg (%cadr form)))
    76917636    (cond ((and (eq (derive-compiler-type arg) 'SYMBOL) (< *safety* 3))
     
    77757720
    77767721(defknown p2-char-code (t t t) t)
    7777 (defun p2-char-code (form target representation)
    7778   (unless (check-arg-count form 1)
    7779     (compile-function-call form target representation)
    7780     (return-from p2-char-code))
     7722(define-inlined-function p2-char-code (form target representation)
     7723  ((check-arg-count form 1))
    77817724  (let ((arg (second form)))
    77827725    (cond ((characterp arg)
     
    77927735
    77937736(defknown p2-java-jclass (t t t) t)
    7794 (defun p2-java-jclass (form target representation)
    7795   (unless (and (= 2 (length form))
    7796                (stringp (cadr form)))
    7797     (compile-function-call form target representation)
    7798     (return-from p2-java-jclass))
     7737(define-inlined-function p2-java-jclass (form target representation)
     7738  ((and (= 2 (length form))
     7739  (stringp (cadr form))))
    77997740  (let ((c (ignore-errors (java:jclass (cadr form)))))
    78007741    (if c (compile-constant c target representation)
     
    78037744
    78047745(defknown p2-java-jconstructor (t t t) t)
    7805 (defun p2-java-jconstructor (form target representation)
    7806   (unless (and (< 1 (length form))
    7807                (every #'stringp (cdr form)))
    7808     (compile-function-call form target representation)
    7809     (return-from p2-java-jconstructor))
     7746(define-inlined-function p2-java-jconstructor (form target representation)
     7747  ((and (< 1 (length form))
     7748  (every #'stringp (cdr form))))
    78107749  (let ((c (ignore-errors (apply #'java:jconstructor (cdr form)))))
    78117750    (if c (compile-constant c target representation)
     
    78147753
    78157754(defknown p2-java-jmethod (t t t) t)
    7816 (defun p2-java-jmethod (form target representation)
    7817   (unless (and (< 1 (length form))
    7818                (every #'stringp (cdr form)))
    7819     (compile-function-call form target representation)
    7820     (return-from p2-java-jmethod))
     7755(define-inlined-function p2-java-jmethod (form target representation)
     7756  ((and (< 1 (length form))
     7757  (every #'stringp (cdr form))))
    78217758  (let ((m (ignore-errors (apply #'java:jmethod (cdr form)))))
    78227759    (if m (compile-constant m target representation)
Note: See TracChangeset for help on using the changeset viewer.