Skip to content

Commit cbf382f

Browse files
committed
automatic position
1 parent fb13898 commit cbf382f

File tree

7 files changed

+46
-12
lines changed

7 files changed

+46
-12
lines changed

AVM/Action/DummyResource.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Prelude
22
import Anoma
3+
import Anoma.Logic
34

45
namespace AVM.Action
56

@@ -16,6 +17,8 @@ def isDummyResource (res : Anoma.Resource) : Bool :=
1617
res.ephemeral &&
1718
res.quantity == 0
1819

20+
#check Anoma.Logic.Error.rawError
21+
1922
/-- The resource logic of any dummy resource. -/
2023
private def dummyResourceLogic : Anoma.Logic :=
2124
{ reference := dummyResourceLogicRef,

AVM/Class/Translation/Logics.lean

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ private def logicFun
298298
(args : Logic.Args)
299299
: Anoma.LogicM :=
300300
let try self : Object classId := Object.fromResource args.self
301+
failwith throw (.custom here# s!"Failed to decode self to an Object:
302+
{repr args.self}"
303+
)
301304
check eco.classes classId |>.invariant self args
302305
match args.status with
303306
| Created => .true

Anoma/Logic.lean

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ import Anoma.Resource
22

33
namespace Anoma
44

5+
inductive Logic.Error : Type where
6+
| rawError (pos : FilePosition)
7+
| custom (pos : FilePosition) (msg : String)
8+
-- | rawError
9+
10+
instance : Repr Logic.Error where
11+
reprPrec e _ :=
12+
match e with
13+
| .rawError p => repr p
14+
| .custom p msg => s!"{repr p}: {msg}"
15+
516
structure Logic.Args : Type 2 where
617
self : Resource
718
status : ConsumedCreated
@@ -13,7 +24,7 @@ structure Logic.Args : Type 2 where
1324

1425
def Logic.Args.isConsumed (d : Logic.Args) := d.status.isConsumed
1526

16-
abbrev LogicM : Type := Except String Unit
27+
abbrev LogicM : Type := Except Logic.Error Unit
1728

1829
abbrev LogicM.true : LogicM := pure .unit
1930

Anoma/Program.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ structure Program.Error.BalanceCheck : Type 2 where
2929
inductive Program.Error : Type 2 where
3030
| identityError (msg : String)
3131
| storageError (msg : String)
32-
| logicFailed (logRef : LogicRef) (reason : String)
32+
| logicFailed (logRef : LogicRef) (reason : Logic.Error)
3333
| missingLogic (ref : LogicRef)
3434
| balanceCheck (err : Program.Error.BalanceCheck)
3535
| typeError (msg : String)

Applib/Surface/Program/Syntax.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def findProof (scope : Term) : TacticM Unit := do
2121
let possibleIndices : List (Fin card) := List.finRange card
2222
let tryN (n : Fin card) : TacticM Unit := do
2323
let sn := Syntax.mkNumLit (toString n)
24-
let labelId ← `(term| $f $sn)
24+
let labelId : TSyntax `term ← `(term| $f $sn)
2525
let t ← `(tactic| try exact ⟨$labelId, by rfl⟩)
2626
evalTactic t
2727
for x in possibleIndices do

Prelude/CustomDefault.lean

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,23 @@ open Elab.Tactic Meta
66

77
elab "mydefault" : tactic => do
88
let tgt ← getMainTarget
9-
if tgt.isAppOf `LogicM
9+
-- logInfo s!"unchecked default {tgt}"
10+
if tgt.isAppOf `Anoma.LogicM
1011
then
11-
let t ← `(tactic| exact (throw here#))
12+
-- logInfo "XXXXXXXX unchecked default"
13+
let rawErr : TSyntax `term := mkIdent `Anoma.Logic.Error.rawError
14+
let t ← `(tactic| exact (throw ($rawErr here#)))
1215
evalTactic t
1316
else do
1417
let t ← `(tactic| exact default)
1518
evalTactic t
1619

1720
elab "mydefaultM" : tactic => do
1821
let tgt ← getMainTarget
22+
-- logInfo "mydefaultM"
1923
if tgt.isAppOf `LogicM
2024
then
25+
-- logInfo "MMMMMMM unchecked default M"
2126
let t ← `(tactic| exact (throw here#))
2227
evalTactic t
2328
else do

Prelude/Debug.lean

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@ import Lean
22

33
open Lean
44

5+
structure FilePosition where
6+
file : String
7+
pos : Position
8+
deriving ToExpr
9+
10+
instance : Repr FilePosition where
11+
reprPrec p _ := s!"{p.file}:{p.pos.line}:{p.pos.column}"
12+
13+
def FilePosition.unknown : FilePosition where
14+
file := "<unknown-file>"
15+
pos := ⟨0, 0
16+
17+
-- returns FilePosition for the location where it is inserted
518
elab "here#" : term => do
619
let file ← getFileName
720
let ref ← getRef
8-
let some pos := ref.getPos?
9-
| return mkStrLit "<unknown position>"
1021
let fm ← getFileMap
11-
let lc := fm.toPosition pos
12-
return mkStrLit s!"{file}:{lc.line}:{lc.column}"
13-
14-
instance (priority := high) [Pure m] : Inhabited (ExceptT String m α) where
15-
default := pure (f := m) (throw here#)
22+
let some pos := ref.getPos?
23+
| return (toExpr FilePosition.unknown)
24+
let lc : FilePosition :=
25+
{ file
26+
pos := fm.toPosition pos }
27+
return (toExpr lc)

0 commit comments

Comments
 (0)