Skip to content

Commit

Permalink
Refactor Prog>>vcgen
Browse files Browse the repository at this point in the history
  • Loading branch information
shingarov committed Nov 18, 2024
1 parent 423bc25 commit aef45c4
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 22 deletions.
41 changes: 35 additions & 6 deletions src/Refinements/HornQuery.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Cf. Info.hs
{ #category : #'instance creation' }
HornQuery class >> fromThings: things [
| q |
q := self new.
q := self basicNew.
things do: [ :x | x addToQuery: q ].
^q
]
Expand Down Expand Up @@ -101,10 +101,23 @@ HornQuery class >> hornVariables: ks smalltalkBlock: aBlockClosure [
^self fromThings: {cstr}, ks
]

{ #category : #'as yet unclassified' }
HornQuery >> addPapp: j [
(HCon papp: j) addToQuery: self.
(Qualifier pappQual: j) addToQuery: self
{ #category : #'instance creation' }
HornQuery class >> mkQuery_qs: qs ks: ks cstr: c syms: syms defs: defs ddecls: ddecls [
"
mkQuery :: [F.Qualifier]
-> [H.Var a]
-> H.Cstr a
-> M.HashMap F.Symbol F.Sort
-> [F.Equation]
-> [F.DataDecl]
-> H.Query a
"
^self basicNew qs: qs ks: ks cstr: c syms: syms defs: defs ddecls: ddecls
]

{ #category : #'instance creation' }
HornQuery class >> new [
self shouldNotImplement
]

{ #category : #accessing }
Expand Down Expand Up @@ -288,6 +301,22 @@ HornQuery >> qMats: anObject [
qMats := anObject
]

{ #category : #'private - initialization' }
HornQuery >> qs: qs ks: ks cstr: c syms: syms defs: defs ddecls: ddecls [
qualifiers := qs.
vars := ks.
qCstr := {c}.
qCon := syms.
qDis := Dictionary new.
qEqns := defs.
qMats := #().
qData := ddecls.

defs isEmpty ifFalse: [ HOpt rewrite addToQuery: self ].

^self
]

{ #category : #accessing }
HornQuery >> qualifiers [
"qualifiers over which to solve cstrs"
Expand All @@ -304,7 +333,7 @@ HornQuery >> solve [
solve
]

{ #category : #private }
{ #category : #accessing }
HornQuery >> vars [
"κ-vars, with parameter-sorts"
vars isNil ifTrue: [ vars := OrderedCollection new ].
Expand Down
2 changes: 1 addition & 1 deletion src/SpriteLang/CGInfo.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CGInfo >> addReflectVar: f rtype: t xts: xts outputSort: ot expr: e [
expr: e
sort: ot.
self cgiDefs add: fDef.
self cgiConsts add: (HCon symbol: f sort: t rtypeSort)
self cgiConsts add: f -> t rtypeSort
]

{ #category : #API }
Expand Down
5 changes: 5 additions & 0 deletions src/SpriteLang/HCstr.extension.st
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ mkHead :: F.SrcSpan -> H.Pred -> SrcCstr
^CstrAnd of: (smashed collect: #cHead)
]

{ #category : #'*SpriteLang' }
HCstr >> strengthenInv:Context [
^self
]

{ #category : #'*SpriteLang' }
HCstr class >> subPs: coll1 _: coll2 [
| p1 p1s p2 p2s |
Expand Down
34 changes: 19 additions & 15 deletions src/SpriteLang/Prog.class.st
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,26 @@ Prog >> solve [

{ #category : #verification }
Prog >> vcgen [
| expr′ env expr′′ c_cgi c cgi query |
| expr′ env eL ps pqs c_cgi c cgi rfls syms c′ query |
expr′ := expr uniq2.
env := ΓContext empEnv: meas typs: data.
expr′′ := expr′ elaborate: env.
c_cgi := [ expr′′ check: env rtype: TInt instance bTrue ] runCG.
c := c_cgi key. cgi := c_cgi value.
query := HornQuery new.
c addToQuery: query.
cgi cgiKVars do: [ :kVar | kVar addToQuery: query ].
quals do: [ :q | q addToQuery: query ].
query qCon: (Dictionary newFromAssociations: meas).
#(1 2 3) do: [ :j | query addPapp: j ].
cgi cgiDefs do: [ :equ | equ addToQuery: query ].
cgi cgiConsts do: [ :con | con addToQuery: query ].
cgi cgiDefs isEmpty ifFalse: [
HOpt rewrite addToQuery: query
eL := expr′ elaborate: env.
ps := #(1 2 3) collect: [ :j |
| hcon |
hcon := HCon papp: j.
hcon symbol -> hcon sort
].
^query
pqs := #(1 2 3) collect: [ :j | Qualifier pappQual: j ].
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.
^HornQuery
mkQuery_qs: quals, pqs
ks: cgi cgiKVars
cstr: "cI &" c′
syms: syms
defs: cgi cgiDefs
ddecls: #()
]

0 comments on commit aef45c4

Please sign in to comment.