Skip to content
Closed
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
13 changes: 8 additions & 5 deletions Strata/Languages/Laurel/LiftImperativeExpressions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -269,19 +269,22 @@ def transformExpr (expr : StmtExprMd) : LiftM StmtExprMd := do

| .StaticCall callee args =>
let model := (← get).model
let seqArgs ← args.reverse.mapM transformExpr
let seqCall := ⟨.StaticCall callee seqArgs.reverse, source⟩
if model.isFunction callee then
return seqCall
let seqArgs ← args.reverse.mapM transformExpr
return ⟨.StaticCall callee seqArgs.reverse, source⟩
else
-- Imperative call in expression position: lift it like an assignment
-- Imperative call in expression position: lift to an assignment
let prePrepends ← takePrepends
let seqArgs ← args.reverse.mapM transformExpr
let argPrepends ← takePrepends
let seqCall := ⟨.StaticCall callee seqArgs.reverse, source⟩
let callResultVar ← freshCondVar
let callResultType ← computeType expr
let liftedCall := [
⟨ (.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 ++ argPrepends ++ prePrepends ++ liftedCall}
return bare (.Var (.Local callResultVar))

| .IfThenElse cond thenBranch elseBranch =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,9 @@ procedure addProcCaller(): int
{
var x: int := 0;
var y: int := addProc({x := 1; x}, {x := x + 10; x});
assert y == 11

// The next statement is not translated correctly.
// I think it's a bug in the handling of StaticCall
// Where a reference is substituted when it should not be
// var z: int := addProc({x := 1; x}, {x := x + 10; x}) + (x := 3);
// assert z == 14
assert y == 11;
var z: int := addProc({x := 1; x}, {x := x + 10; x}) + (x := 3);
assert z == 15
};
"

Expand Down
Loading