This commit is contained in:
2024-08-11 12:18:07 -07:00
parent 32536fc264
commit f27c03ef20
4 changed files with 75 additions and 77 deletions

View File

@@ -24,7 +24,7 @@ processDecl (TypeSig fc nm tm) = do
ty <- check (mkCtx top.metas) tm (VU fc)
ty' <- nf [] ty
putStrLn "got \{pprint [] ty'}"
modify $ claim nm ty'
modify $ setDef nm ty' Axiom
processDecl (Def fc nm raw) = do
putStrLn "-----"
@@ -48,7 +48,7 @@ processDecl (Def fc nm raw) = do
-- putStrLn "ERROR at (\{show l}, \{show c}): Unsolved meta \{show k}"
throwError $ E (l,c) "Unsolved meta \{show k}"
debug "Add def \{nm} \{pprint [] tm} : \{pprint [] ty}"
put (addDef ctx nm tm ty)
modify $ setDef nm ty (Fn tm)
processDecl (DCheck fc tm ty) = do
@@ -74,7 +74,7 @@ processDecl (Data fc nm ty cons) = do
ctx <- get
tyty <- check (mkCtx ctx.metas) ty (VU fc)
-- FIXME we need this in scope, but need to update
modify $ claim nm tyty
modify $ setDef nm tyty Axiom
ctx <- get
cnames <- for cons $ \x => case x of
-- expecting tm to be a Pi type
@@ -84,14 +84,14 @@ processDecl (Data fc nm ty cons) = do
-- TODO count arity
dty <- check (mkCtx ctx.metas) tm (VU fc)
debug "dty \{nm'} is \{pprint [] dty}"
modify $ defcon nm' (getArity dty) nm dty
modify $ setDef nm' dty (DCon (getArity dty) nm)
pure nm'
_ => throwError $ E (0,0) "expected constructor declaration"
-- TODO check tm is VU or Pi ending in VU
-- Maybe a pi -> binders function
-- TODO we're putting in axioms, we need constructors
-- for each constructor, check and add
modify $ deftype nm tyty cnames
modify $ setDef nm tyty (TCon cnames)
pure ()
where
checkDeclType : Tm -> M ()

View File

@@ -23,34 +23,15 @@ Show TopContext where
public export
empty : HasIO m => m TopContext
empty = pure $ MkTop [] !(newIORef (MC [] 0)) True
empty = pure $ MkTop [] !(newIORef (MC [] 0)) False
||| set or replace def. probably need to check types and Axiom on replace
public export
claim : String -> Tm -> TopContext -> TopContext
claim name ty = { defs $= (MkEntry name ty Axiom ::) }
public export
deftype : String -> Tm -> List String -> TopContext -> TopContext
deftype name ty cons = { defs $= (MkEntry name ty (TCon cons) :: )}
public export
defcon : String -> Nat -> String -> Tm -> TopContext -> TopContext
defcon cname arity tyname ty = { defs $= (MkEntry cname ty (DCon arity tyname) ::) }
-- TODO update existing, throw, etc.
public export
addDef : TopContext -> String -> Tm -> Tm -> TopContext
addDef tc name tm ty = { defs $= go } tc
setDef : String -> Tm -> Def -> TopContext -> TopContext
setDef name ty def = { defs $= go }
where
-- What did I do here?
go : List TopEntry -> List TopEntry
-- FIXME throw if we hit [] or is not an axiom
-- FIXME use a map, I want updates
go [] = ?addDEF_fail
go (x@(MkEntry nm _ _) :: xs) = if nm == name
then MkEntry nm ty (Fn tm) :: xs
else x :: go xs
go [] = [MkEntry name ty def]
go (x@(MkEntry nm ty' def') :: defs) = if nm == name
then MkEntry name ty def :: defs
else x :: go defs