What debug mode does
Debug mode adds runtime checks that normally aren't there, because the compiler trusts you. Turn it on with --debug:
python3 -m compiler.main --run --debug file.th
Two kinds of checks get added:
- Integer division and modulo by zero. Applies to
/,//, and%on integers, whenever the divisor's value is only known at runtime. (If the divisor is a compile-time constant zero, the compiler rejects it even without--debug; see Flow.) - Bad string-to-number conversions. Converting a
StringtoInt32,Int8, orFloat32when the string doesn't start with a number.
What a runtime error looks like
When a check fires, the program prints to stderr and exits with code 1.
Enter a number: 0
[RUNTIME ERROR]
│ Error: Division by zero
├─> Location: (null)
└─> Process terminated with exit code 1
A bad conversion reports which cast failed:
[RUNTIME ERROR]
│ Error: Invalid integer conversion
├─> Location: String → Integer cast
└─> Process terminated with exit code 1
The box-drawing lines and colors render on a terminal; if you pipe the output, the raw ANSI escapes show through.
Without debug mode
No checks, no safety net. Dividing by zero and invalid conversions are undefined behavior, straight from the generated LLVM. In practice you get whatever the runtime does, and it won't be a friendly message. Debug mode is for development; leave it off for performance.
What debug mode does not catch
- Array bounds, pointer misuse, or memory bugs: there are no arrays or explicit pointers to protect.
- Reading an uninitialized struct field. That garbage is yours to keep.
The 09_zero_division example in the repo demonstrates a caught division by zero. See Examples.