Commit Graph

10334 Commits

Author SHA1 Message Date
Nick Fitzgerald
6604a26e27 Add a top-level parse function
And make `parse_defs` take `self` by ownership. This avoids a couple `Vec`
clones.
2021-11-11 15:56:55 -08:00
Nick Fitzgerald
e3aeb850b2 Fix a panic when parsing var patterns 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
f2b6244b9c Fix some panics on parsing error paths 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
6a523938de Fix overflows when tokenizing integer literals 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
825258939b Define a fuzz target for the parser 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
cfaa35d8c0 Use structopt to derive CLI flags
Instead of using `clap` directly
2021-11-11 15:56:55 -08:00
Nick Fitzgerald
6ffb02d9f6 Use miette for reporting errors
This gives us errors with annotated context like this:

```
Error:
  × type error: Unknown variable 'x'
    ╭─[isle_examples/let.isle:24:1]
 24 │   (Lower (B.B z))
 25 │   (A.Add x y))
    ·          ┬
    ·          ╰── Unknown variable 'x'
    ╰────
```
2021-11-11 15:56:55 -08:00
Nick Fitzgerald
38da2cee3e Switch to using thiserror 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
b93304b327 Add docs to all public exports and deny(missing_docs) going forward 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
922a3886d5 Fix let variable typing rules 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
972dc00a92 Don't use &mut dyn Write in codegen
We always use a `String` which has infallible writing so we can remove all these
`Result`s and pretend-fallible methods.
2021-11-11 15:56:55 -08:00
Nick Fitzgerald
3535f82056 Remove an unused field in TermFunctionBuilder 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
012f4b04d7 Update TODO 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
5f5484ddbc Use matches!(..) to make TrieNode::is_empty more concise 2021-11-11 15:56:55 -08:00
Nick Fitzgerald
66ba1d89b5 Remove TODO we don't want to do
If the extern types are represented with associated types, then we can't match
on them.
2021-11-11 15:56:55 -08:00
Chris Fallin
91904aa756 TODO items from call with fitzgen 2021-11-11 15:56:55 -08:00
Chris Fallin
20bc5ca7a8 Support extern constants of any primitive type. 2021-11-11 15:56:55 -08:00
Chris Fallin
d0ace640a2 TODO update. 2021-11-11 15:56:55 -08:00
Chris Fallin
521010cc4f Split into isle and islec crates 2021-11-11 15:56:55 -08:00
Chris Fallin
e751f12ac5 Refactor to allow use as library, in order to allow build.rs usage. 2021-11-11 15:56:55 -08:00
Chris Fallin
83672a88cc bugfix to macro template generation: exclude Pos on ident from equality (broken by recent commit) 2021-11-11 15:56:55 -08:00
Chris Fallin
3ed146b782 README update. 2021-11-11 15:56:55 -08:00
Chris Fallin
2a574b1b42 Properly track locations on every AST node. Semantic errors are much more useful now. Also print parse errors in same (pseudo-standard compiler error) output format. 2021-11-11 15:56:55 -08:00
Chris Fallin
7d38b3b6d8 Revamped error handling: keep going beyond some errors to accumulate a list of build errors, like most conventional compilers. 2021-11-11 15:56:55 -08:00
Chris Fallin
b46fa6acb0 Remove old/no longer used lower.rs 2021-11-11 15:56:55 -08:00
Chris Fallin
af9e01a456 Remove old .gitmodules -- no longer using wasmtime as a submodule 2021-11-11 15:56:55 -08:00
Chris Fallin
5a8e35b253 Some fixes to the internal-extractor macro substitution 2021-11-11 15:56:55 -08:00
Chris Fallin
3f96068f94 Some test cases for arg-less enums. 2021-11-11 15:56:55 -08:00
Chris Fallin
edc95c51a0 Support for bools. Also fix fallible/infallible mixup for ctors. 2021-11-11 15:56:55 -08:00
Chris Fallin
a412cce615 Infallible extractors, and some fixes to fallibility in return types (Option<T> vs T). 2021-11-11 15:56:55 -08:00
Chris Fallin
6daa55af82 Initial draft of DSL semantics complete.
This latest refactor adds "extractor macros" in place of the
very-confusing-even-to-the-DSL-author reverse-rules-as-extractors
concept. It was beautifully symmetric but also just too mind-bending to
be practical.

It also adds argument polarity to external extractors. This is inspired
by Prolog's similar notion (see e.g. the "+x" vs. "-x" argument notation
in library documentation) where the unification-based semantics allow
for bidirectional flow through arguments. We don't want polymorphism
or dynamism w.r.t. directions/polarities here; the polarities are
static; but it is useful to be able to feed values *into* an extractor
(aside from the one value being extracted). Semantically this still
correlates to a term-rewriting/value-equivalence world since we can
still translate all of this to a list of equality constraints.

To make that work, this change also adds expressions into patterns,
specifically only for extractor "input" args. This required quite a bit
of internal refactoring but is only a small addition to the language
semantics.

I plan to build out the little instruction-selector sketch further but
the one that is here (in `test3.isle`) is starting to get interesting
already with the current DSL semantics.
2021-11-11 15:56:55 -08:00
Chris Fallin
1ceef04680 (and ...) combinator in patterns 2021-11-11 15:56:55 -08:00
Chris Fallin
602b8308ce More work on sketch for isel and some TODO items derived from it. 2021-11-11 15:56:55 -08:00
Chris Fallin
d725ac13b2 Codegen: parameterize on a generated Context trait that contains external ctors/etors. 2021-11-11 15:56:55 -08:00
Chris Fallin
3ccbaf0f69 Generate match {} statements by merging adjacent MatchVariant trie edges. 2021-11-11 15:56:55 -08:00
Chris Fallin
ed4c857082 Priority-trie: merge edges with different priorities into ranges when possible. 2021-11-11 15:56:55 -08:00
Chris Fallin
7865191093 Update long block comment describing priority trie in codegen.rs. 2021-11-11 15:56:55 -08:00
Chris Fallin
b8e916a0ab Another example, testing rule priorities a bit 2021-11-11 15:56:55 -08:00
Chris Fallin
bc91a4e5f6 Add TODO 2021-11-11 15:56:55 -08:00
Chris Fallin
4a2cd78827 Working example and README 2021-11-11 15:56:55 -08:00
Chris Fallin
d7efd9f219 Working extractor and constructor generation from rules! 2021-11-11 15:56:55 -08:00
Chris Fallin
be1140e80a WIP. 2021-11-11 15:56:55 -08:00
Chris Fallin
cd55dc9568 WIP. 2021-11-11 15:56:55 -08:00
Chris Fallin
e5d76db97a WIP. 2021-11-11 15:56:55 -08:00
Chris Fallin
8c727b175a more codegen WIP: start to generate functions 2021-11-11 15:56:55 -08:00
Chris Fallin
638c9edd01 Support for file input and output, including multiple input files with proper position tracking. 2021-11-11 15:56:55 -08:00
Chris Fallin
e9a57d854d Generate internal enum types. 2021-11-11 15:56:54 -08:00
Chris Fallin
5aa72bc060 skeleton for codegen 2021-11-11 15:56:54 -08:00
Chris Fallin
02ec77a45b trie insertion 2021-11-11 15:56:54 -08:00
Chris Fallin
77ed861857 Start of significant rework: compile to a trie, not an FSM, and handle rule priorities appropriately.
See long block comment in codegen.rs. In brief, I think we actually want
to compile to a trie with priority-intervals, a sort of hybrid of a
priority tree and a trie representing decisions keyed on match-ops
(PatternInsts).

The reasons are:

1. The lexicographic ordering that is fundamental to the FSM-building in
   the Peepmatic view of the problem is sort of fundamentally limited
   w.r.t. our notion of rule priorities. See the example in the block
   comment.

2. While the FSM is nice for interpreter-based execution, when compiling
   to a language with structured control flow, what we really want is a
   tree; otherwise, if we want to form DAGs to share substructure, we
   need something like a "diamond-recovery" algorithm that finds common
   suffixes of *input match-op sequences*, and then we need to
   incorporate something like phi-nodes in order to allow captures from
   either side of the diamond to be used.

3. One of the main advantages of the automaton/transducer approach,
   namely sharing suffixes of the *output* sequence (emitting partial
   output at each state transition), is unfortunately not applicable if
   we allow the overall function to be partial. Otherwise, there is
   always the possibility that we fail at the last match op, so we
   cannot allow any external constructors to be called until we reach
   the final state anyway.

4. Pragmatically, I found I was having to significantly edit the
   peepmatic_automata implementation to adapt to this use-case
   (compilation to Rust), and it seemed more practical to design the
   data structure we want than to try to shoehorn the existing thing
   into the new problem.

WIP, hopefully working soon.
2021-11-11 15:56:54 -08:00