wiki:Tutorial/Core/Compilation

Compilation

To compile a program into an executable, use the -make flag. This works for the following languages:

  • .ds Disciple Source Tetra
  • .dct Disciple Core Tetra
  • .dcl Disciple Core Lite
  • .dcs Disciple Core Salt

Here is a simple Tetra program to start with:
https://raw.githubusercontent.com/DDCSF/ddc/ddc-0.4.3/demo/Tetra/80-Rosetta/AlmostPrime/Main.ds

There are others in the Demo directory:
https://github.com/DDCSF/ddc/tree/ddc-0.4.3/demo/source/tetra

Compilation

To do a standard compile

$ ddc -make Main.ds
$ ./Main
k = 1: 2 3 5 7 11 13 17 19 23 29 
k = 2: 4 6 9 10 14 15 21 22 25 26 
k = 3: 8 12 18 20 27 28 30 42 44 45 
k = 4: 16 24 36 40 54 56 60 81 84 88 
k = 5: 32 48 72 80 108 112 120 162 168 176 

Optimising Compilation

Compile with optimizations using -O. To see the difference between the non-optimised version use -keep-llvm-files and look at the dropped Main.ddc.ll file.

$ ddc -make Main.ds -O -keep-llvm-files
$ ./Main
3628800

Code Generation

If you want to see the intermediate code then use -load, -to-salt, or -to-llvm. The first shows Core Tetra code after type inference, while the second shows the Core Salt, which is an intermediate imperative language.

$ ddc -to-salt Main.ds
...

Or with optimizations

$ ddc -O -to-salt Main.ds
...

The optimized -O version of the Salt code is fairly verbose. It includes code to check there is enough free space on the heap when allocating every object. It also relies on the follow-on LLVM optimiser to do constant folding.

Last modified 7 months ago Last modified on Sep 6, 2016, 10:19:43 AM