fixes to pattern matching and codegen, J example works now

This commit is contained in:
2024-09-13 21:15:57 -07:00
parent 49c1f0ce5d
commit 33015dd060
5 changed files with 49 additions and 17 deletions

View File

@@ -70,7 +70,8 @@ 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
-- drop zero arg call
go (CApp t []) args = go t args
go t [] = pure t
go t (arg :: args) = go (CApp t [arg]) args
@@ -117,12 +118,12 @@ compileTerm (Let _ nm t u) = pure $ CLet nm !(compileTerm t) !(compileTerm u)
export
compileFun : Tm -> M CExp
compileFun tm = go tm []
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)
go : Tm -> SnocList String -> M CExp
go (Lam _ nm t) acc = go t (acc :< nm)
go tm [<] = compileTerm tm
go tm args = pure $ CFun (args <>> []) !(compileTerm tm)