Permalink
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...
1 parent f876fc8 commit cd3298e8d91931d7fecd4c603ed5f5ce89307ec6 @liamh liamh committed Mar 23, 2012
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/types.lisp
View
@@ -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 ()

0 comments on commit cd3298e

Please sign in to comment.