Subject: Re: Amazon used lisp & C exclusively?
From: (Rob Warnock)
Date: Fri, 14 Jul 2006 00:07:58 -0500
Newsgroups: comp.lang.lisp
Message-ID: <>
Frank Buss  <> wrote:
| So converting an integer to a pointer is not illegal code and well
| defined in ANSI C, but the result is implementation defined.
| In contrast to this: AFAIK in Common Lisp there is no such low-level
| access defined at all.

No, but every Common Lisp implementation worth worrying about
*has* some such low-level access facilities defined. E.g., CMUCL
provides SYSTEM:SAP-REF-{8,16,32,64}, which are also SETF'able.
Aliased to "r{8,16,32,64}" and "w{8,16,32,64}", resp., I use these
quite heavily in my little user-mode hardware debugging environment:

    hwtool> (deflex foo (copy-seq "abcdefghij"))

    hwtool> foo                            

    hwtool> (d32 foo)
    0x580005f8: 0x0000002a 0x00000028 0x64636261 0x68676665
    0x58000608: 0x00006a69 0x00000000 0x580005ff 0x2800000b
    0x58000618: 0x580005b3 0x2800000b 0x580005b3 0x2800000b
    0x58000628: 0x580005b3 0x2800000b 0x580005b3 0x5800063b
    hwtool> (loop for addr from 0x58000600
		  for c = (r8 addr)
		  while (plusp c)
	      collect (code-char c))

    (#\a #\b #\c #\d #\e #\f #\g #\h #\i #\j)

Or more cleanly [??? -- well, at least it'll work after a GC]:

    hwtool> (loop for addr from (system:sap-int (system:vector-sap foo))
		  for c = (r8 addr)
		  while (plusp c)
	      collect (code-char c))

    (#\a #\b #\c #\d #\e #\f #\g #\h #\i #\j)

Let's poke a bit, shall we?  ;-}

    hwtool> (w32 0x58000604 0x48474645)		; [1], [2]

    hwtool> foo


It's even more fun when you're peeking & poking at hardware...  ;-}


[1] Yes, I use a "0" readmacro to allow "0x" to mean "#x".

[2] Yes, this would be much cleaner as:

      (w32 (+ 4 (system:sap-int (system:vector-sap foo))) 0x48474645)

    or even:

      (setf (system:sap-ref-32 (system:vector-sap foo) 4) 0x48474645)

Rob Warnock			<>
627 26th Avenue			<URL:>
San Mateo, CA 94403		(650)572-2607