code gen bugfixes; marshal.nim implemented
This commit is contained in:
parent
db0a4a9f86
commit
990dc2d715
21 changed files with 725 additions and 422 deletions
|
|
@ -36,13 +36,16 @@ var
|
|||
IOFBF {.importc: "_IOFBF", nodecl.}: cint
|
||||
IONBF {.importc: "_IONBF", nodecl.}: cint
|
||||
|
||||
proc raiseEIO(msg: string) {.noinline, noreturn.} =
|
||||
raise newException(EIO, msg)
|
||||
|
||||
proc rawReadLine(f: TFile, result: var string) =
|
||||
# of course this could be optimized a bit; but IO is slow anyway...
|
||||
# and it was difficult to get this CORRECT with Ansi C's methods
|
||||
setLen(result, 0) # reuse the buffer!
|
||||
while True:
|
||||
var c = fgetc(f)
|
||||
if c < 0'i32: break # EOF
|
||||
if c < 0'i32: raiseEIO("EOF reached")
|
||||
if c == 10'i32: break # LF
|
||||
if c == 13'i32: # CR
|
||||
c = fgetc(f) # is the next char LF?
|
||||
|
|
@ -76,11 +79,6 @@ proc write(f: TFile, c: Char) = putc(c, f)
|
|||
proc write(f: TFile, a: openArray[string]) =
|
||||
for x in items(a): write(f, x)
|
||||
|
||||
#{.error: "for debugging.".}
|
||||
|
||||
proc raiseEIO(msg: string) {.noinline, noreturn.} =
|
||||
raise newException(EIO, msg)
|
||||
|
||||
proc readFile(filename: string): string =
|
||||
var f = open(filename)
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue