<!DOCTYPE article PUBLIC "-//NLM//DTD JATS (Z39.96) Journal Archiving and Interchange DTD v1.0 20120330//EN" "JATS-archivearticle1.dtd">
<article xmlns:xlink="http://www.w3.org/1999/xlink">
  <front>
    <journal-meta />
    <article-meta>
      <title-group>
        <article-title>Create and Play your Pac-Man Game with the GEMOC Studio</article-title>
      </title-group>
      <contrib-group>
        <contrib contrib-type="author">
          <string-name>(Tool Demonstration)</string-name>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Dorian Leroy</string-name>
          <email>dorian.leroy@cis.jku.at</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Erwan Boussey</string-name>
          <email>erwan.bousse@tuwien.ac.at</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Manuel Wimmerz</string-name>
          <email>wimmer@big.tuwien.ac.at</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Benoit Combemalex</string-name>
          <email>benoit.combemale@irisa.fr</email>
          <xref ref-type="aff" rid="aff0">0</xref>
        </contrib>
        <contrib contrib-type="author">
          <string-name>Wieland Schwinger</string-name>
          <email>wieland.schwinger@jku.ac.at</email>
          <xref ref-type="aff" rid="aff0">0</xref>
          <xref ref-type="aff" rid="aff1">1</xref>
        </contrib>
        <aff id="aff0">
          <label>0</label>
          <institution>@EventHandler up(Pacman: pacman)</institution>
        </aff>
        <aff id="aff1">
          <label>1</label>
          <institution>JKU Linz</institution>
          ,
          <country country="AT">Austria</country>
        </aff>
      </contrib-group>
      <abstract>
        <p>-Executable Domain-Specific Languages (DSLs) are used for defining the behaviors of systems. The operational semantics of such DSLs may define how conforming models react to stimuli from their environment. This commonly requires adapting the semantics to define both the possible domainlevel stimuli, and their handling during the execution. However, manually adapting the semantics for such cross-cutting concern is a complex and error-prone task. In this paper, we present an approach and a tool addressing this problem by augmenting the operational semantics for handling stimuli, and by automatically generating a complete behavioral language interface from this augmentation. At runtime, this interface can receive stimuli sent to models, and can safely handle them by interrupting the execution flow. This tool has been developed for the GEMOC Studio, a language and modeling workbench for executable DSLs. We demonstrate how it can be used to implement a Pac-Man DSL enabling the creation and execution of Pac-Man games. Index Terms-Model Execution; Reactive DSLs; Code Generation</p>
      </abstract>
    </article-meta>
  </front>
  <body>
    <sec id="sec-1">
      <title>-</title>
      <p>I. INTRODUCTION</p>
      <p>
        A large number of Domain-Specific Languages (DSLs)
geared toward the description of the behavior of systems
(e.g., [
        <xref ref-type="bibr" rid="ref1">1</xref>
        ], [
        <xref ref-type="bibr" rid="ref2">2</xref>
        ], [
        <xref ref-type="bibr" rid="ref3">3</xref>
        ], [
        <xref ref-type="bibr" rid="ref4">4</xref>
        ], [
        <xref ref-type="bibr" rid="ref5">5</xref>
        ]). Enabling the execution of their
conforming models allows to make the most out of those
models. This requires the definition of the execution semantics
of these languages, including how conforming models react to
stimuli from their environment [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]. This includes the definition
both of possible domain-specific events—i.e., the different types
of stimuli in the considered domain—and of how occurrences
of said events are to be handled.
      </p>
      <p>
        But incorporating events handling logic within operational
semantics is a difficult task, as it impacts both the content
(e.g., adding event-processing code in existing execution rules)
and the scheduling of execution rules (e.g., defining instants in
the execution when stimuli should be handled). In addition, at
runtime, it is necessary to provide an interface to allow external
actors (e.g., a simulator, a test engine, other models, etc.) to
send event occurrences to models being executed. Depending
on how a semantics is structured, this may require a mechanism
to temporarily interrupt the execution of the model (similarly
to interruptable models in the DEVS formalism [
        <xref ref-type="bibr" rid="ref6">6</xref>
        ]), in order to
react to event occurrences by triggering their handling. Overall,
manually defining such interface and its integration with the
semantics can be a tedious and error-prone task, which must
be repeated for each executable DSL.
      </p>
      <p>
        The demonstrated tool aims to solve this problem. It is
developed as an extension to the GEMOC Studio [
        <xref ref-type="bibr" rid="ref7">7</xref>
        ], an
Eclipsebased language and modeling workbench for executable DSLs.
It provides a non-intrusive and modular way to define both
the possible domain-specific events and their handling logic
within the operational semantics of a DSL. It then generates
an interface to safely send event occurrences to a model being
executed, i.e., only when the model is in a consistent state. An
extension to the execution environment has been developed
to use this interface. The use of this tool is illustrated with a
Pac-Man DSL ([
        <xref ref-type="bibr" rid="ref8">8</xref>
        ], [
        <xref ref-type="bibr" rid="ref9">9</xref>
        ]) allowing to define customized versions
of the world-famous Pac-Man video game, which can then be
played. The tooling as well as the example presented in this
paper are available on Github12.
      </p>
      <p>The remainder of this paper is structured as follows. In
Section II, we provide an overview of the architecture of the
tool. Section III details the Pac-Man use case. Finally, future
research directions are given in Section IV.</p>
    </sec>
    <sec id="sec-2">
      <title>II. ARCHITECTURE In this section we present the architecture of the tool, which is developed as a reactive extension to the GEMOC Studio and is written in Java and Xtend.</title>
      <sec id="sec-2-1">
        <title>A. Executable DSLs and Event Handlers Annotation</title>
        <p>
          The tool presented in this paper supports DSLs whose
abstract syntax is provided as a metamodel and whose execution
semantics is provided as an operational semantics. The
considered operational semantics can be decomposed in i) a data
structure representing the model state and ii) a set of execution
rules. The model state is defined in an execution metamodel
extending the abstract syntax metamodel. Before the execution,
models are initialized through a transformation from the
abstract syntax to the execution metamodel. Model execution
is performed by an endogenous, in-place transformation on
this model state, using the set of execution rules constituting
the operational semantics of the DSL. The approach relies on
providing an annotation mechanism to tag execution rules
as event handlers. This allows the identification of both
events and their corresponding handler. In the GEMOC Studio,
Ecore [
          <xref ref-type="bibr" rid="ref10">10</xref>
          ] is used as a metamodeling language to define
        </p>
      </sec>
    </sec>
    <sec id="sec-3">
      <title>1https://github.com/eclipse/gemoc-studio 2https://github.com/tetrabox/pacman-example.git</title>
      <sec id="sec-3-1">
        <title>PacManInterpreter</title>
        <p>gameLoop()</p>
      </sec>
      <sec id="sec-3-2">
        <title>PacMan</title>
      </sec>
      <sec id="sec-3-3">
        <title>EventInterpreter</title>
      </sec>
      <sec id="sec-3-4">
        <title>EventManager ExecutionEngine</title>
        <p>loop</p>
        <p>[while !gameOver()]
update(dt)
loop
opt
[for evt in eventQueue]
[canProcess(evt)]
executeRule
(evt.name,evt.params)
notify()
dispatchEvent(evt)
processEvents()</p>
        <sec id="sec-3-4-1">
          <title>C. Behavioral Language Interface</title>
          <p>
            the abstract syntax and the execution metamodel of DSLs. event handlers. The outputs of the generator are an Ecore
One goal of the underlying approach is to support multiple event metamodel and a Java class providing the dispatchEvent
metaprogramming languages to define the operational semantics service. As shown on Figure 1, this service retrieves the
of DSLs. We support the Kermeta language [
            <xref ref-type="bibr" rid="ref11">11</xref>
            ] and the xMOF parameters stored within the provided event model and calls
language [
            <xref ref-type="bibr" rid="ref12">12</xref>
            ]. For example, in Kermeta, an @Step annotation the corresponding execution rule with these parameters.
allows to tag methods as execution steps. This annotation has
been extended with the eventHandler boolean parameter. D. Event manager
This parameter fulfills the role required to tag execution rules
as event handlers.
          </p>
          <p>The event manager is the component linking the execution
engine to the generated event interpreter. It has a dynamic state
composed of the event queue which is a list of models
conB. Execution Engine forming to the domain-specific event metamodel (i.e.,
domain</p>
          <p>Within the GEMOC Studio, model execution is orchestrated specific stimuli) part of the behavioral language interface. The
by a component called the execution engine. Among other event manager provides the queueEvent service, which is used
things, this component is responsible for starting and stopping by external components to push event occurrences to the event
the execution. It is notified whenever the execution of a rule is queue. The processEvents service of the event interpreter is
about to begin or comes to an end. During such notifications, called by the execution engine each time the execution reaches
the engine guarantees that there is no ongoing atomic execution a new consistent state. It leads to the temporary interruption
step, which means that the executed model is in a consistent of the planned scheduling of execution rules in order to call
state. A component can be notified each time the model reaches the handling rule corresponding to each event occurrence in
such a state by registering as a listener to the execution engine. the event queue.</p>
          <p>Figure 1 shows how we leverage the notifications sent to the
execution engine to introduce event processing in the execution E. External Components
loop. The DSL (Pac-Man in Figure 1) interpreter executes the
rules of the operational semantics, and notifies the execution
engine when such a rule is executed (here the update rule). The
execution engine then delegates the handling of events to the
event manager, through the processEvent service. In turn, the
event manager iterates over its event queue and delegates for
each event the call of the corresponding execution rule to the
(generated) DSL event interpreter, through the dispatchEvent
service. These two components are detailed below.</p>
          <p>External components use the behavioral language interface
to interact with executed models, through the event manager.</p>
          <p>These components can listen to the execution by registering as
listeners to the execution engine. This way they are notified
when the execution starts, stops or reaches a consistent state,
which allows them to perform their intended task with reliable
data (i.e., the model’s dynamic state). These components also
have access to the services provided by the event interpreter
to check if particular stimuli can be processed in the current
execution state and to push stimuli to the queue. The
PacMan GUI (presented below) is such an external component,
refreshing the view when receiving notifications from the
engine, and forwarding the user’s inputs to the behavioral
interface of the Pac-Man DSL under the form of instances
from its event metamodel.</p>
          <p>The behavioral language interface of an executable DSL
allows external actors to send stimuli to executed models. It
can be decomposed as a domain-specific event metamodel and
a domain-specific event interpreter. These artifacts are both
generated from the annotated execution semantics of the DSL
by a generator implemented in Xtend taking the definition of the
DSL as input. This generator uses the annotation mechanism
provided by the approach to detect execution rules that are</p>
        </sec>
      </sec>
    </sec>
    <sec id="sec-4">
      <title>III. THE PAC-MAN EXAMPLE In this section we detail the Pac-Man DSL used in this tool demonstration.</title>
      <p>top
0..1
left
0..1
1
targetTile</p>
      <p>PassableTile
1</p>
      <p>Entity
+speed: int
Ghost
0..1
pellet</p>
      <p>SuperPellet Pellet</p>
      <p>Pacman
+pelletsEaten: int
+lives: int
+energized: boolean</p>
      <p>imports
activate(Ghost: ghost)
energize(Pacman: pacman)
Execution Rules
gameLoop(Board: board)
update(Board: board, int: deltaTime)
update(Entity: entity, int: deltaTime)
enterNextTile(Entity: entity)
modifySpeed(Entity: entity, int: speed)
@EventHandler @EventHandler
down(Pacman: pacman) left(Pacman: pacman)
@EventHandler
right(Pacman: pacman)
PacmanLeftEvent PacmanRightEvent and a Pacman has a number of initialLives.</p>
      <p>The domain targeted by this DSL is thus the definition of</p>
      <p>Pac-Man games, including the topology of the level (walls,
Fig. 3: Event metamodel generated for the Pacman DSL. ghost house and pellets), the number of ghosts, their behavior
and the starting positions and number of ghosts and pacmen.</p>
      <p>Operational Semantics: The real-time aspect of the</p>
      <p>Abstract Syntax: Figure 2 shows the abstract syntax execution semantics is obtained by using a classic game loop,
of the Pac-Man DSL as well as its execution metamodel. illustrated by Algorithm 1. Thread sleeps are used in order to
A Board is composed of AbstractTiles and Entities. An reach a target frame rate. The lower part of Figure 2 shows a
AbstractTile can be a PassableTile or a WallTile. PassableTiles subset of the execution rules of the Pac-Man DSL. Entities have
are further refined into Tiles and GhostHouseTiles. Tile an update rule used to check whether they reached a new
has an initialPellet attribute indicating which type of Tile according to their speed and the time they already spent
pellet the tile contains, if any. Lastly, an AbstractTile has in their current Tile. Entities also have an enterNextTile
two bidirectional references to its neighboring AbstractTiles: rule that takes care of the actual move and deals with the
right (the opposite being left), and bottom (the opposite consequences of this move (e.g., killing the Pacman if a Ghost
being top). An Entity can either be a Pacman or a Ghost and reaches the same Tile, eating the Pellet present on the Tile,
points to an initial PassableTile where it starts the game and etc.). The Pacman entity has a set of rules (up, down, left
where its position is reset when a Pacman loses a life or a and right) allowing it to change its direction. These rules are
Ghost is eaten. Not shown on the class diagram, a Ghost also annotated as an event handlers, which means that events can be
has a personality dictating its behavior during the game, sent to the model to change the direction of the pacman. The
event metamodel generated from these annotations is shown
in Figure 3.</p>
      <p>User Interface: The user interface has been specifically
developed for the Pac-Man DSL. It is implemented in JavaFX
and consists of two parts: an editor presenting useful tools to
build a Pac-Man game, and the actual game interface, which
receives events from the keyboards and delegates them to the
behavioral interface through the event manager. The game
interface is implemented as an execution engine listener and
updates its view when notified by the engine that a call to the
update execution rule of the Board has been completed.</p>
      <p>IV. FUTURE WORK</p>
      <p>The direct perspectives of this work include the three
following research topics. First, defining and the handling
of output events occurrences sent by an executed model to
its environment. This would be a first step toward enabling
co-simulation in a generic way. Second, the combined use of
behavioral language interfaces and temporal property languages
would allow to investigate activities such as testing or runtime
monitoring for executable DSLs. Third, the implementation
of the underlying approach with another meta-programming
language such as xMOF.</p>
      <p>Acknowledgements—This work has been funded by: the
Austrian Science Fund (FWF): P 28519-N31; the Austrian Agency
for International Mobility and Cooperation in Education, Science
and Research (OeAD) on behalf of the Federal Ministry for
Science, Research and Economy (BMWFW) under the grand
number FR 08/2017, by the French Ministries of Foreign Affairs
and International Development (MAEDI), and the French
Ministry of Education, Higher Education and Research (MENESR);
Austrian Federal Ministry of Science, Research and Economy
and the National Foundation for Research, Technology and
Development.</p>
    </sec>
  </body>
  <back>
    <ref-list>
      <ref id="ref1">
        <mixed-citation>
          [1]
          <string-name>
            <given-names>Object</given-names>
            <surname>Management</surname>
          </string-name>
          <string-name>
            <surname>Group</surname>
          </string-name>
          , “
          <article-title>Semantics of a Foundational Subset for Executable UML Models, V 1</article-title>
          .1,
          <string-name>
            <surname>” August</surname>
          </string-name>
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref2">
        <mixed-citation>
          [2]
          <string-name>
            <given-names>R.</given-names>
            <surname>Bendraou</surname>
          </string-name>
          ,
          <string-name>
            <given-names>B.</given-names>
            <surname>Combemale</surname>
          </string-name>
          ,
          <string-name>
            <given-names>X.</given-names>
            <surname>Crégut</surname>
          </string-name>
          , and
          <string-name>
            <given-names>M. P.</given-names>
            <surname>Gervais</surname>
          </string-name>
          , “
          <source>Definition of an executable SPEM 2</source>
          .0,” in
          <source>Proceedings of the 14th Asia-Pacific Software Engineering Conference (APSEC'07)</source>
          , pp.
          <fpage>390</fpage>
          -
          <lpage>397</lpage>
          , IEEE,
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref3">
        <mixed-citation>
          [3]
          <string-name>
            <given-names>T.</given-names>
            <surname>Fischer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Niere</surname>
          </string-name>
          ,
          <string-name>
            <given-names>L.</given-names>
            <surname>Torunski</surname>
          </string-name>
          ,
          <article-title>and</article-title>
          <string-name>
            <given-names>A.</given-names>
            <surname>Zündorf</surname>
          </string-name>
          , “
          <article-title>Story Diagrams: A New Graph Rewrite Language Based on the Unified Modeling Language</article-title>
          and Java,”
          <source>in Proceedings of the 6th International Workshop Theory and Application of Graph Transformations (TAGT'98)</source>
          , vol.
          <volume>1764</volume>
          , pp.
          <fpage>157</fpage>
          -
          <lpage>167</lpage>
          ,
          <year>2000</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref4">
        <mixed-citation>
          [4]
          <string-name>
            <given-names>D.</given-names>
            <surname>Harel</surname>
          </string-name>
          ,
          <string-name>
            <given-names>H.</given-names>
            <surname>Lachover</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Naamad</surname>
          </string-name>
          ,
          <string-name>
            <given-names>A.</given-names>
            <surname>Pnuelli</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Politi</surname>
          </string-name>
          ,
          <string-name>
            <given-names>R.</given-names>
            <surname>Sherman</surname>
          </string-name>
          ,
          <string-name>
            <surname>A.</surname>
          </string-name>
          <article-title>Shtull-trauring, and M. Trakhtenbrot, “STATEMATE: a working environment for the development of complex reactive systems</article-title>
          ,
          <source>” IEEE Transactions on software engineering</source>
          , vol.
          <volume>16</volume>
          , no.
          <issue>4</issue>
          , pp.
          <fpage>403</fpage>
          -
          <lpage>414</lpage>
          ,
          <year>1990</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref5">
        <mixed-citation>
          [5] OASIS, “
          <source>Web Services Business Process Execution Language Version</source>
          <volume>2</volume>
          .0,”
          <year>2007</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref6">
        <mixed-citation>
          [6]
          <string-name>
            <given-names>Y. V.</given-names>
            <surname>Tendeloo</surname>
          </string-name>
          and
          <string-name>
            <given-names>H.</given-names>
            <surname>Vangheluwe</surname>
          </string-name>
          , “
          <article-title>An introduction to classic DEVS,” CoRR</article-title>
          , vol.
          <source>abs/1701.07697</source>
          ,
          <year>2017</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref7">
        <mixed-citation>
          [7]
          <string-name>
            <given-names>E.</given-names>
            <surname>Bousse</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Degueule</surname>
          </string-name>
          ,
          <string-name>
            <given-names>D.</given-names>
            <surname>Vojtisek</surname>
          </string-name>
          ,
          <string-name>
            <given-names>T.</given-names>
            <surname>Mayerhofer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>J.</given-names>
            <surname>Deantoni</surname>
          </string-name>
          , and
          <string-name>
            <given-names>B.</given-names>
            <surname>Combemale</surname>
          </string-name>
          , “
          <article-title>Execution Framework of the GEMOC Studio (Tool Demo</article-title>
          ),
          <source>” in Proceedings of the 9th International Conference on Software Language Engineering (SLE'16)</source>
          ,
          <source>SLE</source>
          <year>2016</year>
          , p.
          <fpage>8</fpage>
          ,
          <year>2016</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref8">
        <mixed-citation>
          [8]
          <string-name>
            <given-names>R.</given-names>
            <surname>Heckel</surname>
          </string-name>
          , “
          <article-title>Graph transformation in a nutshell,”</article-title>
          <source>Electr. Notes Theor. Comput. Sci.</source>
          , vol.
          <volume>148</volume>
          , no.
          <issue>1</issue>
          , pp.
          <fpage>187</fpage>
          -
          <lpage>198</lpage>
          ,
          <year>2006</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref9">
        <mixed-citation>
          [9]
          <string-name>
            <given-names>E.</given-names>
            <surname>Syriani</surname>
          </string-name>
          and
          <string-name>
            <given-names>H.</given-names>
            <surname>Vangheluwe</surname>
          </string-name>
          , “
          <article-title>A modular timed graph transformation language for simulation-based design</article-title>
          ,
          <source>” Software and System Modeling</source>
          , vol.
          <volume>12</volume>
          , no.
          <issue>2</issue>
          , pp.
          <fpage>387</fpage>
          -
          <lpage>414</lpage>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref10">
        <mixed-citation>
          [10]
          <string-name>
            <given-names>D.</given-names>
            <surname>Steinberg</surname>
          </string-name>
          ,
          <string-name>
            <given-names>F.</given-names>
            <surname>Budinsky</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Paternostro</surname>
          </string-name>
          , and E. Merks,
          <source>EMF: Eclipse Modeling Framework, 2nd Edition</source>
          . Eclipse Series,
          <string-name>
            <surname>Addison-Wesley Professional</surname>
          </string-name>
          ,
          <year>2008</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref11">
        <mixed-citation>
          [11]
          <string-name>
            <surname>J.-M. Jézéquel</surname>
            ,
            <given-names>B.</given-names>
          </string-name>
          <string-name>
            <surname>Combemale</surname>
            ,
            <given-names>O.</given-names>
          </string-name>
          <string-name>
            <surname>Barais</surname>
            ,
            <given-names>M.</given-names>
          </string-name>
          <string-name>
            <surname>Monperrus</surname>
            , and
            <given-names>F.</given-names>
          </string-name>
          <string-name>
            <surname>Fouquet</surname>
          </string-name>
          , “
          <article-title>Mashup of metalanguages and its implementation in the Kermeta language workbench</article-title>
          ,
          <source>” Software and Systems Modeling</source>
          , vol.
          <volume>14</volume>
          , no.
          <issue>2</issue>
          ,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
      <ref id="ref12">
        <mixed-citation>
          [12]
          <string-name>
            <given-names>T.</given-names>
            <surname>Mayerhofer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>P.</given-names>
            <surname>Langer</surname>
          </string-name>
          ,
          <string-name>
            <given-names>M.</given-names>
            <surname>Wimmer</surname>
          </string-name>
          , and G. Kappel, “xMOF:
          <source>Executable DSMLs based on fUML,” in Proceedings of the 6th International Conference on Software Language Engineering (SLE'13)</source>
          , vol.
          <volume>8225</volume>
          of LNCS, Springer,
          <year>2013</year>
          .
        </mixed-citation>
      </ref>
    </ref-list>
  </back>
</article>