Matchbox 0.2

Debugging

Use a repeatable process when a Matchbox program fails to compile or produces an unexpected result.

Confirm the Version

Make sure the installed compiler matches this documentation:

matchbox --version

Confirm that the output reports a Matchbox 0.2 patch release.

Read the Diagnostic

Run the source file and read the complete diagnostic before editing:

matchbox main.mb

Start with the reported file and line. Check keyword spelling, braces, parentheses, function parameters, and statement boundaries near that location. See Compiler Diagnostics for common messages and corrections.

Trace Integer Values

Use print to inspect intermediate results:

var a = 10
var b = 20
var result = a + b

print(a)
print(b)
print(result)

Add prints around the smallest suspicious expression, then remove them after the problem is understood.

Reduce the Program

Copy the failing source file and remove unrelated statements one at a time. Keep the smallest program that still reproduces the problem. A small example makes incorrect values and compiler diagnostics easier to isolate.

Inspect Bytecode

Use -d to compile a source file and display its bytecode:

matchbox -d main.mb

Bytecode can confirm which operations the compiler generated. See Command Line for an example.

Check Program Exit

If execution stops earlier than expected, inspect calls to exit. Statements after exit are not executed.

Runtime arithmetic errors such as division by zero do not have a language-level diagnostic in 0.2. Check divisors, shift counts, and integer ranges before the failing expression.