[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gcl-devel] Re: defconstant vs. defparameter

From: Camm Maguire
Subject: [Gcl-devel] Re: defconstant vs. defparameter
Date: 08 Dec 2005 17:07:46 -0500
User-agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2


My cvs access is not working right now, but you can fix this (as I
will when it is restored) by making var-array-type in
gcl_cmpinline.lsp look like this:

(defun var-array-type (a)
  (when (consp a)
    (cond ((eq (car a) 'var) (var-type (cadr a)))
          ((eq (car a) 'VV) 
           (object-type (or (cdr (aref (car *data*) (cadr a)))
                            (cmp-eval (car (rassoc (cadr a) *constants* :key 
          ((eq (car a)  'cvar)
           (or (cdr (assoc (cadr a) *c-vars*))
               (car (rassoc (cadr a) *c-vars*)))))))

The issue here is with the handling of constants as opposed to
variables.  GCL normally calculates and proagates their type with
type-of and object-type, and then writes these into the .data file for
direct reading and loading when the .o file is loaded.  The problem
has always been that we have two array types, static and normal, which
have the same print/read representation, so it is impossible to pass a
static array by this method.  (If the arrays in the s-data structure
are nont static, for example, all #$%@ will break loose :-)).  Hence
arrays have been elided from the set of thus processed constant
values, and instead the symbol denoting the constant is pushed to the
*constants* stack, and same is evaluated at object file load time.
The former seems a bit safer, as it seems possible that the symbol
might not be around at load time.  The following functions enable at
least non-static array handling just as other constants:

(defun c1constant-value (val always-p)
   ((eq val nil) (c1nil))
   ((eq val t) (c1t))
   ((si:fixnump val)
    (list 'LOCATION (make-info :type (list 'integer val val)) ;;FIXME -- 1024 
should be small fixnum limit
          (list 'FIXNUM-VALUE (and (>= (abs val) 1024)(add-object val))
   ((characterp val)
    (list 'LOCATION (make-info :type 'character)
          (list 'CHARACTER-VALUE (add-object val) (char-code val))))
   ((typep val 'long-float)
    ;; We can't read in long-floats which are too big:
    (let (tem x)
      (unless (setq tem (cadr (assoc val *objects*)))
                   (> (setq x (abs val)) (/ most-positive-long-float 2))
                   (c1expr `(si::|#,| * ,(/ val most-positive-long-float)
                   (< x (* least-positive-long-float 1.0d20))
                   (c1expr `(si::|#,| * ,(/ val least-positive-long-float)
               (push (list val (setq tem *next-vv*)) *objects*))))
      (list 'LOCATION (make-info :type 'long-float)
            (list 'LONG-FLOAT-VALUE (or tem (add-object val)) val))))
   ((typep val 'short-float)
    (list 'LOCATION (make-info :type 'short-float)
          (list 'SHORT-FLOAT-VALUE (add-object val) val)))
   ((and (consp val) (eq (car val) 'si::|#,|))
    (list 'LOCATION (make-info :type (object-type (cmp-eval (cdr val))))
          (list 'VV (add-object val))))
   ((and (arrayp val) (not (si::staticp val)))
    (list 'LOCATION (make-info :type (object-type val))
          (list 'VV (add-object val))))
    (list 'LOCATION (make-info :type (object-type val))
          (list 'VV (add-object val))))
   (t nil)))

(defun object-type (thing)
  (let* ((type (type-of thing)))
    (cond ((type>= 'integer type) `(integer ,thing ,thing))
          ((eq type 'cons) `(cons ,(object-type (car thing)) ,(if (cdr thing) 
(object-type (cdr thing)) 'null)))
          ((eq type 'keyword) 'symbol)
          ((type>= 'character type) 'character)

I might commit this too.  Actually, I wonder how bad it would be to
have a non-std reader macro read in static arrays so that both types
could be thus handled.

Please let me know if problems persist.

Take care,

Robert Boyer <address@hidden> writes:

> Why should declaring something with defconstant instead of with defparameter
> make things slower?
> In the following transcript, the compiled reference to *ar1* uses
> fLrow_major_aref, which I believe is much slower than the in-line v.v_self
> reference to *ar2*.
> Also, I would have thought that the type declarations would have been good
> enough to get an in-line =, as it does if defparameter is used in both
> places, instead of defconstant.
> Thanks so much!
> Bob
> -------------------------------------------------------------------------------
> GCL (GNU Common Lisp)  2.7.0 ANSI    Dec  8 2005 08:51:51
> Source License: LGPL(gcl,gmp,pargcl), GPL(unexec,bfd)
> Binary License:  GPL due to GPL'ed components: (BFD UNEXEC)
> Modifications of this banner must retain notice of a compatible license
> Dedicated to the memory of W. Schelter
> Use (help) to get some basic information on how to use GCL.
> >(defconstant *ar1* (make-array 2 :element-type 'fixnum))
> (defparameter *ar2* (make-array 2 :element-type 'fixnum))
> (proclaim '(type (simple-array fixnum (2)) *ar1* *ar2*))
> (defun bar ()
>     (= (aref *ar1* 0)
>        (aref *ar2* 0)))
> *AR1*
> >
> *AR2*
> >
> >
> >(disassemble 'bar)
> ;; Compiling gazonk4.lsp.
> ;; End of Pass 1.  
> ;; End of Pass 2.  
> ;; OPTIMIZE levels: Safety=0 (No runtime error checking), Space=0, Speed=3, 
> (Debug quality ignored)
> ;; Finished compiling gazonk4.o.
> #include "gazonk4.h"
> void init_code(){do_init(VV);}
> /*    function definition for BAR     */
> static void L1()
> {register object *base=vs_base;
>       register object *sup=base+VM1; VC1
>       vs_check;
>       vs_top=sup;
>       goto TTL;
> TTL:;
>       {fixnum V2;
>       V2= (fixnum)0;
>       V3 = V2;
>       V1= fLrow_major_aref(VV[0],V3);}
>       {fixnum V5;
>       V5= (fixnum)0;
>       V6 = V5;
>       V4= CMPmake_fixnum((long)((fixnum 
> *)((VV[1]->s.s_dbind))->v.v_self)[V6]);}
>       base[0]= (number_compare(V1,V4)==0)?Ct:Cnil;
>       vs_top=(vs_base=base+0)+1;
>       return;
> }

Camm Maguire                                            address@hidden
"The earth is but one country, and mankind its citizens."  --  Baha'u'llah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]