X-Git-Url: http://nitlanguage.org diff --git a/tests/bench_netsim.nit b/tests/bench_netsim.nit index 6a9ade7..f784635 100644 --- a/tests/bench_netsim.nit +++ b/tests/bench_netsim.nit @@ -19,11 +19,11 @@ class Node do return _name end - var _name: String = "noname" + var name: String = "noname" end class WakeUpNode -special Node + super Node fun wake_up is abstract # Wake up the node fun wake_up_in(d: Int) @@ -31,17 +31,16 @@ special Node do _scheduler.add_event(self, d) end - var _scheduler: Scheduler + var scheduler: Scheduler is noinit end class NodeSource -special Node - var _nexts: nullable ArraySet[NodeSink] = null + super Node + var nexts: nullable ArraySet[NodeSink] = null fun attach(n: NodeSink) # Add the sink `n' the the connected nodes # Do nothing if `n' is already connected do - assert n != null # Create the collection if needed if _nexts == null then _nexts = new ArraySet[NodeSink] @@ -53,7 +52,6 @@ special Node # Remove the sink `n' from the connected nodes # Do nothing if `n' is not connected do - assert n != null _nexts.remove(n) end @@ -70,7 +68,7 @@ special Node end class NodeSink -special Node + super Node fun recieve(n: NodeSource) is abstract # the `n' has emeted a signal end @@ -78,8 +76,8 @@ end # class Scheduler - var _time_list: Array[Couple[Int, WakeUpNode]] = new Array[Couple[Int, WakeUpNode]] - var _time: Int = 0 # What time is it ? + var time_list: Array[Couple[Int, WakeUpNode]] = new Array[Couple[Int, WakeUpNode]] + var time: Int = 0 # What time is it ? fun add_event(n: WakeUpNode, d: Int) # The node `n' whant to be weaked up in `d' time units do @@ -109,7 +107,7 @@ class Scheduler fun run_for(time_limit: Int) do - while true do + loop var node = next_event if _time > time_limit then print("Time limit.") @@ -131,14 +129,14 @@ end # class BeepSource -special NodeSource -special WakeUpNode + super NodeSource + super WakeUpNode redef fun wake_up do send wake_up_in(_delay) end - var _delay: Int + var delay: Int fun start do wake_up_in(_delay) @@ -153,16 +151,16 @@ special WakeUpNode end class CountSink -special NodeSink - readable var _count: Int = 0 + super NodeSink + var count: Int = 0 redef fun recieve(n: NodeSource) do - _count = _count + 1 + count = count + 1 end end class SimpleCountSink -special CountSink + super CountSink init(name: String) do @@ -171,9 +169,9 @@ special CountSink end class NodeAlternate -special NodeSink -special NodeSource - var _last: nullable NodeSource + super NodeSink + super NodeSource + var last: nullable NodeSource redef fun recieve(n: NodeSource) do if n != _last then @@ -189,17 +187,17 @@ special NodeSource end class NodeEat -special CountSink -special NodeSource - var _limit: Int + super CountSink + super NodeSource + var limit: Int redef fun recieve(n: NodeSource) do - var c = _count + 1 + var c = count + 1 if c >= _limit then - _count = 0 + count = 0 send else - _count = c + count = c end end @@ -211,10 +209,10 @@ special NodeSource end class NodeDelay -special NodeSource -special NodeSink -special WakeUpNode - var _delay: Int + super NodeSource + super NodeSink + super WakeUpNode + var delay: Int redef fun recieve(n: NodeSource) do wake_up_in(_delay)