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

Idiomatic C backend #690

Open
denismerigoux opened this issue Sep 19, 2024 · 0 comments
Open

Idiomatic C backend #690

denismerigoux opened this issue Sep 19, 2024 · 0 comments
Assignees
Labels
🔧 compiler Issue concerns the compiler ✨ enhancement New feature or request

Comments

@denismerigoux
Copy link
Contributor

The current C89 backend (#671) is semantics-preserving and quite fast (as fast as native OCaml without GC allocations) thanks to @AltGr. However, the code it generates is not very idiomatic and might be difficult to adopt by people that really want a C they can read and modify (https://jonathan.protzenko.fr/2019/01/04/behind-the-scenes.html). Thus, we might want to relax semantics-preservation (slightly) in favor of generating C code that looks like man-made. This could be done in an alternative C89 backend that I would qualify as "idiomatic". The gist of the idiomatic backend is that it should use builtin types and avoid boxing at all costs.

To achieve this objective, the following changes are needed from the current C89 backend :

  • stop using GMP and model integers as long long int and decimals as double ;
  • minimize closure lifting by matching collection operations early and turning them into for loops ;
  • layout structs and enums in a flat fashion (no boxing)
  • pipe Scalc to one of the intermediate representations of https://github.com/FStarLang/karamel/, and apply Karamel's optimization passes and pretty-printing capabilities (thanks @protz !).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 compiler Issue concerns the compiler ✨ enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants