remove zero-argument functions / applications in generated code

This commit is contained in:
2024-09-07 11:41:16 -07:00
parent 796d93d7d9
commit 06f7ba0984
3 changed files with 7 additions and 1 deletions

View File

@@ -187,6 +187,7 @@ mkArgs Z acc = acc
mkArgs (S k) acc = mkArgs k ("h\{show k}" :: acc)
dcon : String -> Nat -> Doc
dcon nm Z = stmtToDoc $ JConst nm $ LitObject [("tag", LitString nm)]
dcon nm arity =
let args := mkArgs arity []
obj := ("tag", LitString nm) :: map (\x => (x, Var x)) args

View File

@@ -69,6 +69,7 @@ apply t (x :: xs) acc (S k) = apply t xs (acc :< x) k
apply t ts acc 0 = go (CApp t (acc <>> [])) ts
where
go : CExp -> List CExp -> M CExp
go (CApp t []) [] = pure t
go t [] = pure t
go t (arg :: args) = go (CApp t [arg]) args
@@ -119,6 +120,7 @@ compileFun tm = go tm []
where
go : Tm -> List String -> M CExp
go (Lam _ nm t) acc = go t (nm :: acc)
go tm [] = compileTerm tm
go tm args = pure $ CFun (reverse args) !(compileTerm tm)