Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

lets design some games

Name: that can run well over tor. 2013-08-03 19:47

and then we can have /prog/ gaming tornies[i]![i]

Name: Anonymous 2013-08-04 2:54

How does one implement pointers in Lisp? There is no implicit memory, so one have to explicitly specify the chunk of memory to work on. Which potentially could be optimized by loading array pointers into segment registers (getting bounds checks and protected memory at no cost). Also, there is no malloc. For now I devised following simple macro:
(defmacro with-ptr ((name base &optional (offset 0)) &body xs)
  (let ((o (gensym "p"))
        (b (gensym "a")))
    `(let ((,o ,offset)
           (,b ,base))
       (macrolet ((,name (op &rest as)
                    (let ((o ',o)
                          (b ',b)
                          (v (gensym "v")))
                      (case op
                        (++ `(let ((,v (aref ,b ,o)))
                               (incf ,o ,@as)
                               ,v))
                        (-- `(let ((,v (aref ,b ,o)))
                               (decf ,o ,@as)
                               ,v))
                        (base b)
                        (offset o)
                        (start? `(= ,o 0))
                        (end? `(= ,o (length ,b)))
                        (avail? `(< ,o (length ,b)))
                        (move-to-head `(setf ,o 0))
                        (move-to-last `(setf ,o (- (length ,b) 1)))
                        (otherwise `(aref ,b (+ ,o ,@as)))))))
         (symbol-macrolet ((,name (aref ,b ,o)))
           ,@xs)))))

(with-ptr (p "abcdefg")
  (while (p avail?)
    (format t "[~a] = ~a~%" (p offset) (p ++))))

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List