| # The Byte Code Composer Tools (Not Yet Finished)

We want to be able to distribute binary versions of layers. Currently, we distribute and compose source code only. The byte code composer tools are a preliminary and experimental first step toward our ultimate goal of distributing binary layers. The idea is to translate each jak file into a stylized Java file -- meaning that there are coding and naming conventions in the Java file that will allow us to express (and hence recognize) refines constructs. One tool, bcjak2java does this translation. Its command line input is a single Jak file and it produces the stylized Java file as output.

The basic idea in stylizing is to emulate mixin layers. For stylized Java code to be compiled, we need to create a stub for every class and interface that is the union of all possible methods and members that can appear within it. The tool bcstubgenerator performs this task. To translate all Jak files in a directory into Java files, the bcj2j script is used. After creating the stub layer, the stylized java classes can be compiled. A script bccomposer composes bytecode layers.

- bcmixin tool

## bcmixin tool

The bcmixin tool is a byte code composition tool for java class files. Its composition rules are similar with the mixin tool in AHEAD. The stylized Java code for the bcmixin tool are:

1. the base classes in the layer are same as the regular java code.
2. the refines classes in the layer are stylized: class A extends stub.A. Here, the "extends stub.A" is used to make the refinement classes get the references from its parent classes through the stub layer. Therefore, the refinement class can call its parent class by the standard super call in Java. And also the refinement classes can be compiled with the stub directory.

How to build and install it:

1. build

using the build file bctools.xml to build the tools:

>ant -f bctools.xml bcmixin -build the bcmxin tool

>ant â€“f bctools.xml bcstubgenerator -build the bcstubgenerator tool

>ant â€“f bctools.xml bctostub -build the bctostub tool

>ant â€“f bctools.xml -build all

2. install it

After build it, put the jar files in the build/lib directory and bcel.jar in the lib directory in your classpath

Also put the AHEAD tools: mmatrix.jar, bcjak2java.jar, mmatrix.jar in your classpath.

You also need to put the bin directory in your path so you can run the script files.

How to run it:

In the standalone/bcbinScripts directory, you will find the following Bash script files:

1. bcj2j: a script to translate all jak files to java files in the given model (directory) recursively. It calls the tool bcjak2java in AHEAD tool suite to do the translation.
2. bcjrename: a script to rename all the classes in the given model. It calls the tool jrename in AHEAD tool suite to do the renaming
3. bccompiler: a script to compile the given model. It will run the stub generator tool first, and then rename the java files in each layer, and then compile each layer
4. bccomposer: a script to run the bccomposer driver to compose the given model by the given equation file and make a jar file from the composed class files.

1. Translate the jak files into java files:

If your model is based on jak files, to run the bcmixin tools, you should transfer the jak files to java file first. The script file bcj2j in the bin directory can help you to translate the jak files in your model into java files easily:

>bcj2j <model name>

Here, you should run the bcj2j in the directory which includes your model.

After your model is translated into pure java files, then you can use bcmixin tools to compile and compose your model.

2. Run bcmixin tools

You can run bcmixin tools in two modes: by hand or by a script file.

1. By hand:

To compile your model:

1. run bcstubgenerator.Main [modelname] to get stub&refine directory

2. compile stub&refine using the standard java compiler

3. run bctostub.Main [stub directory] on stub directory

4. run jrename to rename all the classes in current model

5. on linux, compile each layer with: javac â€“classpath .:refine:stub <layer_name>/*\$\$.java
on windows, compile each layer with javac -classpath .\;refine\;stub <layer_name>/*\$\$.java

To compose an executable application from your model:

1. run java bcmixin.Main [modelname] [equation file]

2. make an executable jar file

2. By a script file:

1. run bcj2j <model>

2. run the script file bccompiler [modelname] to compile your model.

3. run the script file bccomposer [modelname] [equation file] to get an executable jar file from your model by the given equation file.

Example:

get GPL directory

run in bash:

rm -r gpl\$\$

bcj2j gpl

bcompiler gpl

bccomposer gpl\$\$ dgraph