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

Parse attribute-style comments from source code #20

Merged
merged 6 commits into from
May 24, 2024
Merged

Parse attribute-style comments from source code #20

merged 6 commits into from
May 24, 2024

Conversation

richfitz
Copy link
Member

This is the first stage of supporting compiling models; parsing some metadata out of the source code. See the new attributes in inst/examples/sir.cpp and examples/walk.cpp for examples of this.

When we come to do code generation we will not attempt to parse C++ (which is hard) but instead inspect these attributes and generate code based on what we find.  This is what we ended up doing in dust1 eventually, it's much easier than trying to be clever, and practically it's not very hard to do because most models are generated mechanically anyway.

At the same time I've updated the parameter- and data-reading functions to use some common code, which provides much nicer error messages.

We'll probably expand some of the attribute support here, in particular advertising parameter types and if the parameter is updateble, differentiable, or has a default. For now the bare minimum.

The error reporting could be improved and it would not be that hard to return line numbers etc. But the expectation is that most of the code is generated so these errors will probably never be seen

@richfitz richfitz marked this pull request as ready for review May 22, 2024 13:13
@richfitz richfitz requested a review from weshinsley May 22, 2024 13:17
Copy link
Contributor

@weshinsley weshinsley left a comment

Choose a reason for hiding this comment

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

Great - this looks nice



dust2_file <- function(path) {
system.file(path, mustWork = TRUE, package = "dust2")
Copy link
Contributor

Choose a reason for hiding this comment

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

That mustWork arg name always amuses me. I might write some args not_that_bothered_if_it_works in some of my functions.

@richfitz richfitz merged commit 7008657 into main May 24, 2024
7 checks passed
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