Support anonymous fields in ftypes#1042
Open
agspathis wants to merge 3 commits into
Open
Conversation
Contributor
Author
|
The |
959e5e3 to
a2ea8e9
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds support for anonymous
struct/union/bitsfields tostruct/unionftypes, mirroring anonymous structures/unions of C11 and later. Besides their direct benefits, they also obviate the need to introduce tags for intermediate levels when generating ftypes from C types that utilize them.Implementation outline: Anonymous fields are given a
#tname (as opposed to#fof unnamed ones), which is then replaced by the list of subfield names accessible from the containing ftype. They're marked by the=>keyword, as their functionality may be thought of as "field forwarding". The inspector has been adapted so thatrefing a field by name jumps to its level while registering a singledownmove (index-based access remains intact). Sample inspector session:Transcript
Chez Scheme Transcript [Tue Apr 28 19:26:06 2026] > (define-ftype Frob (struct [=> (union [=> (bits [a unsigned 2] [b unsigned 6])] [=> (bits [A unsigned 6] [B unsigned 2])])] [=> [union [c char] [s short]]])) > (define the-frob (make-ftype-pointer Frob (foreign-alloc (ftype-sizeof Frob)))) > (inspect the-frob)(ftype struct ...) : p (struct [=> (union [=> (bits [a 0] [b 50])] [=> (bits [A 8] [B 3])])] [=> (union [c #\à] [s -2080])]) (ftype struct ...) : ftype (struct (=> (union (...) (...))) (=> (union (...) (...)))) : p (struct [=> (union [=> (bits [a unsigned 2] [b unsigned 6])] [=> (bits [A unsigned 6] [B unsigned 2])])] [=> (union [c char] [s short])]) (struct (=> (union (...) (...))) (=> (union (...) (...)))) : u (ftype struct ...) : set! c #\Q (ftype struct ...) : p (struct [=> (union [=> (bits [a 0] [b 50])] [=> (bits [A 8] [B 3])])] [=> (union [c #\Q] [s -2223])]) (ftype struct ...) : set! b 0 (ftype struct ...) : ref b 0 : u (ftype struct ...) : p (struct [=> (union [=> (bits [a 0] [b 0])] [=> (bits [A 0] [B 0])])] [=> (union [c #\Q] [s -2223])]) (ftype struct ...) : ref 0 (ftype union ...) : p (union [=> (bits [a 0] [b 0])] [=> (bits [A 0] [B 0])]) (ftype union ...) : set! A 80 Exception in ftype-set!: invalid value 80 for bit field of size 6 (ftype union ...) : set! A 40 (ftype union ...) : ref 1 (ftype bits ...) : p (bits [A 40] [B 0]) (ftype bits ...) : u 2 (ftype struct ...) : p (struct [=> (union [=> (bits [a 0] [b 10])] [=> (bits [A 40] [B 0])])] [=> (union [c #\Q] [s -2223])]) (ftype struct ...) : q > (transcript-off)Being new to the project, and given #1028, I wish to clarify that I haven't used any LLMs when preparing these changes.