mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-14 07:13:27 +00:00
further system.nim cleanups
This commit is contained in:
@@ -114,18 +114,18 @@ proc c_signal(sign: cint, handler: proc (a: cint) {.noconv.}): c_sighandler_t {.
|
||||
type
|
||||
CFile {.importc: "FILE", header: "<stdio.h>",
|
||||
incompletestruct.} = object
|
||||
CFileStar* = ptr CFile ## The type representing a file handle.
|
||||
CFilePtr* = ptr CFile ## The type representing a file handle.
|
||||
|
||||
var
|
||||
cstderr* {.importc: "stderr", header: "<stdio.h>".}: CFileStar
|
||||
cstdout* {.importc: "stdout", header: "<stdio.h>".}: CFileStar
|
||||
cstderr* {.importc: "stderr", header: "<stdio.h>".}: CFilePtr
|
||||
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.}
|
||||
proc c_printf(frmt: cstring): cint {.
|
||||
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.}
|
||||
|
||||
proc c_sprintf(buf, frmt: cstring): cint {.
|
||||
|
||||
@@ -76,30 +76,30 @@ proc `==`(a, b: StaticStr): bool =
|
||||
proc `==`(a: StaticStr, b: cstring): bool =
|
||||
result = c_strcmp(unsafeAddr a.data, b) == 0
|
||||
|
||||
proc write(f: CFileStar, s: cstring) = c_fputs(s, f)
|
||||
proc writeLine(f: CFileStar, s: cstring) =
|
||||
proc write(f: CFilePtr, s: cstring) = c_fputs(s, f)
|
||||
proc writeLine(f: CFilePtr, s: cstring) =
|
||||
c_fputs(s, f)
|
||||
c_fputs("\n", f)
|
||||
|
||||
proc write(f: CFileStar, s: StaticStr) =
|
||||
proc write(f: CFilePtr, s: StaticStr) =
|
||||
write(f, cstring(unsafeAddr s.data))
|
||||
|
||||
proc write(f: CFileStar, i: int) =
|
||||
proc write(f: CFilePtr, i: int) =
|
||||
when sizeof(int) == 8:
|
||||
discard c_fprintf(f, "%lld", i)
|
||||
else:
|
||||
discard c_fprintf(f, "%ld", i)
|
||||
|
||||
proc close(f: CFileStar): cint {.
|
||||
proc close(f: CFilePtr): cint {.
|
||||
importc: "fclose", header: "<stdio.h>", discardable.}
|
||||
|
||||
proc c_fgetc(stream: CFileStar): cint {.
|
||||
proc c_fgetc(stream: CFilePtr): cint {.
|
||||
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.}
|
||||
|
||||
var
|
||||
cstdin* {.importc: "stdin", header: "<stdio.h>".}: CFileStar
|
||||
cstdin* {.importc: "stdin", header: "<stdio.h>".}: CFilePtr
|
||||
|
||||
proc listBreakPoints() =
|
||||
write(cstdout, EndbBeg)
|
||||
@@ -117,8 +117,8 @@ proc listBreakPoints() =
|
||||
write(cstdout, "\n")
|
||||
write(cstdout, EndbEnd)
|
||||
|
||||
proc openAppend(filename: cstring): CFileStar =
|
||||
proc fopen(filename, mode: cstring): CFileStar {.importc: "fopen", header: "<stdio.h>".}
|
||||
proc openAppend(filename: cstring): CFilePtr =
|
||||
proc fopen(filename, mode: cstring): CFilePtr {.importc: "fopen", header: "<stdio.h>".}
|
||||
|
||||
result = fopen(filename, "ab")
|
||||
if result != nil:
|
||||
@@ -135,12 +135,12 @@ proc dbgRepr(p: pointer, typ: PNimType): string =
|
||||
# dec(recGcLock)
|
||||
deinitReprClosure(cl)
|
||||
|
||||
proc writeVariable(stream: CFileStar, slot: VarSlot) =
|
||||
proc writeVariable(stream: CFilePtr, slot: VarSlot) =
|
||||
write(stream, slot.name)
|
||||
write(stream, " = ")
|
||||
writeLine(stream, dbgRepr(slot.address, slot.typ))
|
||||
|
||||
proc listFrame(stream: CFileStar, f: PFrame) =
|
||||
proc listFrame(stream: CFilePtr, f: PFrame) =
|
||||
write(stream, EndbBeg)
|
||||
write(stream, "| Frame (")
|
||||
write(stream, f.len)
|
||||
@@ -149,7 +149,7 @@ proc listFrame(stream: CFileStar, f: PFrame) =
|
||||
writeLine(stream, getLocal(f, i).name)
|
||||
write(stream, EndbEnd)
|
||||
|
||||
proc listLocals(stream: CFileStar, f: PFrame) =
|
||||
proc listLocals(stream: CFilePtr, f: PFrame) =
|
||||
write(stream, EndbBeg)
|
||||
write(stream, "| Frame (")
|
||||
write(stream, f.len)
|
||||
@@ -158,7 +158,7 @@ proc listLocals(stream: CFileStar, f: PFrame) =
|
||||
writeVariable(stream, getLocal(f, i))
|
||||
write(stream, EndbEnd)
|
||||
|
||||
proc listGlobals(stream: CFileStar) =
|
||||
proc listGlobals(stream: CFilePtr) =
|
||||
write(stream, EndbBeg)
|
||||
write(stream, "| Globals:\n")
|
||||
for i in 0 .. getGlobalLen()-1:
|
||||
@@ -302,7 +302,7 @@ proc breakpointToggle(s: cstring, start: int) =
|
||||
if not b.isNil: b.flip
|
||||
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 i = scanWord(s, dbgTemp, start)
|
||||
while s[i] in {' ', '\t'}: inc(i)
|
||||
@@ -348,7 +348,7 @@ proc dbgStackFrame(s: cstring, start: int, currFrame: PFrame) =
|
||||
listFrame(stream, currFrame)
|
||||
close(stream)
|
||||
|
||||
proc readLine(f: CFileStar, line: var StaticStr): bool =
|
||||
proc readLine(f: CFilePtr, line: var StaticStr): bool =
|
||||
while true:
|
||||
var c = c_fgetc(f)
|
||||
if c < 0'i32:
|
||||
|
||||
@@ -17,10 +17,10 @@ var
|
||||
## instead of stdmsg.write when printing stacktrace.
|
||||
## 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>".}
|
||||
|
||||
proc rawWrite(f: CFileStar, s: string|cstring) =
|
||||
proc rawWrite(f: CFilePtr, s: string|cstring) =
|
||||
# we cannot throw an exception here!
|
||||
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
|
||||
|
||||
|
||||
@@ -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.}
|
||||
Reference in New Issue
Block a user