2 Creating a Minimal Cminor Program

To create a minimal Cminor program:

  1. Create a directory for the project.
  2. Create a source code file with an extension .cminor and put it to the created directory.
  3. Create a project file with an extension .cminorp and put it to the created directory.

Here's the contents of the source file minimal.cminor:

Every valid Cminor program has a nonmember function called main where the execution begins.

Here's the contents of the project file minimal.cminorp:

The project declaration names the project. The source declarations list path to each source file contained by the project.

2.1 Building a Cminor Project

> cminor build minimal.cminorp

If the build succeeds the compiler prints by default nothing to the screen. On successful build the compiler creates a directory named assembly under the project directory. Under the assembly directory, there's a debug directory for debug builds and release directory for release builds. That directory contains an assembly file with extension .cminora that can be executed using the Cminor virtual machine.

Here's the directory structure of the program:

        |
        +--minimal
           |
           +--minimal.cminor
           |
           +--minimal.cminorp
           |
           +--assembly
              |
              +--debug
              |  |
              |  +--minimal.cminora
              |
              +--release
                 |
                 +--minimal.cminora
        

2.2 Running a Cminor Program

> cminor run assembly/debug/minimal.cminora

The minimal program does nothing so there's also no output. If no error occurs, an exit code value 0 is returned to the caller of the program.