New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add compiler macro foreign-type-size #343
Add compiler macro foreign-type-size #343
Conversation
Fixes #340 |
@@ -164,6 +164,14 @@ Signals an error if FOREIGN-TYPE is undefined.")) | |||
(:documentation | |||
"Return the size in bytes of a foreign type.")) | |||
|
|||
(define-compiler-macro foreign-type-size (&whole form foreign-type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any tests that should be performed for this compiler macro alone? I assume that you could call the compiler macro function yourself to ensure that it provides correct results on some test cases.
3cab21f
to
eeab15d
Compare
@samuel-hunter Copy QUOTEDP, CONSTANTP, and EVAL-CONSTANT from https://github.com/sionescu/static-vectors/blob/master/src/constantp.lisp and use them. |
Preexisting compiler macros ought to benefit from this if grafted into CFFI. I think this may be best split into its own PR |
Why a new PR ? |
My thinking, at least, is that it separates two units of work: Adding a compiler macro for foreign-type-size, and then augmenting all compiler macros to use QUOTEDP, CONSTANTP, and EVAL-CONSTANT (many, many compiler macros I see here use cl:constantp and cl:eval). |
I'll make a new branch/PR at least for now |
@samuel-hunter Please rebase to master. I added the utils in d4216a3. |
I opened #344 for converting existing compiler macros. |
f1dd642
to
64140b4
Compare
e0ffe70
to
20ed961
Compare
src/early-types.lisp
Outdated
;; executed in a null lexical environment. | ||
(if (constantp (macroexpand foreign-type)) | ||
`(load-time-value (locally (declare (notinline foreign-type-size)) ,form)) | ||
(if (constant-form-p (macroexpand foreign-type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do the conversion in another PR. You can cherry-pick this commit to another branch.
20ed961
to
64140b4
Compare
The compiler macro is a first-pass that should fix most use cases without breakage. It checks to see if the foreign type is constant, and if so, expands into its foreign type size, falling back to the old form if an error is signaled.
64140b4
to
a978e49
Compare
Fixes #340. Depends on #345
The compiler macro is a first-pass that should fix most use cases without breakage. It checks to see if the foreign type is constant, and if so, expands into its foreign type size, falling back to the old form if an error is signaled.
Before the compiler macro:
After (on SBCL 2.2.5 64-bit)
Tested on SBCL and CCL with no additional test errors.