A Hello World Programm in Sappeur

By Frank Gerlach(frankgerlach.tai@gmx.de)

In the following, I will describe how to create your very first Sappeur program. Linux/POSIX environment will be used.

1. Set Up the Project Directory

$ mkdir helloworld
$ mkdir helloworld/output

2. Copy System Code

In order to use existing system libraries, you should copy them from an existing project. In this case, we use the gauss web server as the existing project.
$ cd helloworld
$ cp ../gauss/String.a* .
$ cp ../gauss/System.a* .
$ cp ../gauss/callCompiler.sh  .

3. Set Up compileorder File

In this step, you define the compilation order of the sappeur declaration files (*.ad). The order must be such that dependencies have been "seen" by the compiler before they are used. Similar to C++, forward declarations can be used for pointer types.
$  vi compileorder
Content:
  String.ad,
  System.ad,
  AppMain.ad

4. Write the main() Method

In this step you will declare the class which hosts the Main::main() method, the entry point to your program.
$ vi AppMain.ad

Of course you can use any editor of your choice, including nano, emacs, notepad++ etc. Please do NOT use notepad. Encoding must be ASCII, no special characters such as umlauts.

Content:
class Main
{
methods:
   int main();

};
Now, implement the main method in a sappeur implementation (*.ai) file.
$ vi AppMain.ai
Content:
int Main::main()
{
   var PrintfClass pfc;
   pfc.fstr("Hello World !").pr();

   return 1;
}
Explanation: You create an object of type PrintfClass. Then you call the format string method and finally call the pr() method to actually print to STDOUT.

7. Compile to C++

$ ./callCompiler.sh
Note that it might be necessary to adapt this shell script to your Sappeur compiler installation.

8. Compile to binary

In this step the Sappeur compiler output (Memory Safe C++ classes) is compiled into a binary executable.
$ cd output
$ make -f Makefile -j 4 all

9. Run Program

$ ./sprprog.exe
Note that the executable name is a historic leftover from the windows world, where the compiler was first hosted. Despite the *.exe extension, this is a normal Linux/POSIX program. In most cases the program can be renamed easily. Also, you can change(and rename, to avoid overwrite) the Makefile to create a program name of your choice.

10. Performance

One of the key capabilities of Sappeur programs is very good efficiency in runtime and memory consumed. A hello world program should execute in milliseconds.
pi@rpigross:~/helloworld/output $ time ./sprprog.exe
Hello World !

real    0m0,013s
user    0m0,001s
sys     0m0,012s

11. Download Helloworld Package

The project above can be downloaded from here

Formelles, Kontakt

Impressum

Datenschutz-Erklärung