diff options
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/hti.nim | 12 | ||||
-rw-r--r-- | lib/system/jssys.nim | 20 | ||||
-rw-r--r-- | lib/system/sysio.nim | 11 |
3 files changed, 14 insertions, 29 deletions
diff --git a/lib/system/hti.nim b/lib/system/hti.nim index bb3769ac4..c7b52bbdf 100644 --- a/lib/system/hti.nim +++ b/lib/system/hti.nim @@ -7,12 +7,6 @@ # distribution, for details about the copyright. # -when declared(ThisIsSystem): - # we are in system module: - {.pragma: codegenType, compilerproc.} -else: - {.pragma: codegenType, importc.} - type # This should be the same as ast.TTypeKind # many enum fields are not used at runtime @@ -79,7 +73,7 @@ type tyVoidHidden TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase - TNimNode {.codegenType.} = object + TNimNode {.compilerProc.} = object kind: TNimNodeKind offset: int typ: ptr TNimType @@ -92,7 +86,7 @@ type ntfAcyclic = 1, # type cannot form a cycle ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow # version - TNimType {.codegenType.} = object + TNimType {.compilerProc.} = object size: int kind: TNimKind flags: set[TNimTypeFlag] @@ -109,6 +103,6 @@ type PNimType = ptr TNimType when defined(nimTypeNames): - var nimTypeRoot {.codegenType.}: PNimType + var nimTypeRoot {.compilerProc.}: PNimType # node.len may be the ``first`` element of a set diff --git a/lib/system/jssys.nim b/lib/system/jssys.nim index 152b48c24..836ac198d 100644 --- a/lib/system/jssys.nim +++ b/lib/system/jssys.nim @@ -182,12 +182,10 @@ proc setConstr() {.varargs, asmNoStackFrame, compilerproc.} = proc makeNimstrLit(c: cstring): string {.asmNoStackFrame, compilerproc.} = {.emit: """ var ln = `c`.length; - var result = new Array(ln + 1); - var i = 0; - for (; i < ln; ++i) { + var result = new Array(ln); + for (var i = 0; i < ln; ++i) { result[i] = `c`.charCodeAt(i); } - result[i] = 0; // terminating zero return result; """.} @@ -225,13 +223,12 @@ proc cstrToNimstr(c: cstring): string {.asmNoStackFrame, compilerproc.} = } ++r; } - result[r] = 0; // terminating zero return result; """.} proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} = asm """ - var len = `s`.length-1; + var len = `s`.length; var asciiPart = new Array(len); var fcc = String.fromCharCode; var nonAsciiPart = null; @@ -262,10 +259,7 @@ proc toJSStr(s: string): cstring {.asmNoStackFrame, compilerproc.} = proc mnewString(len: int): string {.asmNoStackFrame, compilerproc.} = asm """ - var result = new Array(`len`+1); - result[0] = 0; - result[`len`] = 0; - return result; + return new Array(`len`); """ proc SetCard(a: int): int {.compilerproc, asmNoStackFrame.} = @@ -323,7 +317,7 @@ proc cmpStrings(a, b: string): int {.asmNoStackFrame, compilerProc.} = if (`a` == `b`) return 0; if (!`a`) return -1; if (!`b`) return 1; - for (var i = 0; i < `a`.length - 1 && i < `b`.length - 1; i++) { + for (var i = 0; i < `a`.length && i < `b`.length; i++) { var result = `a`[i] - `b`[i]; if (result != 0) return result; } @@ -651,9 +645,7 @@ proc isObj(obj, subclass: PNimType): bool {.compilerproc.} = return true proc addChar(x: string, c: char) {.compilerproc, asmNoStackFrame.} = - asm """ - `x`[`x`.length-1] = `c`; `x`.push(0); - """ + asm "`x`.push(`c`);" {.pop.} diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 40bbf97dc..61835e0f7 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -145,10 +145,9 @@ proc readLine(f: File, line: var TaintedString): bool = var pos = 0 # Use the currently reserved space for a first try - var sp = line.string.len - if sp == 0: - sp = 80 - line.string.setLen(sp) + var sp = max(line.string.len, 80) + line.string.setLen(sp) + while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where # fgets doesn't append an \L @@ -161,7 +160,7 @@ proc readLine(f: File, line: var TaintedString): bool = var last = cast[ByteAddress](m) - cast[ByteAddress](addr line.string[0]) if last > 0 and line.string[last-1] == '\c': line.string.setLen(last-1) - return fgetsSuccess + return last > 1 or fgetsSuccess # We have to distinguish between two possible cases: # \0\l\0 => line ending in a null character. # \0\l\l => last line without newline, null was put there by fgets. @@ -169,7 +168,7 @@ proc readLine(f: File, line: var TaintedString): bool = if last < pos + sp - 1 and line.string[last+1] != '\0': dec last line.string.setLen(last) - return fgetsSuccess + return last > 0 or fgetsSuccess else: # fgets will have inserted a null byte at the end of the string. dec sp |