Commit Graph

46 Commits

Author SHA1 Message Date
Benedikt Peetz a33aa053d2
feat(src): Add real and working support for results
Every `Result` is now -- on demand -- instantiated (i.e. the generic types
are replaced with the concretely specified ones). And can thus simply be
exported to c.
2024-05-20 15:31:05 +02:00
Benedikt Peetz 5a3f337057
fix(src/parsing): Remove the extra `error` attribute keyword
This keyword marked an enum as being an error, which is exactly what
`derive(Error)` already does. Thus this extra attribute keyword has been
removed and the `error` name has been used to rename the `msg` attribute
keyword, to be in-line with what `thiserror` does.
2024-05-20 15:31:01 +02:00
Benedikt Peetz 4feae61a76
fix(parser/unchecked/attributes): Correctly enforce an identifier in `derive`
The ebnf grammar specifies an identifier (namely “Error” in the
`derive` attribute.), while the parser expected a string literal there.
2024-05-20 15:30:58 +02:00
Benedikt Peetz 31493968b5 tests(src/types/newtypes): Test if a full round-trip works 2024-05-04 21:10:35 +02:00
Benedikt Peetz 07c38468ce chore(treewide): Renew copyright headers 2024-05-04 10:20:25 +02:00
Benedikt Peetz 0a60c894d2 feat!(src/macros): Store allocation location in all strings
This makes it possible to automatically free the string in the correct
way expected by both c and rust.
Rust strings can now just be freed by the rust allocator, whilst c
strings are forgotten, so that the c allocator may free them.

BREAKING CHANGE: All usage of explicit mentions `std::string::String`
                 in your `handle_cmd` function will need to be replaced
                 by `trixy::types::newtypes::String`. Otherwise these
                 types should provide the same methods.
2024-05-04 10:12:20 +02:00
Benedikt Peetz 86427b0c1a refactor(src/macros/generate/host): Merge host generation in one module 2024-05-04 08:23:36 +02:00
Benedikt Peetz bd0b3c7dcf
fix(generate/convert/host/rust/derive/structure): Ignore `ptr` arg on todo 2024-03-27 22:36:24 +01:00
Benedikt Peetz a766149521
style(treewide): Format 2024-03-27 22:36:19 +01:00
Benedikt Peetz c69c00e1e9
feat(types/try_from_impl): Add a trixy::String from &str impl
This makes it more convenient to use the api.
2024-03-27 22:36:15 +01:00
Benedikt Peetz db5cd1a29b
fix(macros): Mark the main generate function as must_use
The generated FileTree should be used, calling the function without
using it is useless.
2024-03-27 22:36:12 +01:00
Benedikt Peetz 73416da73c
docs(macros/generate): Improve error output 2024-03-27 22:36:10 +01:00
Benedikt Peetz febb2deae3
fix(types/types_list): Add the supported primitive types
Otherwise, the generated type paths lead nowhere.
2024-03-27 22:36:09 +01:00
Benedikt Peetz a58030ce7e
fix(macros/generate/host/host/type): The function type is a c pointer 2024-03-27 22:36:05 +01:00
Benedikt Peetz 645b8d58f6
fix(macros/generate/host/c/function): Actually call the callback function
Previously, the generated c wrapper function did not call the callback
correctly.
2024-03-27 22:36:03 +01:00
Benedikt Peetz b5f5ae8b03
fix(macros/generate/host): Add unified support for conversions
These include from the c type to rust, vice versa.
2024-03-27 22:36:01 +01:00
Benedikt Peetz 3d35d395f3
fix(macros/generate/auxiliary/c/function): Also add inputs when no output 2024-03-27 22:35:59 +01:00
Benedikt Peetz bfeb62033a
fix(macros/generate/convert/auxiliary/c/arguments): Accept newlines
Multiple lines in one comment were not checked for, which resulted in
only one `*` before instead of a new one after every `\n`.
2024-03-27 22:35:52 +01:00
Benedikt Peetz a66c687421
fix(macros/generate/convert/auxiliary/c): Correctly generate function types 2024-03-27 10:54:01 +01:00
Benedikt Peetz bb101c14fb
feat(macros/generate/convert/auxiliary): Merge comments in c
```c
/**
  comment one
  */
/**
  comment two
  */
/**
  comment three
  */
```
is just not as readable as:
```c
/**
  * comment one
  * comment two
  * comment three
  */
```
2024-03-27 10:17:38 +01:00
Benedikt Peetz 37ba451362
fix(types): Remove top-level support for generic types
These would still parse and would generate _stuff_, but the generated
stuff is just not ideal yet. So better not accept them, until their
internal support has matured.
2024-03-27 10:01:51 +01:00
Benedikt Peetz 9a8ccc9cc2
fix(macros/generate): Correctly generate function types 2024-03-27 10:01:07 +01:00
Benedikt Peetz 7a8dc66876
fix(parser/unchecked/parse_structure): Accept attributes on fields 2024-03-27 09:59:35 +01:00
Benedikt Peetz fae3de8b49
fix(parser/lexing/take_until_sucessive_match): Add utf8 support 2024-03-27 09:58:08 +01:00
Benedikt Peetz 4e3bdf273e
fix(binary/parse): Actually only perform the other steps, if asked for it
Otherwise, the lexing functionality becomes useless, if the Trixy file
can't be parsed and processed.
2024-03-27 08:10:33 +01:00
Benedikt Peetz 508dc2bc46
fix(parser/tokenizer): Remove the tokenizer's death, when exposed to doc comments
Previously, the tokenizer had horrendous errors when lexing raw literal
strings. These have been removed. The remaining issue still persists,
that empty doc comments are serialized in c in a _weird_ way. They
should be merged.
2024-03-27 08:07:29 +01:00
Benedikt Peetz 5ab2bbb8fd
chore(treewide): Update license header 2024-03-26 20:11:23 +01:00
Benedikt Peetz 2b4599592c
chore(treewide): Add or update license header 2024-03-26 19:58:24 +01:00
Benedikt Peetz 5ada3cb83d
style(treewide): format 2024-03-26 19:58:14 +01:00
Benedikt Peetz 5855d9bcb0
fix(macros/config/file_tree/markdown): Change format to align with mdfmt
To ensure, that `mdfmt` does not reformat our `expected.md` files.
2024-03-26 19:58:12 +01:00
Benedikt Peetz d48456d039
test(tests): Add the positive tests (and delete the ones in rust)
The rust based test were both not sufficient to cover all edge-cases and
so unmaintainable that they nearly always didn't even compile. This new
test framework should alleviate both concerns.
However, one big problem still remains: it does not support test cases
that should fail, so these have just been left in the `./tests`
directory.
2024-03-26 17:35:30 +01:00
Benedikt Peetz 08df8e81d4
fix(bin/generate): Actually only generate what was specified
The binary did before generate both host and auxiliary files, even when
only one is specified.
2024-03-26 17:35:25 +01:00
Benedikt Peetz 89fd67c45e
feat(macros/config/file_tree): Add support for parsing a FileTree from file
This makes storing expected `FileTree`s as markdown possible (useful in
tests).
2024-03-26 17:35:24 +01:00
Benedikt Peetz ec929dabe5
feat(bin): Add a binary, that helps in showing the generated code 2024-03-26 17:35:22 +01:00
Benedikt Peetz eb7a901d09
refactor(treewide): Rework file structure in `src/macros`
This might be a big diff, but I _hope_ that it does not change much
functionally (hopefully it changes nothing generation specific).

What has changed?
-----------------
- I had to merge the three crates into one, to allow `macros` to impl
  functions on Types defined in `parser`.
- As mentioned in the point above, the conversion function are now
  inherent to the type they convert (i. e. `r#type.to_rust()` instead of
  `type_to_rust(r#type)`).
- The conversion function have been sorted, by what they convert to:
   - `to_rust()` converts a type to be used in rust *host* code.
   - `to_c()` converts a type to be used in c *host* code.
   - `to_auxiliary_c()` converts a type to be used in c *auxiliary*
     code.
- The top-most `generate` method of `TrixyConfig` now returns a
  `FileTree` instead of writing the files directly. The `FileTree` can
  still be materialize with the `materialize` method. But this change
  facilitates moving non-generation focused code out of the `generate`
  method.

What is the difference between _host_ and _auxiliary_ code?
-----------------------------------------------------------
Auxiliary code is always written in the language it is generated for. So
auxiliary code for c would be written in c (or at least in a subset of c),
as it represents c header files.
Host code is always written in rust. This is the code that is
responsible for implementing the actual ffi stuff. In our case these are
the `extern "C"` functions and the types, defined in trixy.
The rust host code is generating the native rust representations of
these types.
2024-03-26 17:35:21 +01:00
Benedikt Peetz e72c212f0c
fix(trixy): Add thiserror dependency, as it's used in generated code 2024-03-26 17:35:10 +01:00
Benedikt Peetz 5a7bb00548
chore(treewide): Add the new license header 2024-02-19 16:13:55 +01:00
Benedikt Peetz e205ea4625
docs(lib): Add a description to the oneshot-senders 2024-02-18 13:37:34 +01:00
Benedikt Peetz b3c6a4c1a1
feat(treewide): Add broken Vec<E>, Result<T,E> and Option<T> types to c api
These are implemented right now by simply casting the generic arguments
to void pointers and providing a `type_id` field in every struct
denoting the original type.

This implementation, whilst being extremely unwieldy to work with on
the c side, also fails in a lot of fundamental ways:
   1. The `type_id` enum *can* never really support user defined
      types because we would already need it to provide the c to rust
      value conversion.

   2. Even without custom user types the type conversion is extremely
      hard to correctly implement in a somewhat performant way: A vector
      passed from c code to rust would need to completely reallocated
      *one element at a time*. And this only works if the c side has
      correctly cast the void pointer to the vectors data before accessing
      it, as any other way would have lead to possible unaligned data
      (which the rust side had to account for).

   3. The c api is just simply bad in this state:
      You have to always look at the Trixy file to even be able to deal
      with the data the api returns (that is: There is no mention of
      a results generics in the c header).  Additionally the question
      arises if these types should even be leaked into the c code because
      than c just becomes a worse version of rust, which undermines the
      whole reason of providing a c api in the first place.

One way to fix all these issues would be to change the way generics are
handled by using unions instead of the void pointer and trying to avoid
leaking these rust types in c as far as possible.
This approach would require a lot less binding code (both on the c and
rust side), but also would make the rust based c-header-gen-code harder,
as it would then be required to turn a `Vec<String>` to a `char **` (and
obviously a whole wrapper struct with size and string length), whilst
turning a `Vec<char>` to a `char*` differentiating it from a `string_t`.
2023-12-28 10:28:58 +01:00
Benedikt Peetz b9e26418ad
fix(trixy): Use public reexports 2023-12-26 12:18:58 +01:00
Benedikt Peetz 21e1b75193
chore(treewide): Move the trixy subcrates under one trixy crate 2023-12-26 12:14:08 +01:00
Benedikt Peetz 7d1a41aca9
feat(treewide): Provide a c api 2023-12-25 22:23:52 +01:00
Benedikt Peetz 0744c8468d
chore(treewide): Add license headers 2023-12-24 11:30:03 +01:00
Benedikt Peetz ed96a50bd4
feat(trixy-macros): Add rust host code generation 2023-12-24 11:28:30 +01:00
Benedikt Peetz 03f24503b7
chore(treewide): Add license headers 2023-12-23 18:57:10 +01:00
Benedikt Peetz 233fa3e1b5
chore: Initial commit
This not the "real" first commit, the others are in the trinitrix/core
repository, made before the split-up took place
2023-12-23 16:07:17 +01:00