objectionary / speco

Object Specialization for EO Programs
MIT License
6 stars 4 forks source link
eolang java oop specialization
logo

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

mvn PDD status codecov Maven Central Hits-of-Code Lines of code License

Specialization of objects in EO programs.

Speco is a tool that is aimed to be launched on the EO program converted to a collection of .xmir files, which has undergone modifications performed by AOI tool.

Consider the following EO program:

[] > cat
  [] > talk
    QQ.io.stdout > @
      "Meow!"

[] > dog
  [] > talk
    QQ.io.stdout > @
      "Woof!"
  [] > eat
    QQ.io.stdout > @
      "I am eating"

[x] > pet1
  x.talk > @

[x] > pet2
  seq > @
    x.talk
    x.eat

The following block in the .xmir file of this program will be generated after AOI launch:

<aoi>
    <obj fqn="pet1.x">
       <inferred>
          <obj fqn="cat"/>
          <obj fqn="dog"/>
       </inferred>
    </obj>
    <obj fqn="pet2.x">
       <inferred>
          <obj fqn="dog"/>
       </inferred>
    </obj>
</aoi>

As we can see, object x from pet1 is only used with its talk attribute, therefore it can either be an instance of cat or dog. Whereas x located pet2 is used with both talk and eat, which lets us determine that x can only be an instance of dog.

Right now object pet1 has only one implementation, which looks like below in xmir format. It does not give any hints on what object x may be in this context.

<o abstract="" line="20" name="pet1" pos="0">
   <o line="20" name="x" pos="1"/>
   <o base="x" line="21" pos="2"/>
   <o base=".talk" line="21" name="@" pos="3"/>
</o>

Speco makes it obvious what x is in the provided context. For example, it will turn object pet1 into these two declarations of objects pet1_spec_x_cat and pet1_spec_x_dog, which are specific for cat and dog correspondingly.

<o abstract="" line="20" name="pet1_spec_x_cat" pos="0" spec="pet1">
   <o line="20" name="x" pos="1"/>
   <o base="x" line="21" pos="2"/>
   <o base=".talk" line="21" name="@" pos="3"/>
</o>
<o abstract="" line="20" name="pet1_spec_x_dog" pos="0" spec="pet1">
   <o line="20" name="x" pos="1"/>
   <o base="x" line="21" pos="2"/>
   <o base=".talk" line="21" name="@" pos="3"/>
</o>

It will generate a collection of modified .xmir files as an output.

Usage

Build the app locally:

$ make build

and run:

$ java -jar speco.jar --help

To run a transformation:

$ java -jar speco.jar --source=<input> --target=<output>

or use make command:

$ make trans

How it works

The tool works according to an algorithm consisting of 7 transformation rules.

Rule 1:

Rule 2:

Rule 3:

Rule 4:

Rule 5:

Rule 6:

Rule 7:

How to Contribute

Fork repository, make changes, send us a pull request. We will review your changes and apply them to the master branch shortly, provided they don't violate our quality standards. To avoid frustration, before sending us your pull request please run full Maven build:

$ mvn clean install -Pqulice

You will need Maven 3.3+ and Java 8+.