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

feat(macros): init #12

Merged
merged 2 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
- [Engine]()
- [Backends]()
- [Utilities]()
- [Libraries & Macros]()
- [Libraries & Macros](contributing/libraries_macros.md)
- [`libcore`]()

---
Expand Down
25 changes: 25 additions & 0 deletions src/contributing/libraries_macros.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Libraries

# Macros and attributes
The hax engine understands only one attribute: `#[_hax::json(PAYLOAD)]`,
where `PAYLOAD` is a JSON serialization of the Rust enum
`hax_lib_macros_types::AttrPayload`.

Note `#[_hax::json(PAYLOAD)]` is a [tool
attribute](https://github.com/rust-lang/rust/issues/66079): an
attribute that is never expanded.

In the engine, the OCaml module `Attr_payloads` offers an API to query
attributes easily. The types in crate `hax_lib_macros_types` and
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you give an example how to use the API in Attr_payloads?

Copy link
Collaborator Author

@W95Psp W95Psp Nov 14, 2023

Choose a reason for hiding this comment

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

Sure, I'm gonna write something now tomorrow
(EDIT: got distracted by something else, will do that tomorrow)

corresponding serializers/deserializers are automatically generated in
OCaml, thus there is no manual parsing involved.

## User experience
Asking the user to type `#[_hax::json(some_long_json)]` is not very
friendly. Thus, the crate `hax-lib-macros` defines a bunch of [proc
macros](https://doc.rust-lang.org/beta/reference/procedural-macros.html)
that defines nice and simple-to-use macros. Those macro take care of
cooking some `hax_lib_macros_types::AttrPayload` payload(s), then
serialize those payloads to JSON and produce one or more
`#[_hax::json(serialized_pyaload)]` attributes.
W95Psp marked this conversation as resolved.
Show resolved Hide resolved

Loading