require events.4th require eventhandlers.4th variable continue : (call) ( eventdata-u eventid-u eventhandler-addr -- ) eventhandler.xt @ execute ; : (handles?) ( eventid-u eventhandler-addr -- flag ) tuck eventhandler.eventid @ = swap eventhandler.xt @ 0<> and ; : eventloop.has-events? ( -- flag ) events.has-item? ; : eventloop.stop-propagation ( -- ) false continue ! ; : eventloop.dispatch ( -- ) true continue ! events.dequeue MAX_EVENTHANDLERS 0 DO continue @ invert IF 2drop UNLOOP EXIT THEN 2dup I (translate) 2dup (handles?) IF (call) ELSE drop 2drop THEN LOOP 2drop ; : eventloop.run ( -- ) BEGIN eventloop.has-events? IF eventloop.dispatch ELSE EXIT THEN AGAIN ; : eventloop.idlerun ( -- ) BEGIN eventloop.has-events? IF eventloop.dispatch ELSE 0 0 events.enqueue eventloop.dispatch THEN AGAIN ;