@@ -569,6 +569,8 @@ private void EmitLine(string str)
569
569
private static string StateAdtReceivedSelector => $ "{ StateAdt } _Received";
570
570
private static string StateAdtMachinesSelector => $ "{ StateAdt } _Machines";
571
571
572
+ private static bool useLocalPrefix = false ;
573
+
572
574
private static string StateAdtConstruct ( string sent , string received , string machines )
573
575
{
574
576
return
@@ -598,7 +600,7 @@ private static string StateAdtDeclaration()
598
600
599
601
private static string InFlight ( string state , string action )
600
602
{
601
- return $ "({ StateAdtSelectSent ( state ) } [{ action } ] && !{ StateAdtSelectReceived ( state ) } [{ action } ])";
603
+ return useLocalPrefix ? $ "( { LocalPrefix } sent[ { action } ] && ! { StateAdtSelectReceived ( state ) } [ { action } ])" : $ "({ StateAdtSelectSent ( state ) } [{ action } ] && !{ StateAdtSelectReceived ( state ) } [{ action } ])";
602
604
}
603
605
604
606
private static string StateVar => $ "{ BuiltinPrefix } State";
@@ -1024,7 +1026,9 @@ private void GenerateSpecProcedures(List<Machine> specs, List<Invariant> goals,
1024
1026
foreach ( var v in spec . Fields )
1025
1027
EmitLine ( $ "{ GetLocalName ( v ) } = { SpecPrefix } { spec . Name } _{ v . Name } ;") ;
1026
1028
1029
+ useLocalPrefix = true ;
1027
1030
GenerateStmt ( f . Body , spec , goals , generateSanityChecks ) ;
1031
+ useLocalPrefix = false ;
1028
1032
1029
1033
// update the global variables
1030
1034
EmitLine ( $ "{ SpecPrefix } { spec . Name } _State = { LocalPrefix } state;") ;
@@ -1406,7 +1410,9 @@ private void GenerateMachineProcedures(Machine m, List<Invariant> goals, bool ge
1406
1410
EmitLine ( $ "{ GetLocalName ( v ) } = { MachineStateAdtSelectField ( currState , m , v ) } ;") ;
1407
1411
// foreach (var v in f.LocalVariables) EmitLine($"{GetLocalName(v)} = {DefaultValue(v.Type)};");
1408
1412
1413
+ useLocalPrefix = true ;
1409
1414
GenerateStmt ( f . Body , null , goals , generateSanityChecks ) ;
1415
+ useLocalPrefix = false ;
1410
1416
1411
1417
var fields = m . Fields . Select ( GetLocalName ) . Prepend ( $ "{ LocalPrefix } state") . ToList ( ) ;
1412
1418
@@ -2042,7 +2048,7 @@ ContainsExpr cexp when cexp.Collection.Type.Canonicalize() is SetType =>
2042
2048
s ) , // must deref for ADT!
2043
2049
PureCallExpr pexpr => $ "{ pexpr . Pure . Name } ({ string . Join ( ", " , pexpr . Arguments . Select ( ExprToString ) ) } )",
2044
2050
FlyingExpr fexpr => $ "{ InFlight ( StateVar , ExprToString ( fexpr . Instance ) ) } ",
2045
- SentExpr sexpr => $ "{ StateAdtSelectSent ( StateVar ) } [{ ExprToString ( sexpr . Instance ) } ]",
2051
+ SentExpr sexpr => useLocalPrefix ? $ " { LocalPrefix } sent[ { ExprToString ( sexpr . Instance ) } ]" : $ "{ StateAdtSelectSent ( StateVar ) } [{ ExprToString ( sexpr . Instance ) } ]",
2046
2052
TargetsExpr texpr =>
2047
2053
$ "({ LabelAdtSelectTarget ( ExprToString ( texpr . Instance ) ) } == { ExprToString ( texpr . Target ) } )",
2048
2054
_ => throw new NotSupportedException ( $ "Not supported expr ({ expr } ) at { GetLocation ( expr ) } ")
0 commit comments