Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Z3Datatypes from SpriteLang Data #395

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/Refinements/Z3BoolSort.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@ Z3BoolSort >> containsFVar [
^false
]

{ #category : #'*Refinements' }
Z3BoolSort >> functionSort [
^nil
]

{ #category : #'*Refinements' }
Z3BoolSort >> isMono [
^true
Expand Down
6 changes: 6 additions & 0 deletions src/Refinements/Z3DatatypeSort.extension.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extension { #name : #Z3DatatypeSort }

{ #category : #'*Refinements' }
Z3DatatypeSort >> containsFVar [
^false
]
5 changes: 0 additions & 5 deletions src/Refinements/Z3IntSort.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ Z3IntSort >> containsFVar [
^false
]

{ #category : #'*Refinements' }
Z3IntSort >> functionSort [
^nil
]

{ #category : #'*Refinements' }
Z3IntSort >> isMono [
^true
Expand Down
5 changes: 5 additions & 0 deletions src/Refinements/Z3Sort.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Z3Sort >> falseRefinement [
^self | [ :x | Bool false ]
]

{ #category : #'*Refinements' }
Z3Sort >> functionSort [
^nil
]

{ #category : #'*Refinements' }
Z3Sort >> goFunctionSort: vs _: ss [
^{ vs reversed . ss reversed . self }
Expand Down
5 changes: 0 additions & 5 deletions src/Refinements/Z3UninterpretedSort.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ Z3UninterpretedSort >> containsFVar [
^true
]

{ #category : #'*Refinements' }
Z3UninterpretedSort >> functionSort [
^nil "functionSort $ FObj (symbol 'a') >> Nothing"
]

{ #category : #'*Refinements' }
Z3UninterpretedSort >> guest [
^PreSort hotel at: self unsafeName
Expand Down
25 changes: 25 additions & 0 deletions src/SpriteLang/Data.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ Data class >> name: ident vars: idents rvars: rvars ctors: bindToRType_Assocs in
yourself
]

{ #category : #checking }
Data >> checkData: aΓContext [
"
checkData :: Env -> SrcData -> CG SrcCstr
"
"BOGUS"
^CstrAnd of: #()
]

{ #category : #accessing }
Data >> ctors [
^ ctors
Expand Down Expand Up @@ -109,6 +118,22 @@ Data >> printOn: aStream [

]

{ #category : #reflect }
Data >> reflectData [
"
---------------------------------------------------------------------------------
reflectData :: SrcData -> F.DataDecl
---------------------------------------------------------------------------------
"
| tvM fCtors |
tvM := vars zip: (0 to: vars size - 1) with: [ :a :i | a -> (FVar new: i) ].
fCtors := ctors collectAssociations: [ :bind :s | s reflectCtor: bind tvSub: tvM ].
^DataDecl
ddTyCon: name symbolFTycon
ddVars: vars size
ddCtors: fCtors
]

{ #category : #accessing }
Data >> rvars [
^ rvars
Expand Down
61 changes: 61 additions & 0 deletions src/SpriteLang/FunSig.class.st
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
Class {
#name : #FunSig,
#superclass : #Object,
#instVars : [
'fsTVars',
'fsRVars',
'fsParams',
'fsOut'
],
#category : #SpriteLang
}

{ #category : #'instance creation' }
FunSig class >> tVars: tVars rVars: rVars params: params out: out [
^self basicNew
fsTVars: tVars;
fsRVars: rVars;
fsParams: params;
fsOut: out;
yourself
]

{ #category : #accessing }
FunSig >> fsOut [
^ fsOut
]

{ #category : #accessing }
FunSig >> fsOut: anObject [
fsOut := anObject
]

{ #category : #accessing }
FunSig >> fsParams [
^ fsParams
]

{ #category : #accessing }
FunSig >> fsParams: anObject [
fsParams := anObject
]

{ #category : #accessing }
FunSig >> fsRVars [
^ fsRVars
]

{ #category : #accessing }
FunSig >> fsRVars: anObject [
fsRVars := anObject
]

{ #category : #accessing }
FunSig >> fsTVars [
^ fsTVars
]

{ #category : #accessing }
FunSig >> fsTVars: anObject [
fsTVars := anObject
]
8 changes: 5 additions & 3 deletions src/SpriteLang/Prog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Prog >> solve [

{ #category : #verification }
Prog >> vcgen [
| expr′ env eL ps pqs c_cgi c cgi rfls syms c′ query |
| expr′ env eL ps pqs cI c_cgi c cgi rfls syms c′ decs |
expr′ := expr uniq2.
env := ΓContext empEnv: meas typs: data.
eL := expr′ elaborate: env.
Expand All @@ -103,16 +103,18 @@ Prog >> vcgen [
hcon symbol -> hcon sort
].
pqs := #(1 2 3) collect: [ :j | Qualifier pappQual: j ].
cI := [ CstrAnd of: (data collect: [ :t | t checkData: env ]) ] runCG key.
c_cgi := [ eL check: env rtype: TInt instance bTrue ] runCG.
c := c_cgi key. cgi := c_cgi value.
rfls := cgi cgiConsts.
syms := Dictionary newFromAssociations: ps, meas, rfls.
c′ := c strengthenInv: env.
decs := data collect: #reflectData.
^HornQuery
mkQuery_qs: quals, pqs
ks: cgi cgiKVars
cstr: "cI &" c′
cstr: cI & c′
syms: syms
defs: cgi cgiDefs
ddecls: #()
ddecls: decs
]
33 changes: 33 additions & 0 deletions src/SpriteLang/RType.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ fresh :: F.SrcSpan -> Env -> RType -> CG RType
self subclassResponsibility
]

{ #category : #reflect }
RType >> funSig [
"
funSig :: RType -> FunSig
"
| as_rs_t′ as rs t′ xts_ot xts ot |
as_rs_t′ := self bkAlls.
as := as_rs_t′ first. rs := as_rs_t′ second. t′ := as_rs_t′ third.
xts_ot := t′ bkFun.
xts := xts_ot key.
ot := xts_ot value.
^FunSig tVars: as rVars: rs params: xts out: ot
]

{ #category : #'as yet unclassified' }
RType >> generalize [
"Normalize types by generalizing tyvars, refactoring ref-var applications."
Expand Down Expand Up @@ -409,6 +423,25 @@ reflect :: Ident -> SrcExpr -> RType -> CG RType
^self reflectTy: f v: v expr: e
]

{ #category : #reflect }
RType >> reflectCtor: bind tvSub: tvSub [
"
reflectCtor :: TvSub -> (SrcBind, RType) -> F.DataCtor
Cf. Reflect.hs
NB: Here TvSub is 'type TvSub = [(Ident, F.Sort)]', not the other one!
"
| fldTs fFields |
fldTs := self funSig fsParams collect: #value.
fFields := fldTs zip: (0 to: fldTs size - 1) with: [ :t :i |
| fldName fldSort |
fldName := bind id selDataCon: i.
fldSort := t rtypeSort sortSubst: (Dictionary newFromAssociations: tvSub).
DataField dfName: fldName dfSort: fldSort ].
^DataCtor
dcName: bind id
dcFields: fFields
]

{ #category : #reflect }
RType >> reflectTy: f v: v expr: e [
"
Expand Down
8 changes: 8 additions & 0 deletions src/SpriteLang/String.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ rVar :: F.Symbol -> RType
^(TVar symbol: self) bTrue
]

{ #category : #'*SpriteLang' }
String >> selDataCon: i [
"
selDataCon :: DaCon -> Int -> F.Symbol
"
^self intSymbol: i
]

{ #category : #'*SpriteLang' }
String >> unifyX: anotherString [
^self
Expand Down
5 changes: 5 additions & 0 deletions src/SpriteLang/TCon.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,11 @@ TCon >> reft [
^r
]

{ #category : #'as yet unclassified' }
TCon >> rtypeSort [
^c symbolFTycon fAppTC: (ts collect: #rtypeSort)
]

{ #category : #'synthesis constraints' }
TCon >> singleton: x [
^TCon
Expand Down
Loading