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

Compile buffers and structs which lengths are known to more precise types ? #33

Open
jkzinzindohoue opened this issue Feb 12, 2017 · 2 comments

Comments

@jkzinzindohoue
Copy link
Contributor

What would be a good way to make it so that I can write a type type state = b:buffer uint32{length b = 16} and that gets compile to typedef uint32[16] state ?

The usecase is the following: I have an algorithm that relies on a state with an "init", an "update" and a "finish" function. To run the algorithm I would call init the initialize the state, and then update a certain number of times, and then finish to cleanup to the state and return some value. This is very typical in cryptography.

In F* what I would do it that init would be in the StackInline effect, so that one calling the function gets in return a properly formatted, pre-filled state.
However at the C level this function will have been inline and thus will not be available. Which forces me to decouple the allocation of the state from its initialization (because it is stack-based so no mallocs).
Unfortunately I can't do state st; init(st, key) because state will just have been compiled to a pointer and not an array with a statically defined length. If the state is a complicated structure, this is even more painful because the C user need to allocated each element on the stack and then fill the struct that only contains pointers.

Is there a way to easily solve that ? I still want to complain about the lack of a mechanism to translate more information from the Core AST to the extracted AST (like the length of the buffers).

@prosecco
Copy link

prosecco commented Feb 12, 2017 via email

@prosecco
Copy link

prosecco commented Feb 12, 2017 via email

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

No branches or pull requests

2 participants