empirical-lang icon indicating copy to clipboard operation
empirical-lang copied to clipboard

Integer overflow detection

Open chrisaycock opened this issue 4 years ago • 0 comments

Suggested by @llllllllll, use the compiler-optimized routines for safe integer arithmetic, setting the failed result to nil. For example:

x = ...;
y = ...;
if (__builtin_add_overflow(x, y, &z)) {
  z = nil_value;
}

This would require a significant change to the interpreter's math routines. The current set-up is portable, generic, and fast. We would need this to operate across Clang, GCC, and Visual Studio.

There could be a "debug" mode for Empirical in the future, which would abort when overflow occurs rather than return a nil.

chrisaycock avatar Feb 08 '21 05:02 chrisaycock