mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 22:10:33 +00:00
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:
@@ -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;
|
||||
"""
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user