
module ArrivalDetector {
    input arrival : boolean;
    output event_arrival : boolean;

    init {
        event_arrival = false;
    }

    next {
        event_arrival = arrival;
    }
}

module DepartureDetector {
    input departure : boolean;
    output event_departure : boolean;

    init {
        event_departure = false;
    }

    next {
        event_departure = departure;
    }
}

module Counter {
    input event_arrival : boolean;
    input event_departure : boolean;
    output display_update : int;

    var counter : int;

    init {
        counter = 0;
        display_update = counter;
    }

    next {
        if (event_arrival) {
            counter = counter + 1;
            display_update = counter;
        } else if (event_departure) {
            counter = counter - 1;
            display_update = counter;
        } else {
            display_update = counter;
        }
    }
}

module main {
    instance ad : ArrivalDetector(arrival, event_arrival);
    instance dd : DepartureDetector(departure, event_departure);
    instance c : Counter(event_arrival, event_departure, display_update);

    input arrival : boolean;
    input departure : boolean;

    init {
        arrival = false;
        departure = false;
    }

    next {
        // Simulate arrival and departure events
        if (some_condition) {
            arrival = true;
        } else {
            arrival = false;
        }

        if (some_other_condition) {
            departure = true;
        } else {
            departure = false;
        }

        // Propagate events to modules
        next(ad);
        next(dd);
        next(c);
    }
}
