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

Write a transform that turns expressions into statements #48

Open
felixSchl opened this issue Oct 20, 2018 · 1 comment
Open

Write a transform that turns expressions into statements #48

felixSchl opened this issue Oct 20, 2018 · 1 comment
Labels

Comments

@felixSchl
Copy link
Collaborator

The current output is heavily based on expressions, meaning that we apply functions and feed the result into other functions etc. It would be interesting to explore a transform that would turn these expressions into statements by generating fresh variable names in the current block scope and then perform the wiring up.

For example:

Turn this:

purs_any_app(f, purs_any_app(g, purs_any_int_new(100)))

into this:

const ANY * $value0 = purs_any_int_new(100);
const ANY * $value1 = purs_any_app(g, $value0);
const ANY * $value2 = purs_any_app(f, $value1);
return $value2;

At least one benefit of this is that it makes it easier to set breakpoints in generated programs. I am currently performing these transformations by hand when debugging generated output.

@felixSchl
Copy link
Collaborator Author

One thing to potentially look out for though is increased stack usage for all these temporary variables, especially with fat pointers (#59, #54.) Perhaps clang and gcc already optimize for this? It would be nice to perform these optimisations on our AST as well, however, to produce more readable and more terse output. #54 introduces a LOT of noise in the generated code.

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

No branches or pull requests

1 participant