diff options
author | hlaaftana <10591326+hlaaftana@users.noreply.github.com> | 2020-04-29 21:55:09 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-29 20:55:09 +0200 |
commit | 707367e1ca231d964ba82a92b642eb5efdc1aa7c (patch) | |
tree | 9c65a95fea503194c8aa804832944e4c91797d06 /lib/system | |
parent | a297c016fab069665aeb1125ff1c85b5e25e6a01 (diff) | |
download | Nim-707367e1ca231d964ba82a92b642eb5efdc1aa7c.tar.gz |
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
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/jssys.nim | 25 | ||||
-rw-r--r-- | lib/system/reprjs.nim | 14 |
2 files changed, 16 insertions, 23 deletions
diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 98a7a2032..106283490 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -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; """ diff --git a/lib/system/reprjs.nim b/lib/system/reprjs.nim index c45053537..c3f3199a4 100644 --- a/lib/system/reprjs.nim +++ b/lib/system/reprjs.nim @@ -130,20 +130,6 @@ proc reprAux(result: var string, p: pointer, typ: PNimType, cl: var ReprClosure) proc reprArray(a: pointer, typ: PNimType, cl: var ReprClosure): string {.compilerRtl.} = - var isNilArrayOrSeq: bool - # isnil is not enough here as it would try to deref `a` without knowing what's inside - {. emit: """ - if (`a` == null) { - `isNilArrayOrSeq` = true; - } else if (`a`[0] == null) { - `isNilArrayOrSeq` = true; - } else { - `isNilArrayOrSeq` = false; - }; - """ .} - if typ.kind == tySequence and isNilArrayOrSeq: - return "nil" - # We prepend @ to seq, the C backend prepends the pointer to the seq. result = if typ.kind == tySequence: "@[" else: "[" var len: int = 0 |