Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Compiler macro for mem-aptr

Multi-level optimizations depending what arguments are constantp; 
the constantp arguments need to be evaled.
  • Loading branch information...
commit cd3298e8d91931d7fecd4c603ed5f5ce89307ec6 1 parent f876fc8
@liamh liamh authored
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/types.lisp
View
6 src/types.lisp
@@ -299,7 +299,11 @@ to open-code (SETF MEM-REF) forms."
(define-compiler-macro mem-aptr (&whole form ptr type &optional (index 0))
"The pointer to the element."
(if (constantp type)
- `(inc-pointer ptr (* index ,(foreign-type-size type)))
+ (if (constantp index)
+ (if (zerop (eval index))
+ ptr
+ `(inc-pointer ptr ,(* (eval index) (foreign-type-size (eval type)))))
+ `(inc-pointer ptr (* index ,(foreign-type-size (eval type)))))
form))
(define-foreign-type foreign-array-type ()
Please sign in to comment.
Something went wrong with that request. Please try again.