Commit Graph

73 Commits

Author SHA1 Message Date
Benedikt Peetz 3646e4aee8
fix(scripts/renew_copyright_header): Correctly handle shebangs 2024-03-26 19:58:22 +01:00
Benedikt Peetz 3484ead8af
fix(scripts/renew_copyright_header): Add per filetype handling
Otherwise, the mistakes are not avoidable.
2024-03-26 19:58:20 +01:00
Benedikt Peetz a653dec211
chore(docs/generate_docs): Add a `.sh` extension, so scripts recognize the ft 2024-03-26 19:58:19 +01:00
Benedikt Peetz 596197be92
build(flake): Update 2024-03-26 19:58:17 +01:00
Benedikt Peetz e9efc2335a
build(scripts/renew_copyright_header): Init 2024-03-26 19:58:15 +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 fa6b046780
style(flake): Add even more formatters 2024-03-26 17:35:34 +01:00
Benedikt Peetz b85650e911
test(scripts): Add a script, which will help with generating and updating tests 2024-03-26 17:35:32 +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 c898c48de2
chore(parser/docs/grammar.pdf): Update file 2024-03-26 17:35:19 +01:00
Benedikt Peetz 9630e10262
build(flake): Update 2024-03-26 17:35:18 +01:00
Benedikt Peetz eb3156753a
feat(example/valgrind): Add a script to test the c example with valgrind 2024-03-26 17:35:16 +01:00
Benedikt Peetz c2d21fd0a8
fix(types): Improve support for generic rust types
The support might be improved, but I still sort of want to remove
generic types, as the current implementation is just _bad_.
2024-03-26 17:35:15 +01:00
Benedikt Peetz f688df1248
docs(example): Update the example c and tri file to latest progress 2024-03-26 17:35:13 +01:00
Benedikt Peetz d2d18d905e
chore(example): Switch to full trinitrix API 2024-03-26 17:35:12 +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 8b02d13dae
fix(macros): Generate namespacesed types and convertible impls 2024-03-26 17:35:08 +01:00
Benedikt Peetz 5fe757f829
fix(macros/c_api): Add host generation support for structs and enums 2024-03-26 17:35:07 +01:00
Benedikt Peetz 6e72b7bcf1
feat(macros/c_api/header): Add structs and enums to the c header 2024-03-26 17:35:05 +01:00
Benedikt Peetz 9e37456f74
fix(types/error): Add a pseudo error for infallible conversions 2024-03-26 17:35:04 +01:00
Benedikt Peetz 0ebbc4346e
docs(parser/examples): Add various examples (also the trinitrix main api) 2024-03-26 17:35:02 +01:00
Benedikt Peetz 0a6159ef86
test(parser/checked/test): Update test case 2024-03-26 17:35:00 +01:00
Benedikt Peetz ce1e4d83b9
fix(parser/lexing/error): Improve the message of the `NoMatchesTaken` error
This error should only ever be raised, when we encountered a bug.
This change notifies the user, that the situation is rather likely to be
a bug and that this should be reported.
2024-03-26 17:34:58 +01:00
Benedikt Peetz e512352f73
fix(parser/error): Remove multiple errors from line number calc
Errors were contextualized by finding their index in the source file.
This method is extremely flaky, as it _hopes_ that the line is not
spread over multiple lines.
The new method actually uses the span to calculate a matched line and
thus avoids any issues related to the actual position of the line in the
source file.
2024-03-26 17:34:56 +01:00
Benedikt Peetz a50936f264
feat(parser): Associate a vector of nasps with every struct, enum, nasp
This feature makes it possible to generate these types actually in
namespaces and not only in one toplevel.
2024-03-26 17:34:55 +01:00
Benedikt Peetz f73d3aa5d7
feat(parser): Add support for parsing function pointer types
Notably these diverge from rust, by requiring argument names. This is a
deliberate design decision, as it help users to guess what's going to be
passed into their callback.
2024-03-26 17:34:53 +01:00
Benedikt Peetz 21b0ce1c01
feat(parser/bin): Allow `lex` as an alias to `tokenize` 2024-03-26 17:34:51 +01:00
Benedikt Peetz a4513e8c51
refactor(parser): Use predictable names for tokens 2024-03-26 17:34:49 +01:00
Benedikt Peetz add0d170eb
feat(parser): Add support for parsing attributes 2024-03-26 17:34:47 +01:00
Benedikt Peetz f1e9087f40
feat(parser/lexing): Desuger doc comments by running a regex on the file
Previously we actually supported parsing doc comments (`///`), but
replacing them before parsing allows for simplifications in the lexer.
Precisely, that means that we can add support for attributes without
having to maintain the doc comment parser.
2024-03-26 17:34:44 +01:00
Benedikt Peetz 18034e28de
refactor(macros/convertible_derive): Generate the `Convertible` Trait impl
Previously this was derived in the `trixy-types-derive` create, but this
is just making debugging harder and has thus been refactored.
2024-03-26 17:34:28 +01:00
Benedikt Peetz 938e038075
refactor(types/headers/string): Don't typedef a string type
This really does not add anything, and just using `const char*` directly
keeps things more clear.
2024-03-24 17:59:19 +01:00
Benedikt Peetz 17fd954e46
fix(macros/c_api/header): Format doc comments in a c-like way
Formatting them with `/// [Comment]` is a rust convention, c uses `/**
[Comment] */`.
2024-03-24 17:56:43 +01:00
Benedikt Peetz cd5b0c9ee4
refactor(example/main/c): Deduplicate error handling function 2024-03-24 17:52:36 +01:00
Benedikt Peetz 86d00608eb
build(cog.toml): Use `nix fmt` (treefmt) instead of only `cargo fmt` 2024-03-24 17:51:07 +01:00
Benedikt Peetz 7a95fa7d81
chore(.licensure.yml): Add license spdx identifier 2024-03-24 17:46:27 +01:00
Benedikt Peetz 2f7be6fe67
chore(.licensure.yml): Also add the license text to markdown files 2024-03-24 16:39:01 +01:00
Benedikt Peetz 5ce46a1568
fix(trixy/examples/main): Improve c code 2024-02-19 20:58:21 +01:00
Benedikt Peetz d904a19f48
style(treewide): Reformat with treefmt (`nix fmt`) 2024-02-19 20:53:11 +01:00
Benedikt Peetz 8104e802e7
build(update.sh): Add a shebang 2024-02-19 20:52:10 +01:00
Benedikt Peetz 7c27cdc0e0
fix(trixy-macros): Format the generated header with in the GNU style 2024-02-19 20:51:33 +01:00
Benedikt Peetz 1b8a33c919
build(flake): Add treefmt
This only adds this as nix module. So running `nix fmt` will now format
all files under the repo root.

If you want to run this as non-nix user feel free to take a look at the
generated `treefmt.toml`.
2024-02-19 20:48:50 +01:00
Benedikt Peetz 03f8eda241
style(treewide): Reformat 2024-02-19 16:15:18 +01:00
Benedikt Peetz 5a7bb00548
chore(treewide): Add the new license header 2024-02-19 16:13:55 +01:00
Benedikt Peetz 6e26bec209
build(licensure): Add c headers to known files 2024-02-19 16:13:53 +01:00