Skip to content
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

Template haskell for generating Haskell records from C structs #289

Open
expipiplus1 opened this issue Jun 9, 2021 · 5 comments
Open

Template haskell for generating Haskell records from C structs #289

expipiplus1 opened this issue Jun 9, 2021 · 5 comments

Comments

@expipiplus1
Copy link
Owner

There's heaps of functionality in the generators regarding turning

typedef struct {
  double myDouble;
  size_t numInts;
  int *myInts;
} foo;

into

data Foo = Foo 
  { myDouble :: Double
  , myInts :: Vector Int32
  }

Wouldn't it be great to have a quasiquoter taking the former and outputting the latter, along with appropriate Storable or ToCStruct instances?

@dpwiz
Copy link
Collaborator

dpwiz commented Jun 9, 2021

derive-storable in reverse? 🤔

What is its intended use in vulkan?

@expipiplus1
Copy link
Owner Author

derive-storable in reverse?

Exactly

What is its intended use in vulkan?

To get rid of uses of derive-storable like https://github.com/expipiplus1/vulkan/blob/master/examples/rays/Scene.hs#L101-L105

Don't think that that package works with ghc9, and other derive-storable solutions aren't always appropriate (fpco/th-utilities#12)

@dpwiz
Copy link
Collaborator

dpwiz commented Jun 9, 2021

Ouch (the sound of a person suddenly discovered themselves in a middle of a minefield).

Have you seen the Block class?

@expipiplus1
Copy link
Owner Author

regrettably I'm all too familiar :)

@dpwiz
Copy link
Collaborator

dpwiz commented Mar 31, 2023

To get rid of uses of derive-storable like https://github.com/expipiplus1/vulkan/blob/master/examples/rays/Scene.hs#L101-L105

I'm testing that Block class and benchmarks show that it is okay to use it for flat structures like that Sphere. The problems start when the stuff has nested structures.

Also, I've grafted Packed variant to it and the performance stays lit for a few levels of nesting too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants