New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
system refactorings #10559
Merged
Merged
system refactorings #10559
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2f2c93f
move IO subsystem into its own module; refs #10385
Araq 774e8c0
make standalone test compile again
Araq ca1a763
make C++ examples compile again
Araq daee511
make more tests green
Araq 76cc99c
make sysAssert and gcAssert work again
Araq File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,29 +76,52 @@ proc `==`(a, b: StaticStr): bool = | |
proc `==`(a: StaticStr, b: cstring): bool = | ||
result = c_strcmp(unsafeAddr a.data, b) == 0 | ||
|
||
proc write(f: File, s: StaticStr) = | ||
proc write(f: CFileStar, s: cstring) = c_fputs(s, f) | ||
proc writeLine(f: CFileStar, s: cstring) = | ||
c_fputs(s, f) | ||
c_fputs("\n", f) | ||
|
||
proc write(f: CFileStar, s: StaticStr) = | ||
write(f, cstring(unsafeAddr s.data)) | ||
|
||
proc write(f: CFileStar, i: int) = | ||
when sizeof(int) == 8: | ||
discard c_fprintf(f, "%lld", i) | ||
else: | ||
discard c_fprintf(f, "%ld", i) | ||
|
||
proc close(f: CFileStar): cint {. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
for reference here was the previous definition: proc c_fclose(f: File): cint {.
importc: "fclose", header: "<stdio.h>".}
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's ENDB, I hacked it together. |
||
importc: "fclose", header: "<stdio.h>", discardable.} | ||
|
||
proc c_fgetc(stream: CFileStar): cint {. | ||
importc: "fgetc", header: "<stdio.h>".} | ||
proc c_ungetc(c: cint, f: CFileStar): cint {. | ||
importc: "ungetc", header: "<stdio.h>", discardable.} | ||
|
||
var | ||
cstdin* {.importc: "stdin", header: "<stdio.h>".}: CFileStar | ||
|
||
proc listBreakPoints() = | ||
write(stdout, EndbBeg) | ||
write(stdout, "| Breakpoints:\n") | ||
write(cstdout, EndbBeg) | ||
write(cstdout, "| Breakpoints:\n") | ||
for b in listBreakpoints(): | ||
write(stdout, abs(b.low)) | ||
write(cstdout, abs(b.low)) | ||
if b.high != b.low: | ||
write(stdout, "..") | ||
write(stdout, abs(b.high)) | ||
write(stdout, " ") | ||
write(stdout, b.filename) | ||
write(cstdout, "..") | ||
write(cstdout, abs(b.high)) | ||
write(cstdout, " ") | ||
write(cstdout, b.filename) | ||
if b.isActive: | ||
write(stdout, " [disabled]\n") | ||
write(cstdout, " [disabled]\n") | ||
else: | ||
write(stdout, "\n") | ||
write(stdout, EndbEnd) | ||
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): File = | ||
var p: pointer = fopen(filename, "ab") | ||
if p != nil: | ||
result = cast[File](p) | ||
result = fopen(filename, "ab") | ||
if result != nil: | ||
write(result, "----------------------------------------\n") | ||
|
||
proc dbgRepr(p: pointer, typ: PNimType): string = | ||
|
@@ -112,12 +135,12 @@ proc dbgRepr(p: pointer, typ: PNimType): string = | |
# dec(recGcLock) | ||
deinitReprClosure(cl) | ||
|
||
proc writeVariable(stream: File, slot: VarSlot) = | ||
proc writeVariable(stream: CFileStar, slot: VarSlot) = | ||
write(stream, slot.name) | ||
write(stream, " = ") | ||
writeLine(stream, dbgRepr(slot.address, slot.typ)) | ||
|
||
proc listFrame(stream: File, f: PFrame) = | ||
proc listFrame(stream: CFileStar, f: PFrame) = | ||
write(stream, EndbBeg) | ||
write(stream, "| Frame (") | ||
write(stream, f.len) | ||
|
@@ -126,7 +149,7 @@ proc listFrame(stream: File, f: PFrame) = | |
writeLine(stream, getLocal(f, i).name) | ||
write(stream, EndbEnd) | ||
|
||
proc listLocals(stream: File, f: PFrame) = | ||
proc listLocals(stream: CFileStar, f: PFrame) = | ||
write(stream, EndbBeg) | ||
write(stream, "| Frame (") | ||
write(stream, f.len) | ||
|
@@ -135,7 +158,7 @@ proc listLocals(stream: File, f: PFrame) = | |
writeVariable(stream, getLocal(f, i)) | ||
write(stream, EndbEnd) | ||
|
||
proc listGlobals(stream: File) = | ||
proc listGlobals(stream: CFileStar) = | ||
write(stream, EndbBeg) | ||
write(stream, "| Globals:\n") | ||
for i in 0 .. getGlobalLen()-1: | ||
|
@@ -145,10 +168,10 @@ proc listGlobals(stream: File) = | |
proc debugOut(msg: cstring) = | ||
# the *** *** markers are for easy recognition of debugger | ||
# output for external frontends. | ||
write(stdout, EndbBeg) | ||
write(stdout, "| ") | ||
write(stdout, msg) | ||
write(stdout, EndbEnd) | ||
write(cstdout, EndbBeg) | ||
write(cstdout, "| ") | ||
write(cstdout, msg) | ||
write(cstdout, EndbEnd) | ||
|
||
proc dbgFatal(msg: cstring) = | ||
debugOut(msg) | ||
|
@@ -157,20 +180,20 @@ proc dbgFatal(msg: cstring) = | |
|
||
proc dbgShowCurrentProc(dbgFramePointer: PFrame) = | ||
if dbgFramePointer != nil: | ||
write(stdout, "*** endb| now in proc: ") | ||
write(stdout, dbgFramePointer.procname) | ||
write(stdout, " ***\n") | ||
write(cstdout, "*** endb| now in proc: ") | ||
write(cstdout, dbgFramePointer.procname) | ||
write(cstdout, " ***\n") | ||
else: | ||
write(stdout, "*** endb| (proc name not available) ***\n") | ||
write(cstdout, "*** endb| (proc name not available) ***\n") | ||
|
||
proc dbgShowExecutionPoint() = | ||
write(stdout, "*** endb| ") | ||
write(stdout, framePtr.filename) | ||
write(stdout, "(") | ||
write(stdout, framePtr.line) | ||
write(stdout, ") ") | ||
write(stdout, framePtr.procname) | ||
write(stdout, " ***\n") | ||
write(cstdout, "*** endb| ") | ||
write(cstdout, framePtr.filename) | ||
write(cstdout, "(") | ||
write(cstdout, framePtr.line) | ||
write(cstdout, ") ") | ||
write(cstdout, framePtr.procname) | ||
write(cstdout, " ***\n") | ||
|
||
proc scanAndAppendWord(src: cstring, a: var StaticStr, start: int): int = | ||
result = start | ||
|
@@ -279,7 +302,7 @@ proc breakpointToggle(s: cstring, start: int) = | |
if not b.isNil: b.flip | ||
else: debugOut("[Warning] unknown breakpoint ") | ||
|
||
proc dbgEvaluate(stream: File, s: cstring, start: int, f: PFrame) = | ||
proc dbgEvaluate(stream: CFileStar, s: cstring, start: int, f: PFrame) = | ||
var dbgTemp: StaticStr | ||
var i = scanWord(s, dbgTemp, start) | ||
while s[i] in {' ', '\t'}: inc(i) | ||
|
@@ -315,8 +338,8 @@ proc dbgStackFrame(s: cstring, start: int, currFrame: PFrame) = | |
var dbgTemp: StaticStr | ||
var i = scanFilename(s, dbgTemp, start) | ||
if dbgTemp.len == 0: | ||
# just write it to stdout: | ||
listFrame(stdout, currFrame) | ||
# just write it to cstdout: | ||
listFrame(cstdout, currFrame) | ||
else: | ||
var stream = openAppend(addr dbgTemp.data) | ||
if stream == nil: | ||
|
@@ -325,7 +348,7 @@ proc dbgStackFrame(s: cstring, start: int, currFrame: PFrame) = | |
listFrame(stream, currFrame) | ||
close(stream) | ||
|
||
proc readLine(f: File, line: var StaticStr): bool = | ||
proc readLine(f: CFileStar, line: var StaticStr): bool = | ||
while true: | ||
var c = c_fgetc(f) | ||
if c < 0'i32: | ||
|
@@ -340,16 +363,16 @@ proc readLine(f: File, line: var StaticStr): bool = | |
result = true | ||
|
||
proc listFilenames() = | ||
write(stdout, EndbBeg) | ||
write(stdout, "| Files:\n") | ||
write(cstdout, EndbBeg) | ||
write(cstdout, "| Files:\n") | ||
var i = 0 | ||
while true: | ||
let x = dbgFilenames[i] | ||
if x.isNil: break | ||
write(stdout, x) | ||
write(stdout, "\n") | ||
write(cstdout, x) | ||
write(cstdout, "\n") | ||
inc i | ||
write(stdout, EndbEnd) | ||
write(cstdout, EndbEnd) | ||
|
||
proc dbgWriteStackTrace(f: PFrame) | ||
proc commandPrompt() = | ||
|
@@ -361,10 +384,10 @@ proc commandPrompt() = | |
dbgTemp: StaticStr | ||
|
||
while again: | ||
write(stdout, "*** endb| >>") | ||
write(cstdout, "*** endb| >>") | ||
let oldLen = dbgUser.len | ||
dbgUser.len = 0 | ||
if not readLine(stdin, dbgUser): break | ||
if not readLine(cstdin, dbgUser): break | ||
if dbgUser.len == 0: dbgUser.len = oldLen | ||
# now look what we have to do: | ||
var i = scanWord(addr dbgUser.data, dbgTemp, 0) | ||
|
@@ -398,7 +421,7 @@ proc commandPrompt() = | |
prevState = dbgState | ||
prevSkipFrame = dbgSkipToFrame | ||
dbgState = dbSkipCurrent | ||
dbgEvaluate(stdout, addr dbgUser.data, i, dbgFramePtr) | ||
dbgEvaluate(cstdout, addr dbgUser.data, i, dbgFramePtr) | ||
dbgState = prevState | ||
dbgSkipToFrame = prevSkipFrame | ||
elif ?"o" or ?"out": | ||
|
@@ -412,15 +435,15 @@ proc commandPrompt() = | |
prevState = dbgState | ||
prevSkipFrame = dbgSkipToFrame | ||
dbgState = dbSkipCurrent | ||
listLocals(stdout, dbgFramePtr) | ||
listLocals(cstdout, dbgFramePtr) | ||
dbgState = prevState | ||
dbgSkipToFrame = prevSkipFrame | ||
elif ?"g" or ?"globals": | ||
var | ||
prevState = dbgState | ||
prevSkipFrame = dbgSkipToFrame | ||
dbgState = dbSkipCurrent | ||
listGlobals(stdout) | ||
listGlobals(cstdout) | ||
dbgState = prevState | ||
dbgSkipToFrame = prevSkipFrame | ||
elif ?"u" or ?"up": | ||
|
@@ -501,29 +524,29 @@ proc dbgWriteStackTrace(f: PFrame) = | |
b = b.prev | ||
for j in countdown(i-1, 0): | ||
if tempFrames[j] == nil: | ||
write(stdout, "(") | ||
write(stdout, skipped) | ||
write(stdout, " calls omitted) ...") | ||
write(cstdout, "(") | ||
write(cstdout, skipped) | ||
write(cstdout, " calls omitted) ...") | ||
else: | ||
write(stdout, tempFrames[j].filename) | ||
write(cstdout, tempFrames[j].filename) | ||
if tempFrames[j].line > 0: | ||
write(stdout, '(') | ||
write(stdout, tempFrames[j].line) | ||
write(stdout, ')') | ||
write(stdout, ' ') | ||
write(stdout, tempFrames[j].procname) | ||
write(stdout, "\n") | ||
write(cstdout, "(") | ||
write(cstdout, tempFrames[j].line) | ||
write(cstdout, ")") | ||
write(cstdout, " ") | ||
write(cstdout, tempFrames[j].procname) | ||
write(cstdout, "\n") | ||
|
||
proc checkForBreakpoint = | ||
let b = checkBreakpoints(framePtr.filename, framePtr.line) | ||
if b != nil: | ||
write(stdout, "*** endb| reached ") | ||
write(stdout, framePtr.filename) | ||
write(stdout, "(") | ||
write(stdout, framePtr.line) | ||
write(stdout, ") ") | ||
write(stdout, framePtr.procname) | ||
write(stdout, " ***\n") | ||
write(cstdout, "*** endb| reached ") | ||
write(cstdout, framePtr.filename) | ||
write(cstdout, "(") | ||
write(cstdout, framePtr.line) | ||
write(cstdout, ") ") | ||
write(cstdout, framePtr.procname) | ||
write(cstdout, " ***\n") | ||
commandPrompt() | ||
|
||
proc lineHookImpl() {.nimcall.} = | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not
s/CFileStar/CFilePtr
? seems more readable and it follows the existing nim conventionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, will change it.