next up previous contents
Next: 3.2.2 C++ code synthesis Up: 3.2 HelloWorld Example Previous: 3.2 HelloWorld Example   Contents

3.2.1 Python code synthesis

To synthesize Python code from the model description, the user may execute the following command:

scc -lpython HelloWorld.des

HelloWorld.py will be generated. The following information is printed on the console:

-----
Time spent on compilation:         0.010 (sec)
File(s) generated:                 HelloWorld.py
-----
Command to compile the source:     (N/A)
Command to run the compiled code:  python HelloWorld.py
-----

This output tells the user that:

  1. SCC spent 0.010 second in generating the target code;

  2. the only file produced is HelloWorld.py;

  3. because target language Python is an interpreted language, it is not necessary to compile HelloWorld.py before execution;

  4. to execute the generated code, execute command:
    python HelloWorld.py
    

Now execute HelloWorld.py and enter some events in the console:

    Hello World Example
['A'] > e
['B'] > exit

When the execution is started, the model description is printed, and a prompt for input appears. The current state of the model is also displayed in the format of Python list. If event e is entered, the model correctly changes to state B. Command exit ends the execution and stops the program.

One may notice that the ``Hello World!'' message was not printed as it was printed in the simulation in SVM. This is because the output of the transition is ignored by SCC, which defaults not to generate any action code for the target code. To synthesize code with support for action code, the user should execute the following command instead:

scc -lpython --ext HelloWorld.des

Again, similar information about the code synthesis is printed on the console:

-----
Time spent on compilation:         0.015 (sec)
File(s) generated:                 HelloWorld.py
-----
Command to compile the source:     (N/A)
Command to run the compiled code:  python HelloWorld.py
-----

Now execute the target code again. The result should look like:

    Hello World Example
['A'] > e
Hello World!
['B'] > exit

This execution result is exactly the same as simulating the model in SVM:

svm -t HelloWorld.des


next up previous contents
Next: 3.2.2 C++ code synthesis Up: 3.2 HelloWorld Example Previous: 3.2 HelloWorld Example   Contents
Thomas Huining Feng
2004-04-05