Skip to content
Draft
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
17 changes: 12 additions & 5 deletions Strata/Languages/Laurel/LiftImperativeExpressions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -274,14 +274,21 @@ def transformExpr (expr : StmtExprMd) : LiftM StmtExprMd := do
if model.isFunction callee then
return seqCall
else
-- Imperative call in expression position: lift it like an assignment
-- Imperative call in expression position: lift to an assignment.
let previousPrependedStmts ← takePrepends
let outputs := match model.get callee with
| .staticProcedure proc => proc.outputs
| .instanceProcedure _ proc => proc.outputs
| _ => []
let callResultVar ← freshCondVar
let callResultType ← computeType expr
let callResultType ← match outputs with
| [single] => pure single.type
| _ => computeType expr
let liftedCall := [
(.Var (.Declare ⟨callResultVar, callResultType⟩)), source ⟩,
⟨.Assign [⟨ .Local callResultVar, source⟩] seqCall, source⟩
⟨.Var (.Declare ⟨callResultVar, callResultType⟩), source⟩,
⟨.Assign [⟨.Local callResultVar, source⟩] seqCall, source⟩
]
modify fun s => { s with prependedStmts := s.prependedStmts ++ liftedCall}
modify fun s => { s with prependedStmts := s.prependedStmts ++ liftedCall ++ previousPrependedStmts}
return bare (.Var (.Local callResultVar))

| .IfThenElse cond thenBranch elseBranch =>
Expand Down
Loading