Skip to content

Commit 61fd12e

Browse files
feat: feature-complete Sort API, minor ffi-level Except Error-handling improvements (#39)
* feat: add dataty-related `Sort` functions and tests * chore: make `Sort.getKind` produce `Except Error` * chore: improve `Except Error` handling at cpp-level
1 parent 7d1894b commit 61fd12e

File tree

3 files changed

+388
-268
lines changed

3 files changed

+388
-268
lines changed

cvc5.lean

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -692,9 +692,12 @@ private def mkExceptOkU16 : UInt16 → Except Error UInt16 := .ok
692692
private def mkExceptOkU8 : UInt8 → Except Error UInt8 := .ok
693693

694694
/-- Only used by FFI to inject errors. -/
695-
@[export except_err]
696-
private def mkExceptErr {α : Type} : String → Except Error α :=
697-
.error ∘ Error.error
695+
@[export generic_except_err]
696+
private def mkExceptErr {α : Type} : Error → Except Error α := .error
697+
698+
/-- Only used by FFI to inject errors. -/
699+
@[export generic_except_err_of_string]
700+
private def mkExceptErrOfString {α : Type} : String → Except Error α := .error ∘ Error.error
698701

699702
end ffi_except_constructors
700703

@@ -1088,7 +1091,7 @@ protected extern_def hash : cvc5.Sort → UInt64
10881091
instance : Hashable cvc5.Sort := ⟨Sort.hash⟩
10891092

10901093
/-- Get the kind of this sort. -/
1091-
extern_def getKind : cvc5.Sort → SortKind
1094+
extern_def!? getKind : cvc5.Sort Except Error SortKind
10921095

10931096
/-- Determine if this is the null sort (`cvc5.Sort`). -/
10941097
extern_def isNull : cvc5.Sort → Bool
@@ -1193,6 +1196,9 @@ extern_def isInstantiated : cvc5.Sort → Bool
11931196
/-- A string representation of this sort. -/
11941197
protected extern_def toString : cvc5.Sort → String
11951198

1199+
instance : ToString cvc5.Sort := ⟨Sort.toString⟩
1200+
instance : Repr cvc5.Sort := ⟨fun self _ => self.toString⟩
1201+
11961202
/-- Determine if this term has a symbol (a name).
11971203
11981204
For example, free constants and variables have symbols.
@@ -1290,11 +1296,35 @@ the vector takes priority.
12901296
- `sorts` The sub-sorts to be substituted within this sort.
12911297
- `replacements` The sort replacing the substituted sub-sorts.
12921298
-/
1293-
extern_def!? substitute
1294-
: cvc5.Sort → (sorts : Array cvc5.Sort) → (replacements : Array cvc5.Sort) → Except Error cvc5.Sort
1299+
extern_def!? substitute :
1300+
cvc5.Sort → (sorts : Array cvc5.Sort) → (replacements : Array cvc5.Sort) → Except Error cvc5.Sort
12951301

1296-
instance : ToString cvc5.Sort := ⟨Sort.toString⟩
1297-
instance : Repr cvc5.Sort := ⟨fun self _ => self.toString⟩
1302+
/-- The arity of a datatype constructor sort. -/
1303+
extern_def!? getDatatypeConstructorArity : cvc5.Sort → Except Error Nat
1304+
1305+
/-- The domain sorts of a datatype constructor sort. -/
1306+
extern_def!? getDatatypeConstructorDomainSorts : cvc5.Sort → Except Error (Array cvc5.Sort)
1307+
1308+
/-- The codomain sort of a constructor sort. -/
1309+
extern_def!? getDatatypeConstructorCodomainSort : cvc5.Sort → Except Error cvc5.Sort
1310+
1311+
/-- The domain sort of a datatype selector sort. -/
1312+
extern_def!? getDatatypeSelectorDomainSort : cvc5.Sort → Except Error cvc5.Sort
1313+
1314+
/-- The codomain sort of a datatype selector sort. -/
1315+
extern_def!? getDatatypeSelectorCodomainSort : cvc5.Sort → Except Error cvc5.Sort
1316+
1317+
/-- The domain sort of a datatype tester sort. -/
1318+
extern_def!? getDatatypeTesterDomainSort : cvc5.Sort → Except Error cvc5.Sort
1319+
1320+
/-- The codomain sort of a datatype tester sort. -/
1321+
extern_def!? getDatatypeTesterCodomainSort : cvc5.Sort → Except Error cvc5.Sort
1322+
1323+
/-- Get the arity of a datatype sort.
1324+
1325+
Number of type parameters if the datatype is parametric, `0` otherwise.
1326+
-/
1327+
extern_def!? getDatatypeArity : cvc5.Sort → Except Error Nat
12981328

12991329
end cvc5.Sort
13001330

0 commit comments

Comments
 (0)