Skip to content

Commit

Permalink
Implement beginnigs of Z3 interface for DataDecl
Browse files Browse the repository at this point in the history
NB: Still no datatype recursion!!!  See e.g. Horn L5cons00data.
  • Loading branch information
shingarov committed Oct 29, 2024
1 parent b7d5d77 commit fd376e9
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Refinements/DataCtor.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ DataCtor >> printOn: aStream [
nextPutAll: ')'
]

{ #category : #'SMT interface' }
DataCtor >> smt2ctor: ts [
| instantiatedFields |
instantiatedFields := dcFields collect: [ :field | field dfName -> (field smt2field: ts) ].
^Z3Constructor
name: self symbol
recognizer: 'is-', self symbol
fields: instantiatedFields
referencing: (Array new: dcFields size withAll: 0) "BOGUS, implement mutually-recursive ADTs!"
]

{ #category : #Symbolic }
DataCtor >> symbol [
^dcName
Expand Down
14 changes: 14 additions & 0 deletions src/Refinements/DataDecl.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,26 @@ DataDecl >> gtInspectorConstructorsIn: composite [
display: [ ddCtors ]
]

{ #category : #'SMT interface' }
DataDecl >> instantiateZ3Sort: ts [
| ctors z3datatypeSort |
ctors := self smt2datactors: ts.
z3datatypeSort := Z3DatatypeSort name: self symbol constructors: ctors.
ctors do: #delete.
^z3datatypeSort
]

{ #category : #printing }
DataDecl >> printOn: aStream [
aStream nextPutAll: 'data '.
aStream nextPutAll: self ddTyCon symbol
]

{ #category : #'SMT interface' }
DataDecl >> smt2datactors: ts [
^ddCtors collect: [ :ctor | ctor smt2ctor: ts ]
]

{ #category : #Symbolic }
DataDecl >> symbol [
"
Expand Down
8 changes: 8 additions & 0 deletions src/Refinements/DataField.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,11 @@ DataField >> dfSort [
DataField >> dfSort: anObject [
dfSort := anObject
]

{ #category : #'SMT interface' }
DataField >> smt2field: ts [
| θ monomorphicSort |
θ := Dictionary newFromAssociations: (ts collectWithIndex: [ :t :idx | idx-1 -> t ]).
monomorphicSort := dfSort apply: θ.
^monomorphicSort "z3sort"
]

0 comments on commit fd376e9

Please sign in to comment.