-
Notifications
You must be signed in to change notification settings - Fork 2
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
C codegen #1
Comments
Hola! I think it's an interesting idea, if you're willing to implement it (reusing the parser and AST, of course). There are lots of questions around the best way to represent some of these constructs in C (map, optional, unions), but why not. Bonus points if you also generate conversions OCaml<->C for the types 😉 |
Yeah maps might be tricky. I don't need them for my use-case at the moment, but I'll try to think of something. I'm definitely happy to contribute this if we get to implement it (CC @rigon)!
Yes! Man, I wish there was a DSL to write C in OCaml! 😄 |
Great! For maps (or even lists), I imagine it's reasonable to allow the generated code to allocate at least a bit (this is not flatbuffers/capnproto!). So I think something like that could work (forgive me, my C is a bit… rusty): BARE:
generated C (types): struct Complex {
double re;
double im;
};
struct ComplexArray {
data: Complex*;
len: size_t;
};
struct StringArray {
data: char**;
len: size_t;
};
struct MapIntBool {
keys: int*;
values: bool*; // or some bitvector…
len: size_t;
}
struct Foo {
long a;
StringArray b;
ComplexArray c;
MapIntBool d;
}; and then use malloc to create the arrays/association lists? |
Hey! :)
Just came across the BARE format (thanks to your project!) and was surprised by how similar it is to a custom format I created for my company's product. I'm immediately sold and started thinking about integrating BARE.
We currently use it between C and OCaml apps, so my natural question is can we add C codegen? I haven't looked extensively but it doesn't seem like there's currently a C code generator out there.
Thoughts?
The text was updated successfully, but these errors were encountered: