many bugfixes for js (#14158)

* many bugfixes for js

fixes #12672, fixes #14153, closes #14123, closes #11331, fixes #11783, fixes #13966, fixes #14087, fixes #14117, closes #12256.

mostly fixes the fact that it was allowed to assign to newly created temp variables. additionally attempts to get rid of null initialized seqs/strings (though they might pop up here and there); this simplifies a lot of things and makes code size smaller. even if null seqs/strings pop up here and there it's still better than all those bugs existing.

* formatting fixes

* CI fixes

* more CI fixes
This commit is contained in:
hlaaftana 2020-04-29 21:55:09 +03:00 • committed by GitHub
commit 707367e1ca
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 240 additions and 65 deletions

View file

@ -397,24 +397,29 @@ else:
""".}
# Arithmetic:
proc checkOverflowInt(a: int) {.asmNoStackFrame, compilerproc.} =
asm """
if (`a` > 2147483647 || `a` < -2147483648) `raiseOverflow`();
"""
proc addInt(a, b: int): int {.asmNoStackFrame, compilerproc.} =
asm """
var result = `a` + `b`;
if (result > 2147483647 || result < -2147483648) `raiseOverflow`();
`checkOverflowInt`(result);
return result;
"""
proc subInt(a, b: int): int {.asmNoStackFrame, compilerproc.} =
asm """
var result = `a` - `b`;
if (result > 2147483647 || result < -2147483648) `raiseOverflow`();
`checkOverflowInt`(result);
return result;
"""
proc mulInt(a, b: int): int {.asmNoStackFrame, compilerproc.} =
asm """
var result = `a` * `b`;
if (result > 2147483647 || result < -2147483648) `raiseOverflow`();
`checkOverflowInt`(result);
return result;
"""
@ -432,27 +437,29 @@ proc modInt(a, b: int): int {.asmNoStackFrame, compilerproc.} =
return Math.trunc(`a` % `b`);
"""
proc checkOverflowInt64(a: int) {.asmNoStackFrame, compilerproc.} =
asm """
if (`a` > 9223372036854775807 || `a` < -9223372036854775808) `raiseOverflow`();
"""
proc addInt64(a, b: int): int {.asmNoStackFrame, compilerproc.} =
asm """
var result = `a` + `b`;
if (result > 9223372036854775807
|| result < -9223372036854775808) `raiseOverflow`();
`checkOverflowInt64`(result);
return result;
"""
proc subInt64(a, b: int): int {.asmNoStackFrame, compilerproc.} =
asm """
var result = `a` - `b`;
if (result > 9223372036854775807
|| result < -9223372036854775808) `raiseOverflow`();
`checkOverflowInt64`(result);
return result;
"""
proc mulInt64(a, b: int): int {.asmNoStackFrame, compilerproc.} =
asm """
var result = `a` * `b`;
if (result > 9223372036854775807
|| result < -9223372036854775808) `raiseOverflow`();
`checkOverflowInt64`(result);
return result;
"""