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

[WIP] Improved codegen #34

Merged
merged 2 commits into from
Oct 5, 2021

Conversation

ThePuzzlemaker
Copy link
Contributor

@ThePuzzlemaker ThePuzzlemaker commented Oct 2, 2021

Motivation

Generating text is fallible, and probably inefficient. The current executor also writes to a file every time something is to be executed and runs SWIPL from the PATH.

What's here so far

  • Code generator to SWI-Prolog
  • Executor using embeded SWIPL
  • Higher-level interface to some unsafe things that swipl-rs doesn't expose
  • Rudimentary REPL mostly used for testing

What's to come (many probably in separate PRs)

  • Proper CLI and REPL, (the latter possibly with runtime structural editing)
  • Compile to SWIPL file or save state from file, rather than assertz-ing at runtime.
  • Proper bug-fixing, testing, and code cleanup. Also, try to reduce unsafe if possible, just to decrease the surface of possible memory safety bugs
  • Proper error handling for when something goes wrong within Prolog (i.e. when solving or compiling)

@ThePuzzlemaker ThePuzzlemaker marked this pull request as draft October 2, 2021 01:32
brightly-salty added a commit that referenced this pull request Oct 5, 2021
* AST/parser changes, remove anyhow

Patched out editor for now just because it'd be too borked

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>

* Use unic-ucd-category intead of unic-ucd

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>
SWIPL provides a FFI interface called the FLI that can make code
generation more ergonomic and less fallible. This PR uses that
interface. There are some rough edges in the library I used (cc
terminusdb-labs/swipl-rs#4), but it's still a lot better than generating
text and parsing SWIPL's output as text (which would probably not work
if an exception is raised).

There is still a bit more that needs to be done in terms of ergonomics
and error handling, but this prototype is at a pretty good state at the
moment.

This commit is a squash of the following commits:
- [WIP] Improved codegen
- Revamp prelude/builtins, move save state to target/
- Remove unnecessary primitive, unnecessary dependencies, and fix clippy
  warnings
- Undo some parser/deps changes
- Revert the previous
- Remove merge artifact
- Fix code for new AST

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>
@brightly-salty brightly-salty marked this pull request as ready for review October 5, 2021 00:32
@brightly-salty brightly-salty merged commit 2ed5640 into mlatu-lang:rust Oct 5, 2021
@ThePuzzlemaker ThePuzzlemaker deleted the improved-codegen branch October 5, 2021 01:04
brightly-salty added a commit that referenced this pull request Oct 7, 2021
* Initial Rust work

* Fix clippy hints, better error handling

* Build time + runtime improvements

* Add structured editor

* Fix prelude and allow newlines/CR (#31)

* AST/Parser changes (From #34&#32, separated into this PR) (#36)

* AST/parser changes, remove anyhow

Patched out editor for now just because it'd be too borked

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>

* Use unic-ucd-category intead of unic-ucd

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>

* [WIP] Improved codegen (#34)

* UI improvements for structural editor (#32)

* Use std::fmt for centering, add labels for halves

This makes everything cleaner! With some algebra and code™, it's
possible to use `format!` for centering text.

This commit also adds labels to the pattern and replacement half, just
being centered boxes `| Pattern |` and `| Replacement |` in the usually
bland `--------`(...) line after the status.

* Fix rule index (off-by-one errors go brrr)

* Switch from termion to crossterm

Squash of:
- Switch from termion to crossterm (@brightly-salty)
- Abstract away a view for easier layouting (@brightly-salty)
- Add lockfile (@ThePuzzlemaker)
- Undo some AST/parser changes (@ThePuzzlemaker)

Co-authored-by: ThePuzzlemaker <tpzker@thepuzzlemaker.info>

* Fix code for new AST, make pretty_rule use &[Term] instead of Vec<Term>

* Rebase and fix

* Add failing interactive mode

* Improve interactive rewriter

* Fix prelude + mlatu.pl

* Add CLI + standardize keybindings

Co-authored-by: Caden Haustein <code@brightlysalty.33mail.com>

* Update documentation

Co-authored-by: James [Undefined] <tpzker@thepuzzlemaker.info>
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