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 threadon --run --debug file.th
Four 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. - List index out of bounds. Reading
xs[i]with an index past the end of the list stops withError: List index out of bounds. - Dict key not found. Reading
d[k]whenkisn't in the dict stops withError: KeyError: dict key not found.
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.