Matchbox 0.2

Programs

A Matchbox program is a .mb source file made of statements, expressions, function definitions, and comments. Top-level statements run in source order after the file is compiled.

Matchbox is statically typed. The compiler knows the types of values before the program runs, which helps it catch mistakes early and produce bytecode with predictable storage and instruction choices.

This small program declares a variable, assigns values to it, and prints the result:

var count int
count = 10
count = count + 5

print(count)

Save it as basics.mb, then run:

matchbox basics.mb

The program writes:

15

Top-Level Statements

Code outside a function is top-level code. Matchbox runs top-level statements from the beginning of the file to the end.

In the example, var count int reserves memory for an integer named count. The assignments store values in that variable. The expression count + 5 produces a new integer value, and print writes the final value to standard output.

Functions and Blocks

Function definitions can also appear at the top level:

func square(value int) int {
    return value * value
}

var result = square(6)
print(result)

The statements between { and } form the function body. A function definition must appear before code that calls it because Matchbox resolves names in source order.

Reading Order

When reading a Matchbox file, start at the top and follow each statement in order. Declarations reserve memory, definitions provide initial values, assignments update existing variables, expressions produce values, and function calls run reusable code.

Matchbox 0.2 is intentionally small. It does not yet provide conditionals, loops, strings, file input, or standard input. See Current Limitations before designing a larger program.

Continue to Comments for the first language-basics topic.