forked from Orchid/orchid
Macro system done in theory
too afraid to begin debugging, resting for a moment
This commit is contained in:
@@ -42,9 +42,9 @@ Prioritised macro patterns must start and end with a vectorial placeholder. They
|
||||
Macros are checked from the outermost block inwards.
|
||||
|
||||
1. For every name token, test all named macros starting with that name
|
||||
1. If the tail is implicit, continue iterating
|
||||
1. If the tail is implicit, continue iterating
|
||||
2. Test all prioritized macros
|
||||
1. Take the first rule that matches in the highest prioritized block
|
||||
1. Take the first rule that matches in the highest prioritized block
|
||||
|
||||
Test all in a set of macros
|
||||
1. Take the first rule that matches in each block
|
||||
@@ -75,26 +75,26 @@ Recursion has to happen through the interpreter itself, so the macro system is d
|
||||
- line parser `macro` parses a macro with the existing logic
|
||||
- atom `MacRecurState` holds the recursion state
|
||||
- function `resolve_recur` finds all matches on a MacTree
|
||||
- type: `MacRecurState -> MacTree -> MacTree`
|
||||
- use all relevant macros to find all matches in the tree
|
||||
- since macros must contain a locally defined token, it can be assumed that at the point that a constant is evaluated and all imports in the parent module have been resolved, necessarily all relevant macro rules must have been loaded
|
||||
- for each match
|
||||
- check for recursion violations
|
||||
- wrap the body in iife-s corresponding to the named values in the match state
|
||||
- emit a recursive call to process and run the body, and pass the same recursive call as argument for the macro to use
|
||||
- type: `MacRecurState -> MacTree -> MacTree`
|
||||
- use all relevant macros to find all matches in the tree
|
||||
- since macros must contain a locally defined token, it can be assumed that at the point that a constant is evaluated and all imports in the parent module have been resolved, necessarily all relevant macro rules must have been loaded
|
||||
- for each match
|
||||
- check for recursion violations
|
||||
- wrap the body in iife-s corresponding to the named values in the match state
|
||||
- emit a recursive call to process and run the body, and pass the same recursive call as argument for the macro to use
|
||||
```
|
||||
(\recur. lower (recur $body) recur)
|
||||
(resolve_recur $mac_recur_state)
|
||||
```
|
||||
- emit a single call to `instantiate_tpl` which receives all of these
|
||||
- emit a single call to `instantiate_tpl` which receives all of these
|
||||
- function `instantiate_tpl` inserts `MacTree` values into a `MacTree(tpl)`
|
||||
- type: `MacTree(tpl) [-> MacTree] -> MacTree`
|
||||
- type: `MacTree(tpl) [-> MacTree] -> MacTree`
|
||||
_this function deduces the number of arguments from the first argument. This combines poorly with autocurry, but it's an easy way to avoid representing standalone tree lists_
|
||||
- walks the tree to find max template slot number, reads and type checks as many template values
|
||||
- returns the populated tree
|
||||
- walks the tree to find max template slot number, reads and type checks as many template values
|
||||
- returns the populated tree
|
||||
- function `resolve` is the main entry point of the code
|
||||
- type: `MacTree -> MacTree`
|
||||
- invokes `resolve_recur` with an empty `MacRecurState`
|
||||
- type: `MacTree -> MacTree`
|
||||
- invokes `resolve_recur` with an empty `MacRecurState`
|
||||
- function `lower` is the main exit point of the code
|
||||
- type: `MacTree -> any`
|
||||
- Lowers `MacTree` into the equivalent `Expr`.
|
||||
- type: `MacTree -> any`
|
||||
- Lowers `MacTree` into the equivalent `Expr`.
|
||||
Reference in New Issue
Block a user