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

constants defined in OCaml: #6

Closed
wants to merge 5 commits into from
Closed

Conversation

craff
Copy link
Contributor

@craff craff commented Aug 5, 2023

This way Events.(et lor inp lor out) is compiled into a constant (I check with -dlinear)

We also gain that exclusive is always available from OCaml even if not supported.

@craff craff mentioned this pull request Aug 5, 2023
Copy link
Owner

@lindig lindig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason I am exporting C constants using a function is to avoid having to define the constant values in OCaml where I don't have access to the original definition or header file. I don't see a draw back. These functions are called when the OCaml module is initialised and after that all values are defined and there is no function call overhead while they are being used.

What is gained by defining the constants in OCaml?

@craff
Copy link
Contributor Author

craff commented Aug 5, 2023 via email

@lindig
Copy link
Owner

lindig commented Aug 5, 2023

I agree that the constants are no longer compile-time constants. The trade off here is that I can be sure that I am using the correct constants. Given how fast bit operations are and the language we are using, I still like the trade off.

A potential middle ground could be to define the constants and to check them against the correct constants using the mechanism we have currently.

@craff
Copy link
Contributor Author

craff commented Aug 5, 2023 via email

@craff
Copy link
Contributor Author

craff commented Aug 5, 2023 via email

@lindig
Copy link
Owner

lindig commented Aug 5, 2023

I think a PPX adds a dependency that I would rather avoid. But I could imagine something like:

let pri = 0x002
assert (pri = polly_PRI ());

Now you have compile-time constants but you also verify that they are correct.

@craff
Copy link
Contributor Author

craff commented Aug 5, 2023 via email

@craff
Copy link
Contributor Author

craff commented Aug 5, 2023

I close this PR, because I restarted from master to have a clean commit history

@craff craff closed this Aug 5, 2023
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

Successfully merging this pull request may close these issues.

2 participants