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

Consider writing an Optimizer #9

Open
xrstf opened this issue Dec 21, 2023 · 1 comment
Open

Consider writing an Optimizer #9

xrstf opened this issue Dec 21, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@xrstf
Copy link
Owner

xrstf commented Dec 21, 2023

To optimize we'd first need to add an IsPure() to the Function interface, so the optimizer could pre-evaluate pure expressions that only rely on known literal values (like (+ 1 2)).

Optimizing would be mostly for fun and giggles and not truly something that I consider necessary for a small language with usually small programs like with Rudi. But it could still be fun to try.

@xrstf xrstf added the enhancement New feature or request label Dec 21, 2023
@xrstf
Copy link
Owner Author

xrstf commented Dec 28, 2023

Work on the optimizer has stalled because Rudi cannot represent intermediary data. Think of a statement like

(set! $v (semver "1.2.3"))

semver is pure (i.e. side-effect free), so the optimizer would pre-evaluate the function call, but then I currently have no option to represent that output value (a *semver struct) as Rudi, so I cannot generate (set! $v ...???....). My goal was originally to be able to have an optimizer that would take an AST and return an AST, which can be dumped as Rudi code. But currently I see no good way of doing it.

One workaround would be to say that optimized AST's can only live in memory and not be dumped. Then I can use ast.Shim to contain arbitrary values.

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