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

Automatic compilation #17

Open
6 of 15 tasks
noteflakes opened this issue Feb 28, 2024 · 1 comment
Open
6 of 15 tasks

Automatic compilation #17

noteflakes opened this issue Feb 28, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@noteflakes
Copy link
Contributor

noteflakes commented Feb 28, 2024

Compilation right now works only partially, and is based on Ruby's internal AST representation. This does have the advantage of being able to compile dynamically generated templates, but is not a very friendly API, nor is it well documented or guaranteed to be stable over the long run.

Over the long run, the Ruby ecosystem will come together around Prism, and that's why I'm working on Sirop, a complementary gem that builds on top of Prism.

So the idea is to build a compiler on top of Sirop (a big part of the functionality is already there in the test DSL compiler).

This issue is for tracking progress on this undertaking.

Still to be implemented:

JIT compilation

We want compilation to be automatic and transparent. Say, on the second call to #render for a specific template, the template is automatically compiled and the compiled code is memoized. From then on, rendering will actually use the compiled proc.

For naked procs, we can memoize the compiled version in some ivar under Papercraft, e.g. Papercraft.__compiled_proc_cache__.

Next steps

  • Create a bunch of fixtures in Papercraft test directory. We can put in basically all existing tests, plus from the examples directory.
  • Implement a harness that takes a fixture, runs it normally, then compiles the fixture, then runs the compiled version and then compare the two results, which should be identical.
  • Reimplement compiler using Sirop.
@noteflakes noteflakes added the enhancement New feature or request label Feb 28, 2024
@noteflakes noteflakes self-assigned this Feb 28, 2024
@noteflakes
Copy link
Contributor Author

Preliminary work in commit 10abb62.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant