Mousetail
small compiler for Modal into other languages.Mousetail is a tool for turning Modal rules into into static code. It provides a system for writing new backends that inject code into a scaffold. It fits in under 300 lines of lua code and could in theory allow for multiple backends.
Unfortunately, it's still pretty rough. There was numerous strugles trying to retrofit generated rules into the existing interpreter and assumptions proven wrong.
Hoever, it's correct enough to run various program and pass 47/50 test. Those last three test have proven... challenging.
Struggles Writing Mousetail
The following section covers various strugles writing Mousetail.
Register Hell
Easily the hardest part of Modal was handling the registers. And, there are still issues with them. The first challenge of registers is how they interact when they fail. If two rules for as followed
<> (?a b c) ... <> (?a c c) ... a c cWhen the first rule fails you have to backtrack to the next rule.
Next issues with register is they break the idea of using a prefix tree. On the surface, it seems like registers can be joined together. But, regester actually represent an arbatrary prefix. This results in a "coloring" of rules:
<> (order a) 0 <> (?x b) 1 <> (?x c) 2 <> (?x d) 3 <> (order d) (order e) order dIf Mousetail naively group
(order a)
and (order d)
(which it does currently), then this code would evaluate in the wrong order. The priorty should be (order a) -> (?x b) -> (?x c) -> (?x d) -> (order d)
. However, grouping (order a)
and (order b)
would cause (?x d)
to be unreached. This generalizes over your rule set. You cannot move rules over this boundary; it will break eval order.
Late Binding
Rules in modal can be defined at any point. This make static compiling hard becase you have to defer rule activation to runtime. I believe the solution to this is to have all compiled rules start out "inactive" and reactivate them when their rule gets evaluted. One cute solution I thought could work is using IO:
?((?: ?0) ?:) activate-rule (foo bar baz)This would enable the rule `foo bar baz` in the compiled set. More thought will need to be put into this.
Deletion
Deletion is the opposite problem. Now you have to search for the rule to disable. This could be done farely easily. But, I never got around to doing it in Mousetail.