@@ -33,7 +33,7 @@ The presence of the empty program, `.Mir`, on the `<k>` cell indicates that the
33
33
``` k
34
34
rule <k> .Mir => #initialized() ... </k>
35
35
<phase> Initialization </phase>
36
- rule <k> #initialized() => #executeFunctionLike(Fn(String2IdentifierToken(" main") :: .FunctionPath), .ArgumentList ) ... </k>
36
+ rule <k> #initialized() => #executeFunctionLike(Fn(main :: .FunctionPath), .OperandList ) ... </k>
37
37
<phase> Initialization => Execution </phase>
38
38
```
39
39
@@ -45,11 +45,11 @@ If we are, then we stop execution and enter the finalization phase. Otherwise, i
45
45
<callStack> ListItem(FUNCTION_KEY) => .List </callStack>
46
46
<phase> Execution => Finalization </phase>
47
47
<returncode> _ => 0 </returncode>
48
- requires FUNCTION_KEY ==K Fn(String2IdentifierToken(" main") )
48
+ requires FUNCTION_KEY ==K Fn(main)
49
49
50
50
rule <k> #return(FUNCTION_KEY, _) => .K ... </k>
51
51
<callStack> ListItem(FUNCTION_KEY) XS => XS </callStack>
52
- requires FUNCTION_KEY =/=K Fn(String2IdentifierToken(" main") )
52
+ requires FUNCTION_KEY =/=K Fn(main)
53
53
endmodule
54
54
```
55
55
@@ -310,14 +310,16 @@ Executing a function-like means:
310
310
Note that the ` main ` function is special: it does not have a caller.
311
311
312
312
``` k
313
- syntax MirSimulation ::= #executeFunctionLike(FunctionLikeKey, ArgumentList)
313
+ syntax IdentifierToken ::= "main" [token]
314
+
315
+ syntax MirSimulation ::= #executeFunctionLike(FunctionLikeKey, OperandList)
314
316
//--------------------------------------------------------------------------
315
317
rule <k> #executeFunctionLike(FN_KEY, _ARGS)
316
318
=> #executeBasicBlock(FN_KEY, 0)
317
319
...
318
320
</k>
319
321
<callStack> .List => ListItem(FN_KEY) </callStack>
320
- requires FN_KEY ==K Fn(String2IdentifierToken(" main") :: .FunctionPath)
322
+ requires FN_KEY ==K Fn(main :: .FunctionPath)
321
323
rule <k> #executeFunctionLike(CALLEE_FN_KEY, ARGS)
322
324
=> #instantiateArguments(CALLER_FN_KEY, ARGS, 1)
323
325
~> #executeBasicBlock(CALLEE_FN_KEY, 0)
@@ -337,7 +339,7 @@ Note that the `main` function is special: it does not have a caller.
337
339
<callStack> ListItem(Rec(PATH, _)) _STACK </callStack> [priority(49)]
338
340
339
341
// TODO: Either save unimplemented stack frame for correct initial values, or clear values
340
- syntax MirSimulation ::= #addRecursiveFrame(FunctionLikeKey, ArgumentList )
342
+ syntax MirSimulation ::= #addRecursiveFrame(FunctionLikeKey, OperandList )
341
343
//-------------------------------------------------------------------------
342
344
rule <k> #addRecursiveFrame(Fn(PATH), ARGS)
343
345
=> #instantiateArguments(Rec(PATH, 0), ARGS, 1)
@@ -364,10 +366,10 @@ Note that the `main` function is special: it does not have a caller.
364
366
Assign arguments (actual parameters) to formal parameters of a function-like:
365
367
366
368
``` k
367
- syntax MirSimulation ::= #instantiateArguments(FunctionLikeKey, ArgumentList , Int)
369
+ syntax MirSimulation ::= #instantiateArguments(FunctionLikeKey, OperandList , Int)
368
370
//--------------------------------------------------------------------------------
369
- rule <k> #instantiateArguments(_FN_KEY, .ArgumentList , _) => .K ... </k>
370
- rule <k> #instantiateArguments(FN_KEY, (ARG, REST):ArgumentList , ARGUMENT_NUMBER:Int)
371
+ rule <k> #instantiateArguments(_FN_KEY, .OperandList , _) => .K ... </k>
372
+ rule <k> #instantiateArguments(FN_KEY, (ARG, REST):OperandList , ARGUMENT_NUMBER:Int)
371
373
=> #writeLocal(CALLEE_FN_KEY, Int2Local(ARGUMENT_NUMBER), evalOperand(CALLER_FN_KEY, ARG))
372
374
~> #instantiateArguments(FN_KEY, REST, ARGUMENT_NUMBER +Int 1)
373
375
...
@@ -489,32 +491,38 @@ or panics if the function-like or the block is missing:
489
491
...
490
492
</k>
491
493
<callStack> ListItem(Fn(FNAME)) ... </callStack>
492
- requires FNAME ==K toFunctionPath(OTHER_FN_NAME) [priority(49)]
494
+ requires FNAME ==K toFunctionPath(OTHER_FN_NAME) [priority(49)]
493
495
rule <k> #executeTerminator(DEST_LOCAL:Local = OTHER_FN_NAME:PathInExpression ( ARGS ) -> ((NEXT:BBName _):BB))
494
496
=> #executeFunctionLike(Fn(toFunctionPath(OTHER_FN_NAME)), ARGS)
495
497
~> #transferLocal(Rec(toFunctionPath(OTHER_FN_NAME), DEPTH +Int 1), Int2Local(0), Rec(FNAME, DEPTH), DEST_LOCAL)
496
498
~> #executeBasicBlock(Rec(FNAME, DEPTH), BBName2Int(NEXT))
497
499
...
498
500
</k>
499
501
<callStack> ListItem(Rec(FNAME, DEPTH)) ... </callStack>
500
- requires FNAME ==K toFunctionPath(OTHER_FN_NAME) [priority(49)]
502
+ requires FNAME ==K toFunctionPath(OTHER_FN_NAME) [priority(49)]
501
503
rule <k> #executeTerminator(switchInt (ARG:Operand) -> [ TARGETS:SwitchTargets , otherwise : OTHERWISE:BB ])
502
504
=> #switchInt(FN_KEY, castMIRValueToInt(evalOperand(FN_KEY, ARG)), TARGETS, OTHERWISE)
503
505
...
504
506
</k>
505
507
<callStack> ListItem(FN_KEY) ... </callStack>
506
508
requires isInt(castMIRValueToInt(evalOperand(FN_KEY, ARG)))
507
- rule <k> #executeTerminator(_:Local = PANIC_CALL (ARG, .ArgumentList ))
509
+ rule <k> #executeTerminator(_:Local = PANIC_CALL (ARG, .OperandList ))
508
510
=> #panic(FN_KEY, PanicCall, ARG)
509
511
...
510
512
</k>
511
513
<callStack> ListItem(FN_KEY) ... </callStack>
512
- requires PANIC_CALL ==K String2IdentifierToken("core") :: String2IdentifierToken("panicking") :: String2IdentifierToken("panic") :: .ExpressionPathList
514
+ requires PANIC_CALL ==K String2IdentifierToken("core") :: String2IdentifierToken("panicking") :: String2IdentifierToken("panic") :: .ExpressionPathList
513
515
rule <k> #executeTerminator(TERMIANTOR:Terminator)
514
516
=> #internalPanic(FN_KEY, NotImplemented, TERMIANTOR)
515
517
...
516
518
</k>
517
519
<callStack> ListItem(FN_KEY) ... </callStack> [owise]
520
+
521
+ // Option Unwrap Call
522
+ rule <k> #executeTerminator(DEST_LOCAL:Local = Option :: < _TYPES > :: unwrap :: .ExpressionPathList ( ARG , .OperandList ) -> ((NEXT:BBName _):BB))
523
+ => #executeStatement(DEST_LOCAL = #unwrap(ARG)) ~> #executeBasicBlock(FN_KEY, BBName2Int(NEXT)) ...
524
+ </k>
525
+ <callStack> ListItem(FN_KEY) ... </callStack> [priority(48)]
518
526
```
519
527
520
528
The following rule executes exists to copy a value of one local to another local, the locals may belong to different functions.
0 commit comments