k-legacy
k-legacy copied to clipboard
Rule gets applied once, but not again
I have a configuration like this:
<T>
...
<nodes>
<node> <id> 0 </id> <k> @nextPacket ... </k> <in> packet </in> ... </node>
<node> <id> 1 </id> <k> @nextPacket ... </k> <in> . </in> ... </node>
...
</nodes>
</T>
And I have a rule like this
rule <k> @nextPacket => @dostuff(packet) ... </k>
<in> packet => . </in>
The rule seems to work for node 0, the execution proceeds to a configuration like this
<T>
...
<nodes>
<node> <id> 0 </id> <k> @nextPacket ... </k> <in> . </in> ... </node>
<node> <id> 1 </id> <k> @nextPacket ... </k> <in> packet </in> ... </node>
...
</nodes>
</T>
(note that packet is now at node 1)
But it seems the execution stops here and does not continue.
@cos @daejunpark
I tried to create a simplified version of the problem and here it is:
module TEST
configuration
<T>
<xx> @init($PGM:Program) </xx>
<nodes>
<node multiplicity="*">
<id> .K </id>
<k> .K </k>
<bin> .List </bin>
<bout> .List </bout>
</node>
</nodes>
</T>
syntax Program ::= "www"
syntax KItem ::= "$p" "(" List "," Int ")"
syntax KItem ::= "@init" "(" Program ")" | "@nextPacket"
syntax KItem ::= "@val" "(" Int ")"
rule <xx> @init ( _:Program ) => . </xx>
<nodes>
(.Bag =>
<node>
<id> 0 </id>
<k> @nextPacket </k>
<bin> ListItem($p(ListItem(@val(100)),1)) </bin>
...
</node>)
(.Bag =>
<node>
<id> 1 </id>
<k> @nextPacket </k>
...
</node>)
...
</nodes>
rule <k> @nextPacket => .K </k>
<bin> (ListItem($p(P:List,Port:Int)) => .) _:List </bin>
<bout> _:List (.List => ListItem($p(P,Port +Int 1))) </bout>
rule <node> <bout> (ListItem($p(P:List,Port:Int)) => .) _:List </bout> ... </node>
<node> <bin> .List => ListItem($p(P,Port)) </bin> ... </node>
endmodule
And here are the steps that are taken:
KDebug> peek
initTCell ( .Map $STDIN |-> "" $IO |-> "off" $PGM |-> www )
KDebug> step
1 Step(s) Taken.
KDebug> peek
<T> <xx> . </xx> <nodes> <node> <id> 0 </id> <k> @nextPacket </k> <bin> ListItem ( $p ( ListItem ( @val ( 100 ) ) , 1 ) ) </bin> <bout> .List </bout> </node> <node> <id> 1 </id> <k> @nextPacket </k> <bin> .List </bin> <bout> .List </bout> </node> </nodes> </T>
KDebug> step
1 Step(s) Taken.
KDebug> peek
<T> <xx> . </xx> <nodes> <node> <id> 0 </id> <k> . </k> <bin> . </bin> <bout> ListItem ( $p ( ListItem ( @val ( 100 ) ) , 2 ) ) </bout> </node> <node> <id> 1 </id> <k> @nextPacket </k> <bin> .List </bin> <bout> .List </bout> </node> </nodes> </T>
KDebug> step
1 Step(s) Taken.
KDebug> peek
<T> <xx> . </xx> <nodes> <node> <id> 0 </id> <k> . </k> <bin> . </bin> <bout> . </bout> </node> <node> <id> 1 </id> <k> @nextPacket </k> <bin> ListItem ( $p ( ListItem ( @val ( 100 ) ) , 2 ) ) </bin> <bout> .List </bout> </node> </nodes> </T>
KDebug> step
Attempted 1 step(s). Took 0 steps(s).
Final State Reached
The same rule:
rule <k> @nextPacket => .K </k>
<bin> (ListItem($p(P:List,Port:Int)) => .) _:List </bin>
<bout> _:List (.List => ListItem($p(P,Port +Int 1))) </bout>
Does not get applied the second time
Actually the simplified example was fixed by changing .
to .List
. But doing so did not solve the problem in the actual program.
The actual rules are like this:
rule <k> @nextPacket => @parse&ingress ~> @egress ~> @txenPacket ~> @nextPacket ... </k>
<buffer> <bin> (ListItem($packet(P:List, Port:Int)) => .List) _:List </bin> ... </buffer>
rule <topology> ... $node_port(SN:Int,SP:Int) |-> $node_port(DN:Int,DP:Int) </topology>
<node> <nodeId> SN </nodeId> <bout> (ListItem($packet(P:List,SP)) => .List) _:List </bout> ... </node>
<node> <nodeId> DN </nodeId> <k> @nextPacket ... </k> <bin> .List => ListItem($packet(P,DP)) </bin> ... </node>
The problem somehow got mysteriously fixed by itself after changing some irrelevant parts of the semantics!
I remember having a similar issue some time ago. Unfortunately is not something in the front end, and I don't know where to look in the backend.