- Antril
- Getting started
- Your first program
Your first program
Create an Antril project from a template, run it, build it and change it.
A Larva project is a folder with a .queen project file and its source files. larva new makes one from a template.
Create a project
larva new with no arguments lists the templates and the languages:
larva new
Templates (larva new <template> [Name] [--lang <language>]):
Console-App A program for the console: its Main prints a greeting
Library A library other projects use: a class with a method
Languages (--lang):
antril Antril 0.8.0 (.ant)
Create a console program called Hello:
larva new Console-App Hello
C:\work\Hello: Console App in Antril (Program.ant, Hello.queen)
larva build Hello\Hello.queen
The project goes into a new folder named after it; -o <folder> puts it somewhere else. When Antril is the only language installed, larva uses it; otherwise add --lang antril.
What is in the project
Hello/
Hello.queen the project file
Program.ant the program
bin/ the build (made by larva build or larva run)
Program.ant holds the entry point, Main, inside the project's namespace:
import System;
into namespace Hello
{
/// The program's entry.
Main()
{
Console.WriteLine("Hello from Larva!");
}
}
Hello.queen says what the project is and how it is built:
queen 1.0;
chunk PROJ:
name: Hello,
type: exe,
version: v1.0
chunk BUILD:
gc: default,
backend: llvm,
optimization: 3,
borrowcheck: off,
unsafe: allow
larva new writes the BUILD chunk from the values your machine uses (see larva config in The larva command). Every chunk and key is described in Project files.
Run it
From the project's folder, larva run builds the program if something changed and runs it:
cd Hello
larva run
C:\work\Hello\bin\Hello.exe (llvm back end, O3, entry Hello::Hello.$Module.Main)
Hello from Larva!
The first line is larva's build report; it goes to the error stream, so the program's own output stays apart. Run it again without changes and larva goes straight to the program.
larva run takes the same build options as larva build. For example, larva run --backend x64 builds with Larva's own x86-64 back end, which compiles faster than LLVM.
Build it
larva build with no file compiles the project you are in:
larva build
C:\work\Hello\bin\Hello.exe (llvm back end, O3, entry Hello::Hello.$Module.Main)
The executable goes to bin/<name>.exe, unless the .queen names another place with output: in BUILD. A project with type: library builds bin/<name>.dll, a Larva library other projects can use.
Tip
To check the code without producing anything, use larva build --check.
Change the program
Open Program.ant and replace Main:
import System;
into namespace Hello
{
/// The program's entry.
Main()
{
str[] names = ["Ana", "Luis", "Mia"];
loop (str name in names)
Console.WriteLine($"Hello, {name}!");
Console.WriteLine($"{names.Length} greetings");
}
}
larva run
C:\work\Hello\bin\Hello.exe (llvm back end, O3, entry Hello::Hello.$Module.Main)
Hello, Ana!
Hello, Luis!
Hello, Mia!
3 greetings
Every .ant file under the project's folder is part of the project, so you can add files next to Program.ant without listing them anywhere.
A library
The Library template makes a project that other projects use:
larva new Library Shapes
C:\work\Shapes: Library in Antril (Greeter.ant, Shapes.queen)
larva build Shapes\Shapes.queen
Another project uses it by naming it in its DEPS chunk (proj: ../Shapes), or as a package through Hive.
Next: the language tour.
Edit this page on GitHub Report an issue