feat: add compileDecl

cc @kha
This commit is contained in:
Leonardo de Moura 2020-01-07 16:38:41 -08:00
parent 69be2148d6
commit 2ce2610c0a
3 changed files with 14 additions and 5 deletions

View file

@ -561,10 +561,15 @@ result ++ remaining.toList
def addDecl (ref : Syntax) (decl : Declaration) : CommandElabM Unit := do
env ← getEnv;
match env.addDecl decl with
| Except.ok env => modify $ fun s => { env := env, .. s }
| Except.error kex => do
opts ← getOptions;
throwError ref (kex.toMessageData opts)
| Except.ok env => setEnv env
| Except.error kex => do opts ← getOptions; throwError ref (kex.toMessageData opts)
def compileDecl (ref : Syntax) (decl : Declaration) : CommandElabM Unit := do
env ← getEnv;
opts ← getOptions;
match env.compileDecl opts decl with
| Except.ok env => setEnv env
| Except.error kex => throwError ref (kex.toMessageData opts)
end Command
end Elab

View file

@ -150,7 +150,7 @@ withDeclId view.declId $ fun name => do
| some decl => do
addDecl ref decl;
applyAttributes ref declName view.modifiers.attrs AttributeApplicationTime.afterTypeChecking;
-- TODO invoke compiler
compileDecl ref decl;
applyAttributes ref declName view.modifiers.attrs AttributeApplicationTime.afterCompilation
end Command

View file

@ -215,3 +215,7 @@ def three := 3
#eval run "#check g (y := three)"
#eval run "#check g (z := three)"
#eval run "#check g three (z := zero)"
#eval run "open Lean.Parser
@[termParser] def myParser : Lean.Parser.Parser Lean.ParserKind.leading := parser! coe \"hi\"
#check myParser"