diff options
Diffstat (limited to 'lib')
-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 |