Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Basics

A BitterASM program is a text file, usually ending in .basm. This chapter covers what every program is made of: its layout, and the values it computes with.

One statement per line

A newline ends a statement, just as in a traditional assembler:

macro show(value: int) {
    @emit value
}

show 1
show 2
1 2

Inside (), [] and {}, a statement can continue onto the next line, so a long call can be split:

macro add3(a: int, b: int, c: int) -> int {
    @return a + b + c
}

macro show(value: int) {
    @emit value
}

show add3(
    1,
    2,
    3
)
6

Comments

# starts a comment that runs to the end of the line. There are no block comments. ## and #! start doc comments.

# A whole-line comment.
macro show(value: int) {
    @emit value    # a trailing comment
}

show 7
7

Names

Names may contain letters, digits and underscores, and don’t start with a digit. Any Unicode letter counts, so π is a valid name. A name that starts with an underscore marks a parameter as deliberately unused (see Diagnostics and lints).

The only reserved words are from, import, as, in, pub, skip, macro, type, struct, enum, const and section. Everything else, including int and every instruction mnemonic, is an ordinary name.

Order doesn’t matter

A file’s declarations are visible throughout the file, so you can use a macro or constant above the line that declares it:

show LIMIT

const LIMIT = 9

macro show(value: int) {
    @emit value
}
9

What does follow source order is the output: calls emit their values in the order they appear.

What a file can contain

StatementExampleChapter
Importfrom std.binary import bitsModules
Constantconst WIDTH = 8Constants
Macromacro nop() { ... }Macros
Struct, enum, type aliasstruct Point { ... }Types
Macro calladd a0, a1, a2Macros
Labelloop:Labels
Sectionsection .textSections
Syntax overridesyntax add(a, b) = { ... }Custom syntax
@for, @if, @fold@for i in 0..4 { ... }Meta keywords

In this chapter