Skip to content

Commit 8ac29e0

Browse files
committed
Add code generation for extracting annotations
1 parent 5432464 commit 8ac29e0

5 files changed

Lines changed: 398 additions & 263 deletions

File tree

Strata/DDM/Format.lean

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def fvarName (ctx : FormatContext) (idx : FreeVarIndex) : String :=
111111
else
112112
s!"fvar!{idx}"
113113

114-
protected def ofDialects (dialects : DialectMap) (globalContext : GlobalContext) (opts : FormatOptions) : FormatContext where
114+
protected def ofDialects (dialects : DialectMap) (globalContext : GlobalContext := {}) (opts : FormatOptions := {}) : FormatContext where
115115
opts := opts
116116
getFnDecl sym := Id.run do
117117
let .function f := dialects.decl! sym
@@ -441,13 +441,13 @@ private partial def OperationF.mformatM (op : OperationF α) : FormatM PrecForma
441441

442442
end
443443

444-
instance Expr.instToStrataFormat : ToStrataFormat Expr where
444+
instance Expr.instToStrataFormat : ToStrataFormat (ExprF α) where
445445
mformat e c s := e.mformatM #[] c s |>.fst
446446

447-
instance Arg.instToStrataFormat : ToStrataFormat Arg where
447+
instance Arg.instToStrataFormat : ToStrataFormat (ArgF α) where
448448
mformat a c s := a.mformatM c s |>.fst
449449

450-
instance Operation.instToStrataFormat : ToStrataFormat Operation where
450+
instance Operation.instToStrataFormat : ToStrataFormat (OperationF α) where
451451
mformat o c s := o.mformatM c s |>.fst
452452

453453
namespace MetadataArg

Strata/DDM/Integration/Lean/BoolConv.lean

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,29 @@ import Strata.DDM.Integration.Lean.OfAstM
88

99
namespace Strata
1010

11+
1112
/-- Convert Init.Bool inductive to OperationF -/
12-
def Bool.toAst {α} [Inhabited α] (v : Ann Bool α) : OperationF α :=
13-
if v.val then
14-
⟨v.ann, q`Init.boolTrue, #[]
13+
def OperationF.ofBool {α} (ann : α) (b : Bool) : OperationF α :=
14+
if b then
15+
{ ann := ann, name := q`Init.boolTrue, args := #[] }
1516
else
16-
⟨v.ann, q`Init.boolFalse, #[]
17+
{ ann := ann, name := q`Init.boolFalse, args := #[] }
1718

1819
/-- Convert OperationF to Init.Bool -/
19-
def Bool.ofAst {α} [Inhabited α] [Repr α] (op : OperationF α) : OfAstM (Ann Bool α) :=
20-
match op.name with
21-
| q`Init.boolTrue =>
22-
if op.args.size = 0 then
23-
pure ⟨op.ann, true
24-
else
25-
.error s!"boolTrue expects 0 arguments, got {op.args.size}"
26-
| q`Init.boolFalse =>
27-
if op.args.size = 0 then
28-
pure ⟨op.ann, false
29-
else
30-
.error s!"boolFalse expects 0 arguments, got {op.args.size}"
31-
| _ =>
32-
.error s!"Unknown Bool operator: {op.name}"
20+
def Bool.ofAst {α} [Inhabited α] [Repr α] (arg : ArgF α) : OfAstM Bool := do
21+
match arg with
22+
| .op op =>
23+
match op.name with
24+
| q`Init.boolTrue =>
25+
if op.args.size ≠ 0 then
26+
.error s!"boolTrue expects 0 arguments, got {op.args.size}"
27+
pure true
28+
| q`Init.boolFalse =>
29+
if op.args.size ≠ 0 then
30+
.error s!"boolFalse expects 0 arguments, got {op.args.size}"
31+
pure false
32+
| _ =>
33+
.error s!"Unknown Bool operator: {op.name}"
34+
| _ => .throwExpected "boolean" arg
3335

3436
end Strata

0 commit comments

Comments
 (0)