further system.nim cleanups
This commit is contained in:
parent
2851f316f6
commit
37f9ace517
5 changed files with 31 additions and 42 deletions
|
|
@ -114,18 +114,18 @@ proc c_signal(sign: cint, handler: proc (a: cint) {.noconv.}): c_sighandler_t {.
|
||||||
type
|
type
|
||||||
CFile {.importc: "FILE", header: "<stdio.h>",
|
CFile {.importc: "FILE", header: "<stdio.h>",
|
||||||
incompletestruct.} = object
|
incompletestruct.} = object
|
||||||
CFileStar* = ptr CFile ## The type representing a file handle.
|
CFilePtr* = ptr CFile ## The type representing a file handle.
|
||||||
|
|
||||||
var
|
var
|
||||||
cstderr* {.importc: "stderr", header: "<stdio.h>".}: CFileStar
|
cstderr* {.importc: "stderr", header: "<stdio.h>".}: CFilePtr
|
||||||
cstdout* {.importc: "stdout", header: "<stdio.h>".}: CFileStar
|
cstdout* {.importc: "stdout", header: "<stdio.h>".}: CFilePtr
|
||||||
|
|
||||||
proc c_fprintf(f: CFileStar, frmt: cstring): cint {.
|
proc c_fprintf(f: CFilePtr, frmt: cstring): cint {.
|
||||||
importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
|
importc: "fprintf", header: "<stdio.h>", varargs, discardable.}
|
||||||
proc c_printf(frmt: cstring): cint {.
|
proc c_printf(frmt: cstring): cint {.
|
||||||
importc: "printf", header: "<stdio.h>", varargs, discardable.}
|
importc: "printf", header: "<stdio.h>", varargs, discardable.}
|
||||||
|
|
||||||
proc c_fputs(c: cstring, f: CFileStar): cint {.
|
proc c_fputs(c: cstring, f: CFilePtr): cint {.
|
||||||
importc: "fputs", header: "<stdio.h>", discardable.}
|
importc: "fputs", header: "<stdio.h>", discardable.}
|
||||||
|
|
||||||
proc c_sprintf(buf, frmt: cstring): cint {.
|
proc c_sprintf(buf, frmt: cstring): cint {.
|
||||||
|
|
|
||||||
|
|
@ -76,30 +76,30 @@ proc `==`(a, b: StaticStr): bool =
|
||||||
proc `==`(a: StaticStr, b: cstring): bool =
|
proc `==`(a: StaticStr, b: cstring): bool =
|
||||||
result = c_strcmp(unsafeAddr a.data, b) == 0
|
result = c_strcmp(unsafeAddr a.data, b) == 0
|
||||||
|
|
||||||
proc write(f: CFileStar, s: cstring) = c_fputs(s, f)
|
proc write(f: CFilePtr, s: cstring) = c_fputs(s, f)
|
||||||
proc writeLine(f: CFileStar, s: cstring) =
|
proc writeLine(f: CFilePtr, s: cstring) =
|
||||||
c_fputs(s, f)
|
c_fputs(s, f)
|
||||||
c_fputs("\n", f)
|
c_fputs("\n", f)
|
||||||
|
|
||||||
proc write(f: CFileStar, s: StaticStr) =
|
proc write(f: CFilePtr, s: StaticStr) =
|
||||||
write(f, cstring(unsafeAddr s.data))
|
write(f, cstring(unsafeAddr s.data))
|
||||||
|
|
||||||
proc write(f: CFileStar, i: int) =
|
proc write(f: CFilePtr, i: int) =
|
||||||
when sizeof(int) == 8:
|
when sizeof(int) == 8:
|
||||||
discard c_fprintf(f, "%lld", i)
|
discard c_fprintf(f, "%lld", i)
|
||||||
else:
|
else:
|
||||||
discard c_fprintf(f, "%ld", i)
|
discard c_fprintf(f, "%ld", i)
|
||||||
|
|
||||||
proc close(f: CFileStar): cint {.
|
proc close(f: CFilePtr): cint {.
|
||||||
importc: "fclose", header: "<stdio.h>", discardable.}
|
importc: "fclose", header: "<stdio.h>", discardable.}
|
||||||
|
|
||||||
proc c_fgetc(stream: CFileStar): cint {.
|
proc c_fgetc(stream: CFilePtr): cint {.
|
||||||
importc: "fgetc", header: "<stdio.h>".}
|
importc: "fgetc", header: "<stdio.h>".}
|
||||||
proc c_ungetc(c: cint, f: CFileStar): cint {.
|
proc c_ungetc(c: cint, f: CFilePtr): cint {.
|
||||||
importc: "ungetc", header: "<stdio.h>", discardable.}
|
importc: "ungetc", header: "<stdio.h>", discardable.}
|
||||||
|
|
||||||
var
|
var
|
||||||
cstdin* {.importc: "stdin", header: "<stdio.h>".}: CFileStar
|
cstdin* {.importc: "stdin", header: "<stdio.h>".}: CFilePtr
|
||||||
|
|
||||||
proc listBreakPoints() =
|
proc listBreakPoints() =
|
||||||
write(cstdout, EndbBeg)
|
write(cstdout, EndbBeg)
|
||||||
|
|
@ -117,8 +117,8 @@ proc listBreakPoints() =
|
||||||
write(cstdout, "\n")
|
write(cstdout, "\n")
|
||||||
write(cstdout, EndbEnd)
|
write(cstdout, EndbEnd)
|
||||||
|
|
||||||
proc openAppend(filename: cstring): CFileStar =
|
proc openAppend(filename: cstring): CFilePtr =
|
||||||
proc fopen(filename, mode: cstring): CFileStar {.importc: "fopen", header: "<stdio.h>".}
|
proc fopen(filename, mode: cstring): CFilePtr {.importc: "fopen", header: "<stdio.h>".}
|
||||||
|
|
||||||
result = fopen(filename, "ab")
|
result = fopen(filename, "ab")
|
||||||
if result != nil:
|
if result != nil:
|
||||||
|
|
@ -135,12 +135,12 @@ proc dbgRepr(p: pointer, typ: PNimType): string =
|
||||||
# dec(recGcLock)
|
# dec(recGcLock)
|
||||||
deinitReprClosure(cl)
|
deinitReprClosure(cl)
|
||||||
|
|
||||||
proc writeVariable(stream: CFileStar, slot: VarSlot) =
|
proc writeVariable(stream: CFilePtr, slot: VarSlot) =
|
||||||
write(stream, slot.name)
|
write(stream, slot.name)
|
||||||
write(stream, " = ")
|
write(stream, " = ")
|
||||||
writeLine(stream, dbgRepr(slot.address, slot.typ))
|
writeLine(stream, dbgRepr(slot.address, slot.typ))
|
||||||
|
|
||||||
proc listFrame(stream: CFileStar, f: PFrame) =
|
proc listFrame(stream: CFilePtr, f: PFrame) =
|
||||||
write(stream, EndbBeg)
|
write(stream, EndbBeg)
|
||||||
write(stream, "| Frame (")
|
write(stream, "| Frame (")
|
||||||
write(stream, f.len)
|
write(stream, f.len)
|
||||||
|
|
@ -149,7 +149,7 @@ proc listFrame(stream: CFileStar, f: PFrame) =
|
||||||
writeLine(stream, getLocal(f, i).name)
|
writeLine(stream, getLocal(f, i).name)
|
||||||
write(stream, EndbEnd)
|
write(stream, EndbEnd)
|
||||||
|
|
||||||
proc listLocals(stream: CFileStar, f: PFrame) =
|
proc listLocals(stream: CFilePtr, f: PFrame) =
|
||||||
write(stream, EndbBeg)
|
write(stream, EndbBeg)
|
||||||
write(stream, "| Frame (")
|
write(stream, "| Frame (")
|
||||||
write(stream, f.len)
|
write(stream, f.len)
|
||||||
|
|
@ -158,7 +158,7 @@ proc listLocals(stream: CFileStar, f: PFrame) =
|
||||||
writeVariable(stream, getLocal(f, i))
|
writeVariable(stream, getLocal(f, i))
|
||||||
write(stream, EndbEnd)
|
write(stream, EndbEnd)
|
||||||
|
|
||||||
proc listGlobals(stream: CFileStar) =
|
proc listGlobals(stream: CFilePtr) =
|
||||||
write(stream, EndbBeg)
|
write(stream, EndbBeg)
|
||||||
write(stream, "| Globals:\n")
|
write(stream, "| Globals:\n")
|
||||||
for i in 0 .. getGlobalLen()-1:
|
for i in 0 .. getGlobalLen()-1:
|
||||||
|
|
@ -302,7 +302,7 @@ proc breakpointToggle(s: cstring, start: int) =
|
||||||
if not b.isNil: b.flip
|
if not b.isNil: b.flip
|
||||||
else: debugOut("[Warning] unknown breakpoint ")
|
else: debugOut("[Warning] unknown breakpoint ")
|
||||||
|
|
||||||
proc dbgEvaluate(stream: CFileStar, s: cstring, start: int, f: PFrame) =
|
proc dbgEvaluate(stream: CFilePtr, s: cstring, start: int, f: PFrame) =
|
||||||
var dbgTemp: StaticStr
|
var dbgTemp: StaticStr
|
||||||
var i = scanWord(s, dbgTemp, start)
|
var i = scanWord(s, dbgTemp, start)
|
||||||
while s[i] in {' ', '\t'}: inc(i)
|
while s[i] in {' ', '\t'}: inc(i)
|
||||||
|
|
@ -348,7 +348,7 @@ proc dbgStackFrame(s: cstring, start: int, currFrame: PFrame) =
|
||||||
listFrame(stream, currFrame)
|
listFrame(stream, currFrame)
|
||||||
close(stream)
|
close(stream)
|
||||||
|
|
||||||
proc readLine(f: CFileStar, line: var StaticStr): bool =
|
proc readLine(f: CFilePtr, line: var StaticStr): bool =
|
||||||
while true:
|
while true:
|
||||||
var c = c_fgetc(f)
|
var c = c_fgetc(f)
|
||||||
if c < 0'i32:
|
if c < 0'i32:
|
||||||
|
|
|
||||||
|
|
@ -17,10 +17,10 @@ var
|
||||||
## instead of stdmsg.write when printing stacktrace.
|
## instead of stdmsg.write when printing stacktrace.
|
||||||
## Unstable API.
|
## Unstable API.
|
||||||
|
|
||||||
proc c_fwrite(buf: pointer, size, n: csize, f: CFileStar): cint {.
|
proc c_fwrite(buf: pointer, size, n: csize, f: CFilePtr): cint {.
|
||||||
importc: "fwrite", header: "<stdio.h>".}
|
importc: "fwrite", header: "<stdio.h>".}
|
||||||
|
|
||||||
proc rawWrite(f: CFileStar, s: string|cstring) =
|
proc rawWrite(f: CFilePtr, s: string|cstring) =
|
||||||
# we cannot throw an exception here!
|
# we cannot throw an exception here!
|
||||||
discard c_fwrite(cstring(s), 1, s.len, f)
|
discard c_fwrite(cstring(s), 1, s.len, f)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Nim's Runtime Library
|
||||||
|
# (c) Copyright 2019 Nim contributors
|
||||||
|
#
|
||||||
|
# See the file "copying.txt", included in this
|
||||||
|
# distribution, for details about the copyright.
|
||||||
|
#
|
||||||
|
|
||||||
include inclrtl
|
include inclrtl
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,19 +0,0 @@
|
||||||
#
|
|
||||||
#
|
|
||||||
# Nim's Runtime Library
|
|
||||||
# (c) Copyright 2013 Andreas Rumpf
|
|
||||||
#
|
|
||||||
# See the file "copying.txt", included in this
|
|
||||||
# distribution, for details about the copyright.
|
|
||||||
#
|
|
||||||
|
|
||||||
|
|
||||||
# Nim's standard IO library. It contains high-performance
|
|
||||||
# routines for reading and writing data to (buffered) files or
|
|
||||||
# TTYs.
|
|
||||||
|
|
||||||
{.push debugger:off .} # the user does not want to trace a part
|
|
||||||
# of the standard library!
|
|
||||||
|
|
||||||
|
|
||||||
{.pop.}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue