
\documentclass[11pt]{article}
%\usepackage{mydraft}

\usepackage{TRmydraft}
\usepackage{wmff}
\usepackage{graphicx}
%\usepackage{graphalgb}

\pagestyle{myheadings}
\markright{Using the OOSimL/Java Compiler\hfill}

\begin{document}

\reptitle{{\bf Using The OOSimL/Java}}
\author{Jos\'e M. Garrido}

\date{December, 2016}

\subtitle{{\bf With a  Terminal Window}}
\subsubtitle{On Linux Operating System}
%\subsubtitle{Technical Report TR-CSIS-OOPsimL (Part 2)}

\authoraffil{Department of Computer Science} 
 
%
%\halftitlepage
%
\titlepage

\mdraft
%\maketitle
%\newpage
%\tableofcontents
%\newpage


\section{The OOSimL Compiler}

 This document briefly describes the features and explains how to use the OOSimL compiler that generates Java code. The compiler that generates C++ code is explained in a separate document. 

The OOSimL to Java compilation is a two-phase process. The first phase involves a translation into an equivalent Java source program, the second phase involves the corresponding Java translation to Java byte-code. 

\begin{figure}[h]
%\vspace{.1in}
%\centereps{3.5in}{0.463in}{oostran.png}
\centering
\includegraphics[width=3.25in]{figs/oostran.png}
\caption{First phase of compilation of an OOSimL program}
\label{fig:oostran}
%\vspace{0.1in}
\end{figure}

The first phase of the compilation is illustrated in Figure~\ref{fig:oostran}. The second phase of compilation involves compiling the corresponding Java program and use of the Java compiler. Figure~\ref{fig:javac} shows what is involved in compilation of a source program in Java. The Java compiler checks for syntax errors in the source program and then translates it into a program in bytecode, which is the program in an intermediate form. 

\begin{figure}[h]
%\vspace{.1in}
\centering
\includegraphics[width=3.25in]{figs/javac.png}
\caption{Compiling a Java source program}
\label{fig:javac}
%\vspace{0.1in}
\end{figure}

Note that the Java bytecode is not dependent on any particular platform or computer system. This makes the bytecode very portable from one machine to another.
 
Figure~\ref{fig:jvm} shows how to execute a program in bytecode. The Java virtual machine (JVM) carries out the interpretation of the program in bytecode.

\vspace{.1in}
\begin{figure}[h]
\centering
\includegraphics[width=3.25in]{figs/jvm.png}
\caption{Executing a Java program}
\label{fig:jvm}
\end{figure}
\vspace{0.1in}

The OOSimL software, a sample model, and documentation are archived in the file {\tt oosiml.tar.gz}, available from the OOSimL Web page:

%\begin{quote}
{\tt \small
\begin{verbatim}
  http://ksuweb.kennesaw.edu/~jgarrido/oosiml.html
\end{verbatim}
}
%\end{quote}

%\section{Configuring the OOSimL Compiler}



Currently, there are two general procedures used for developing programs and simulation models with the OOSimL compiler. These procedures are:

\begin{enumerate}
\item
Developing the simulation model with the Eclipse integrated environment.
 
\item
Working in a Terminal window.
\end{enumerate}

The next sections introduce and explain how to configure and use the OOSimL compiler with the command window. 
The OOSimL software consists of two main components: the compiler/translator executable program {\tt oosiml.out}, and the run-time library, {\tt oosimlib.jar}. The compiler has the following functions:

\begin{enumerate}

\item
Syntax checking of a source program in OOSimL; a list of errors is displayed and written to an error file with the same name as the source program

\item
Generation of an equivalent program in Java

\end{enumerate}

\section{Installing the OOSimL Software and Models}

The first general step is to create a folder and then to store the relevant files in the folder. As mentioned previously, the two essential files are: the OOSimL compiler, which is an executable program called {\tt oosiml.out}, and the runtime library, {\tt oosimlib.jar}. 

\begin{enumerate}
\item
Start and open a terminal window. 
\item
Create a new directory, for example {\tt oosimldir}.  Now change to that new directory.

{\tt \small
\begin{verbatim}
  mkdir oosimldir
  cd oosimldir
\end{verbatim}
}

\item
Download the archive {\tt oosiml.tar.gz} from the web page. Store the archive in the current directory and extract the files using the following command:

{\tt \small
\begin{verbatim}
  tar -xzvf oosiml.tar.gz
\end{verbatim}
}

\item
Type the following command to uncompress the simulation model in the JAR file  {\tt carwash.jar}. This stores all the files of the Carwash model in a subdirectory {\tt carwash}.

{\tt \small
\begin{verbatim}
  jar xf carwash.jar
\end{verbatim}
}

\item
To get a list of the files in the current directory, type {\tt ls} and then press Enter.  

\end{enumerate}

\section{Using a Terminal Window}

Any text editor can be used to write and edit a new program in OOSimL or to modify an existing OOSimL program. A good editor for developing OOSimL and Java programs {\tt gedit}. For editing and using the OOSimL compiler in a command window, complete the following steps:



\begin{enumerate}


\item
Change the directory to the one where the files of the simulation model is stored. Use the {\tt cd} command. For example, {\tt cd carwash}.

\item 
Start the editor.
\item
Type and edit the source program (e.g., {\tt Carwash.osl}) with the  editor. Note that the source files have the {\tt .osl} extension. 

\item
Invoke the OOSimL compiler to check syntax and generate a Java program. 

{\tt \small
\begin{verbatim}
  ~/oosimldir/oosiml.out Carwash.osl
\end{verbatim}
}

After a few seconds, you will see a message on the screen. In this case, File {\tt Carwash.osl}, {\tt no syntax errors}, {\tt lines processed: 49}. 

\item
In the current directory, (or folder) two new files appear with the same name as your original source file. One of the files stores the syntax errors found. This file has the same name as the source program but with an {\tt err} extension; for example, {\tt Carwash.err}.

\item 
The second file contains the generated Java program; the file has the same name but with the {\tt java} extension. For example, if your source program is {\tt Carwash.osl}, then the Java program created is {\tt Carwash.java}.

\item 
Use the Java compiler to compile the Java program (e.g. {\tt Carwash.java}) generated by the OOSimL compiler.
Compiling simulation programs, involve setting the {\em classpath\/} for the compiler to find the appropriate libraries, {\tt oosimlib.jar}. Assume that these libraries are located in the {\tt c:$\backslash$oosimldirl} directory and that the current directory contains the Java classes for the simulation model, the following command compiles all the Java files in the current directory.

{\tt \small
\begin{verbatim}
javac -classpath ~/oosimldirl/oosimlib.jar *.java 
\end{verbatim}
}


\item
Use the Java Virtual Nachine (JVM) to run the compiled program. When starting execution, enter the input data to the program, if needed.
The following command will start  of the simulation model, assuming that the main class is named {\em Carwash}.

{\tt \small
\begin{verbatim}
java -classpath ~/oosimldir/oosimlib.jar;. Carwash
\end{verbatim}
}

Note that running a simulation model creates two new files in the current directory, these are: {\tt carwtrace.yxy} and {\tt Carwstat.txt}. The names of these files can be changed by edting the source file with the main class.



\end{enumerate}


\end{document}
