Users › 01 Getting started

Getting started

Build the toolchain, run your first program, and learn the four commands you will use every day.

1. Build the toolchain

Lopolith is a C11 program. From the repository root:

$ make            # builds ./loth (the compiler + VM + CLI)
$ make libs       # builds lib/Std.so and lib/Thread.so

make libs matters: the standard library is delivered as native plugins (.so), and #import Std will not resolve until they exist. Build both targets once and you are done.

2. Hello, world

Create hello.loth. A program is one file per class; the file path must match the class name.

%simple com.example.Hello implements Main
    #import Std
    int run(int argc, String[] argv) Main@run {
        Std.print("Hello, world!\n")
        return 0
    }
Hello, world!
$ ./loth run hello.loth
Hello, world!

Three things to notice, because they are different from most languages:

3. The four commands

loth run <file.loth> [-e Class] [-cp dir] [args...]   # compile (if needed) and run
loth compile <file.loth> -o <dir>                    # write portable .lothc modules
loth <file.lothc> [-e Class] [args...]                # run compiled modules
loth native-info <lib.so>                             # inspect a native library

4. Paths are part of the program

The fully-qualified name in the first directive must match the file path:

com/example/Hello.loth   ⇄   %simple com.example.Hello

This mapping is checked by the compiler and by the loader, so a class cannot quietly live under the wrong name. Every file has exactly one primary directive (%class, %interface, %simple, %native, %nativesimple), optionally followed by private helper classes (%sub), which chapter 2 covers.

5. What can go wrong