moderate system cleanup & refactor (#20355)

* system refactor, move out 600 lines

* compilation, slice, backwardsindex, misc_num moved out of system
* some procs/types moved into arithmetics, basic_types
* system no longer depends on syncio
* some procs moved around to fit with their surroundings

* make exceptions an import, old ops to misc_num

* move instantiationInfo back

* move back nim version, fix windows echo

* include compilation

* better docs for imported modules, fix unsigned ops

also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem

* fix terminal

* workaround IC test & weird csize bug, changelog

* move NimMajor etc back to compilation, rebase for CI

* try ic fix

* form single `indices`, slim out TaintedString, try fix IC

* fix CI, update changelog, addQuitProc

* fix CI

* try fix CI

* actually fix CI finally hopefully

* Update lib/system/compilation.nim

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>

* update kochdocs

* hopefully fix csize uses for slimsystem

* fix tquit

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
This commit is contained in:
metagn 2022-09-28 22:28:45 +03:00 • committed by GitHub
commit 919a889ba8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
37 changed files with 1167 additions and 1102 deletions

View file

@ -39,6 +39,13 @@ type
FileHandle* = cint ## type that represents an OS file handle; this is
## useful for low-level file access
FileSeekPos* = enum ## Position relative to which seek should happen.
# The values are ordered so that they match with stdio
# SEEK_SET, SEEK_CUR and SEEK_END respectively.
fspSet ## Seek to absolute value
fspCur ## Seek relative to current position
fspEnd ## Seek relative to end
# text file handling:
when not defined(nimscript) and not defined(js):
# duplicated between io and ansi_c
@ -142,13 +149,6 @@ proc c_fprintf(f: File, frmt: cstring): cint {.
proc c_fputc(c: char, f: File): cint {.
importc: "fputc", header: "<stdio.h>".}
# When running nim in android app, stdout goes nowhere, so echo gets ignored
# To redirect echo to the android logcat, use -d:androidNDK
when defined(androidNDK):
const ANDROID_LOG_VERBOSE = 2.cint
proc android_log_print(prio: cint, tag: cstring, fmt: cstring): cint
{.importc: "__android_log_print", header: "<android/log.h>", varargs, discardable.}
template sysFatal(exc, msg) =
raise newException(exc, msg)
@ -791,52 +791,6 @@ proc setStdIoUnbuffered*() {.tags: [], benign.} =
when declared(stdin):
discard c_setvbuf(stdin, nil, IONBF, 0)
when declared(stdout):
when defined(windows) and compileOption("threads"):
proc addSysExitProc(quitProc: proc() {.noconv.}) {.importc: "atexit", header: "<stdlib.h>".}
const insideRLocksModule = false
include "system/syslocks"
var echoLock: SysLock
initSysLock echoLock
addSysExitProc(proc() {.noconv.} = deinitSys(echoLock))
const stdOutLock = not defined(windows) and
not defined(android) and
not defined(nintendoswitch) and
not defined(freertos) and
not defined(zephyr) and
hostOS != "any"
proc echoBinSafe(args: openArray[string]) {.compilerproc.} =
when defined(androidNDK):
var s = ""
for arg in args:
s.add arg
android_log_print(ANDROID_LOG_VERBOSE, "nim", s)
else:
# flockfile deadlocks some versions of Android 5.x.x
when stdOutLock:
proc flockfile(f: File) {.importc, nodecl.}
proc funlockfile(f: File) {.importc, nodecl.}
flockfile(stdout)
when defined(windows) and compileOption("threads"):
acquireSys echoLock
for s in args:
when defined(windows):
writeWindows(stdout, s)
else:
discard c_fwrite(s.cstring, cast[csize_t](s.len), 1, stdout)
const linefeed = "\n"
discard c_fwrite(linefeed.cstring, linefeed.len, 1, stdout)
discard c_fflush(stdout)
when stdOutLock:
funlockfile(stdout)
when defined(windows) and compileOption("threads"):
releaseSys echoLock
when defined(windows) and not defined(nimscript) and not defined(js):
# work-around C's sucking abstraction:
@ -960,3 +914,7 @@ iterator lines*(f: File): string {.tags: [ReadIOEffect].} =
result.lines += 1
var res = newStringOfCap(80)
while f.readLine(res): yield res
template `&=`*(f: File, x: typed) =
## An alias for `write`.
write(f, x)