Learn Aero / First Program

First Program

Create a file hello.aero:

// 第一个 Aero 程序
print("Hello, Aero!\n");

Run it:

aero run hello.aero

Output:

Hello, Aero!

What This print Does

print is a built-in Aero function that ultimately calls printf from the C standard library:

  • Without \n in the string, no newline is emitted
  • You can use format strings just like in C: print("%d\n", 42)
  • print(1 + 1);            // 输出 2
    print(2 + 3 * 4);        // 输出 14(乘除优先)
    print("两行\n文字\n");   // 输出两行

    Compiling to a Standalone Executable

    aero run is JIT: it compiles and runs directly in memory without writing a file. To get a standalone, distributable .exe:

    aero build hello.aero

    This produces hello.exe, which you can run by double-clicking. This exe neither depends on the Aero compiler nor on LLVM dynamic libraries — copy it to another Windows machine and it will run as long as the target machine has a normal UCRT runtime.

    What Error Messages Look Like

    Aero's compile errors are in English, with a consistent format:

    错误: line 3 col 5 [语法分析] expected `;`, found `}`

    From left to right: the line and column of the error, the stage (lexing/parsing/type/borrow/codegen), and the specific message.

    Exercises

    1. Make the program output three lines: your name, today's date, and a slogan

    2. Compile with aero build, copy the exe to another directory and run it, confirming it doesn't depend on the original directory

    3. Deliberately remove a semicolon and run again, then read the error message

    Aero 文档 · 基于 Aero 1.2.0 文档整理 · MIT
    SereinTeam