dimitriv / Ziria

A domain-specific-language and compiler for low-level bitstream processing.
92 stars 18 forks source link

Redundancy in the grammar/AST #57

Open edsko opened 9 years ago

edsko commented 9 years ago

The top-level grammar rule is currently

<prog> ::= <decl>* <let-decl>*

with corresponding AST

data Prog a b
  = MkProg { globals :: [(Name,Ty,Maybe (Exp b))]
           , comp :: Comp a b }

However, <let-decl> includes a letref case, so there is no need to separately allow for a list of declarations (vars). Similarly, we have for function definitions

"fun" <comp-ann> <var-bind> <comp-params> "{" <decl>* <commands> "}"

with corresponding AST

  LetFunC     :: Name
              -> [(Name, CallArg Ty CTy0)] -- params (could include computation types)
              -> [(Name,Ty,Maybe (Exp b))] -- locals
              -> Comp a b                  -- body
              -> Comp a b                  -- rhs
              -> Comp0 a b

but again here too the Comp can include its own let refs.

In both cases the separate list of vars is redundant, and removing them is a simplification without loss of generality (though we need to exercise some care or we might incur a performance regression).