@@ -307,66 +307,65 @@ private void WriteMachineFields(CompilationContext context, StringWriter output,
307
307
}
308
308
309
309
foreach ( var field in machine . Fields )
310
- context . WriteLine ( output , $ "private { GetPExplicitType ( field . Type ) } { CompilationContext . GetVar ( field . Name ) } = { GetDefaultValue ( field . Type ) } ;") ;
311
-
312
- context . WriteLine ( output ) ;
313
-
314
- context . WriteLine ( output , "@Generated" ) ;
315
- context . WriteLine ( output , "@Override" ) ;
316
- context . WriteLine ( output , "public void reset() {" ) ;
317
- context . WriteLine ( output , " super.reset();" ) ;
318
- foreach ( var field in machine . Fields )
319
- context . WriteLine ( output , $ " { CompilationContext . GetVar ( field . Name ) } = { GetDefaultValue ( field . Type ) } ;") ;
320
- context . WriteLine ( output , "}" ) ;
321
- context . WriteLine ( output ) ;
322
-
323
- context . WriteLine ( output , "@Generated" ) ;
324
- context . WriteLine ( output , "@Override" ) ;
325
- context . WriteLine ( output , "public List<String> getLocalVarNames() {" ) ;
326
- context . WriteLine ( output , " List<String> result = super.getLocalVarNames();" ) ;
327
- foreach ( var field in machine . Fields )
328
- {
329
- context . WriteLine ( output , $ " result.add(\" { CompilationContext . GetVar ( field . Name ) } \" );") ;
330
- }
331
- context . WriteLine ( output , " return result;" ) ;
332
- context . WriteLine ( output , "}" ) ;
310
+ context . WriteLine ( output , $ "public { GetPExplicitType ( field . Type ) } { CompilationContext . GetVar ( field . Name ) } = { GetDefaultValue ( field . Type ) } ;") ;
333
311
context . WriteLine ( output ) ;
334
312
335
- context . WriteLine ( output , "@Generated" ) ;
336
- context . WriteLine ( output , "@Override" ) ;
337
- context . WriteLine ( output , "public List<Object> getLocalVarValues() {" ) ;
338
- context . WriteLine ( output , " List<Object> result = super.getLocalVarValues();" ) ;
339
- foreach ( var field in machine . Fields )
340
- {
341
- context . WriteLine ( output , $ " result.add({ CompilationContext . GetVar ( field . Name ) } );") ;
342
- }
343
- context . WriteLine ( output , " return result;" ) ;
344
- context . WriteLine ( output , "}" ) ;
345
- context . WriteLine ( output ) ;
346
-
347
- context . WriteLine ( output , "@Generated" ) ;
348
- context . WriteLine ( output , "@Override" ) ;
349
- context . WriteLine ( output , "public List<Object> copyLocalVarValues() {" ) ;
350
- context . WriteLine ( output , " List<Object> result = super.copyLocalVarValues();" ) ;
351
- foreach ( var field in machine . Fields )
352
- {
353
- context . WriteLine ( output , $ " result.add({ CompilationContext . GetVar ( field . Name ) } );") ;
354
- }
355
- context . WriteLine ( output , " return result;" ) ;
356
- context . WriteLine ( output , "}" ) ;
357
- context . WriteLine ( output ) ;
358
-
359
- context . WriteLine ( output , "@Generated" ) ;
360
- context . WriteLine ( output , "@Override" ) ;
361
- context . WriteLine ( output , "protected int setLocalVarValues(List<Object> values) {" ) ;
362
- context . WriteLine ( output , " int idx = super.setLocalVarValues(values);" ) ;
363
- foreach ( var field in machine . Fields )
364
- {
365
- context . WriteLine ( output , $ " { CompilationContext . GetVar ( field . Name ) } = ({ GetPExplicitType ( field . Type ) } ) values.get(idx++);") ;
366
- }
367
- context . WriteLine ( output , " return idx;" ) ;
368
- context . WriteLine ( output , "}" ) ;
369
- context . WriteLine ( output ) ;
313
+ // context.WriteLine(output, "@Generated");
314
+ // context.WriteLine(output, "@Override");
315
+ // context.WriteLine(output, "public void reset() {");
316
+ // context.WriteLine(output, " super.reset();");
317
+ // foreach (var field in machine.Fields)
318
+ // context.WriteLine(output, $" {CompilationContext.GetVar(field.Name)} = {GetDefaultValue(field.Type)};");
319
+ // context.WriteLine(output, "}");
320
+ // context.WriteLine(output);
321
+ //
322
+ // context.WriteLine(output, "@Generated");
323
+ // // context.WriteLine(output, "@Override");
324
+ // context.WriteLine(output, "public List<String> getLocalVarNames() {");
325
+ // context.WriteLine(output, " List<String> result = super.getLocalVarNames();");
326
+ // foreach (var field in machine.Fields)
327
+ // {
328
+ // context.WriteLine(output, $" result.add(\"{CompilationContext.GetVar(field.Name)}\");");
329
+ // }
330
+ // context.WriteLine(output, " return result;");
331
+ // context.WriteLine(output, "}");
332
+ // context.WriteLine(output);
333
+ //
334
+ // context.WriteLine(output, "@Generated");
335
+ // context.WriteLine(output, "@Override");
336
+ // context.WriteLine(output, "public List<Object> getLocalVarValues() {");
337
+ // context.WriteLine(output, " List<Object> result = super.getLocalVarValues();");
338
+ // foreach (var field in machine.Fields)
339
+ // {
340
+ // context.WriteLine(output, $" result.add({CompilationContext.GetVar(field.Name)});");
341
+ // }
342
+ // context.WriteLine(output, " return result;");
343
+ // context.WriteLine(output, "}");
344
+ // context.WriteLine(output);
345
+ //
346
+ // context.WriteLine(output, "@Generated");
347
+ // context.WriteLine(output, "@Override");
348
+ // context.WriteLine(output, "public List<Object> copyLocalVarValues() {");
349
+ // context.WriteLine(output, " List<Object> result = super.copyLocalVarValues();");
350
+ // foreach (var field in machine.Fields)
351
+ // {
352
+ // context.WriteLine(output, $" result.add({CompilationContext.GetVar(field.Name)});");
353
+ // }
354
+ // context.WriteLine(output, " return result;");
355
+ // context.WriteLine(output, "}");
356
+ // context.WriteLine(output);
357
+ //
358
+ // context.WriteLine(output, "@Generated");
359
+ // context.WriteLine(output, "@Override");
360
+ // context.WriteLine(output, "protected int setLocalVarValues(List<Object> values) {");
361
+ // context.WriteLine(output, " int idx = super.setLocalVarValues(values);");
362
+ // foreach (var field in machine.Fields)
363
+ // {
364
+ // context.WriteLine(output, $" {CompilationContext.GetVar(field.Name)} = ({GetPExplicitType(field.Type)}) values.get(idx++);");
365
+ // }
366
+ // context.WriteLine(output, " return idx;");
367
+ // context.WriteLine(output, "}");
368
+ // context.WriteLine(output);
370
369
}
371
370
372
371
private void WriteMachineConstructor ( CompilationContext context , StringWriter output , Machine machine )
@@ -393,21 +392,7 @@ private void WriteMachineConstructor(CompilationContext context, StringWriter ou
393
392
if ( method is Continuation )
394
393
{
395
394
var cont = ( Continuation ) method ;
396
- context . WriteLine ( output , "registerContinuation(" ) ;
397
- context . WriteLine ( output , $ "\" { context . GetContinuationName ( cont ) } \" ") ;
398
- context . WriteLine ( output , $ ", (machine, msg) -> { context . GetContinuationName ( cont ) } (machine, msg)") ;
399
- context . WriteLine ( output , $ ", () -> clear_{ context . GetContinuationName ( cont ) } ()") ;
400
- foreach ( var ( caseEvent , _) in cont . Cases )
401
- {
402
- context . Write ( output , $ ", \" { caseEvent . Name } \" ") ;
403
- }
404
- context . WriteLine ( output , ");" ) ;
405
-
406
- // context.Write(output, $"continuations.put(\"{context.GetContinuationName(cont)}\", ");
407
- // context.Write(output, $"(pc) -> ((continuation_outcome, msg) -> {context.GetContinuationName(cont)}(");
408
- // context.Write(output, "continuation_outcome");
409
- // context.WriteLine(output, $", msg)));");
410
- // context.WriteLine(output, $"clearContinuationVars.add(() -> clear_{context.GetContinuationName(cont)}());");
395
+ context . WriteLine ( output , $ "register_{ context . GetContinuationName ( cont ) } ();") ;
411
396
}
412
397
}
413
398
@@ -1021,7 +1006,13 @@ private bool WriteStmt(Function function, CompilationContext context, StringWrit
1021
1006
context . WriteLine ( output , ");" ) ;
1022
1007
break ;
1023
1008
case ReceiveSplitStmt splitStmt :
1024
- context . WriteLine ( output , $ "{ CompilationContext . CurrentMachine } .blockUntil(\" { context . GetContinuationName ( splitStmt . Cont ) } \" );") ;
1009
+ Continuation continuation = splitStmt . Cont ;
1010
+ context . WriteLine ( output , $ "PContinuation { context . GetContinuationName ( continuation ) } = getContinuation(\" { context . GetContinuationName ( continuation ) } \" );") ;
1011
+ foreach ( var local in continuation . LocalParameters )
1012
+ {
1013
+ context . WriteLine ( output , $ "{ context . GetContinuationName ( continuation ) } .setVar(\" { continuation . StoreForLocal [ local ] . Name } \" , { CompilationContext . GetVar ( local . Name ) } );") ;
1014
+ }
1015
+ context . WriteLine ( output , $ "{ CompilationContext . CurrentMachine } .blockUntil(\" { context . GetContinuationName ( continuation ) } \" );") ;
1025
1016
context . Write ( output , "return;" ) ;
1026
1017
exited = true ;
1027
1018
break ;
@@ -1039,11 +1030,20 @@ private void WriteContinuation(CompilationContext context, StringWriter output,
1039
1030
throw new NotImplementedException ( $ "Receive statement in a function with non-void return type is not supported. Found in function named { continuation . ParentFunction . Name } .") ;
1040
1031
}
1041
1032
1042
- context . Write ( output , $ "void clear_ { context . GetContinuationName ( continuation ) } () ") ;
1033
+ context . Write ( output , $ "void register_ { context . GetContinuationName ( continuation ) } () ") ;
1043
1034
context . WriteLine ( output , "{" ) ;
1035
+ context . Write ( output , $ "PContinuation { context . GetContinuationName ( continuation ) } = registerContinuation(") ;
1036
+ context . WriteLine ( output , $ "\" { context . GetContinuationName ( continuation ) } \" ") ;
1037
+ context . WriteLine ( output , $ ", (machine, msg) -> { context . GetContinuationName ( continuation ) } (machine, msg)") ;
1038
+ foreach ( var ( caseEvent , _) in continuation . Cases )
1039
+ {
1040
+ context . Write ( output , $ ", \" { caseEvent . Name } \" ") ;
1041
+ }
1042
+ context . WriteLine ( output , ");" ) ;
1043
+
1044
1044
foreach ( var param in continuation . StoreParameters )
1045
1045
{
1046
- context . WriteLine ( output , $ "{ GetPExplicitType ( param . Type ) } { CompilationContext . GetVar ( param . Name ) } = { GetDefaultValue ( param . Type ) } ;") ;
1046
+ context . WriteLine ( output , $ "{ context . GetContinuationName ( continuation ) } .addVar( \" { param . Name } \" , { GetDefaultValue ( param . Type ) } ) ;") ;
1047
1047
}
1048
1048
context . WriteLine ( output , "}" ) ;
1049
1049
@@ -1063,11 +1063,12 @@ private void WriteContinuation(CompilationContext context, StringWriter output,
1063
1063
context . WriteLine ( output , "{" ) ;
1064
1064
1065
1065
var continuationLocalParams = new HashSet < string > ( ) ;
1066
+ context . WriteLine ( output , $ "PContinuation { context . GetContinuationName ( continuation ) } = getContinuation(\" { context . GetContinuationName ( continuation ) } \" );") ;
1066
1067
foreach ( var local in continuation . LocalParameters )
1067
1068
{
1068
1069
continuationLocalParams . Add ( local . Name ) ;
1069
1070
context . Write ( output , $ "{ GetPExplicitType ( local . Type ) } { CompilationContext . GetVar ( local . Name ) } ") ;
1070
- context . WriteLine ( output , $ "= { CompilationContext . GetVar ( continuation . StoreForLocal [ local ] . Name ) } ;") ;
1071
+ context . WriteLine ( output , $ " = ( { GetPExplicitType ( local . Type ) } ) { context . GetContinuationName ( continuation ) } .getVar( \" { continuation . StoreForLocal [ local ] . Name } \" ) ;") ;
1071
1072
}
1072
1073
1073
1074
context . WriteLine ( output , $ "switch ({ messageName } .getEvent().toString())") ;
0 commit comments