diff --git a/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs b/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs index 0ac3aef8e..abba9be83 100644 --- a/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs +++ b/Src/PCompiler/CompilerCore/Backend/PExplicit/PExplicitCodeGenerator.cs @@ -1022,6 +1022,8 @@ private bool WriteStmt(Function function, CompilationContext context, StringWrit break; case ReceiveSplitStmt splitStmt: context.WriteLine(output, $"{CompilationContext.CurrentMachine}.blockUntil(\"{context.GetContinuationName(splitStmt.Cont)}\");"); + context.Write(output, "return;"); + exited = true; break; default: throw new NotImplementedException($"Statement type '{stmt.GetType().Name}' is not supported, found in {function.Name}"); diff --git a/Src/PCompiler/CompilerCore/Backend/PExplicit/TransformASTPass.cs b/Src/PCompiler/CompilerCore/Backend/PExplicit/TransformASTPass.cs index 65b3f7304..e07592633 100644 --- a/Src/PCompiler/CompilerCore/Backend/PExplicit/TransformASTPass.cs +++ b/Src/PCompiler/CompilerCore/Backend/PExplicit/TransformASTPass.cs @@ -190,7 +190,7 @@ static private void GenerateInline(Function caller, Function callee, IReadOnlyLi callNum++; } - static private List ReplaceReturn(IReadOnlyList body, IPExpr location) + private static List ReplaceReturn(IReadOnlyList body, IPExpr location) { var newBody = new List(); foreach (var stmt in body) @@ -468,7 +468,7 @@ static private IPExpr ReplaceVars(IPExpr expr, Dictionary var } } - static private Function TransformFunction(Function function, Machine machine) + private static Function TransformFunction(Function function, Machine machine) { if (function.CanReceive != true) { return function; @@ -492,7 +492,7 @@ static private Function TransformFunction(Function function, Machine machine) return transformedFunction; } - static private IPStmt ReplaceBreaks(IPStmt stmt, List afterStmts) + static private IPStmt InlineAfterAndReplaceBreaks(IPStmt stmt, List afterStmts) { if (stmt == null) return null; var statements = new List(); @@ -501,11 +501,11 @@ static private IPStmt ReplaceBreaks(IPStmt stmt, List afterStmts) case CompoundStmt compoundStmt: foreach (var inner in compoundStmt.Statements) { - statements.Add(ReplaceBreaks(inner, afterStmts)); + statements.Add(InlineAfterAndReplaceBreaks(inner, afterStmts)); } return new CompoundStmt(compoundStmt.SourceLocation, statements); case IfStmt ifStmt: - return new IfStmt(ifStmt.SourceLocation, ifStmt.Condition, ReplaceBreaks(ifStmt.ThenBranch, afterStmts), ReplaceBreaks(ifStmt.ElseBranch, afterStmts)); + return new IfStmt(ifStmt.SourceLocation, ifStmt.Condition, InlineAfterAndReplaceBreaks(ifStmt.ThenBranch, afterStmts), InlineAfterAndReplaceBreaks(ifStmt.ElseBranch, afterStmts)); case ReceiveStmt receiveStmt: var cases = new Dictionary(); foreach(var entry in receiveStmt.Cases) @@ -521,7 +521,7 @@ static private IPStmt ReplaceBreaks(IPStmt stmt, List afterStmts) foreach (var param in entry.Value.Signature.Parameters) replacement.Signature.Parameters.Add(param); replacement.Signature.ReturnType = entry.Value.Signature.ReturnType; foreach (var callee in entry.Value.Callees) replacement.AddCallee(callee); - replacement.Body = (CompoundStmt) ReplaceBreaks(entry.Value.Body, afterStmts); + replacement.Body = (CompoundStmt) InlineAfterAndReplaceBreaks(entry.Value.Body, afterStmts); cases.Add(entry.Key, replacement); } return new ReceiveStmt(receiveStmt.SourceLocation, cases); @@ -542,7 +542,7 @@ static private IPStmt ReplaceBreaks(IPStmt stmt, List afterStmts) } } - static private bool CanReceive(IPStmt stmt) + private static bool CanReceive(IPStmt stmt) { if (stmt == null) return false; switch(stmt) @@ -567,7 +567,7 @@ static private bool CanReceive(IPStmt stmt) } } - static private IPStmt HandleReceives(IPStmt statement, Function function, Machine machine) + private static IPStmt HandleReceives(IPStmt statement, Function function, Machine machine) { switch (statement) { @@ -604,6 +604,12 @@ static private IPStmt HandleReceives(IPStmt statement, Function function, Machin thenStmts = new List(cond.ThenBranch.Statements); if (cond.ElseBranch != null) elseStmts = new List(cond.ElseBranch.Statements); + if (CanReceive(cond) && (after != null)) + { + thenStmts.Add(after); + elseStmts.Add(after); + after = null; + } IPStmt thenBody = new CompoundStmt(cond.SourceLocation, thenStmts); IPStmt elseBody = new CompoundStmt(cond.SourceLocation, elseStmts); thenBody = HandleReceives(thenBody, function, machine); @@ -747,7 +753,7 @@ static private IPStmt HandleReceives(IPStmt statement, Function function, Machin while (bodyEnumerator.MoveNext()) { var stmt = bodyEnumerator.Current; - var replaceBreak = ReplaceBreaks(stmt, afterStmts); + var replaceBreak = InlineAfterAndReplaceBreaks(stmt, afterStmts); if (replaceBreak != null) { loopBody.Add(ReplaceVars(replaceBreak, newVarMap)); } diff --git a/Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/logger/PExplicitLogger.java b/Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/logger/PExplicitLogger.java index bc2c39488..a5137ab72 100644 --- a/Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/logger/PExplicitLogger.java +++ b/Src/PRuntimes/PExplicitRuntime/src/main/java/pexplicit/runtime/logger/PExplicitLogger.java @@ -256,7 +256,7 @@ public static void logCurrentDataChoice(PValue choice, int step, int idx) { public static void logNewState(int step, int idx, Object stateKey, SortedSet machines) { if (verbosity > 3) { log.info(String.format(" @%d::%d new state with key %s", step, idx, stateKey)); - if (verbosity > 4) { + if (verbosity > 6) { log.info(String.format(" %s", ComputeHash.getExactString(machines))); } }