summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system')
-rw-r--r--lib/system/cgprocs.nim12
-rwxr-xr-xlib/system/dyncalls.nim40
-rwxr-xr-xlib/system/gc.nim29
-rwxr-xr-xlib/system/inclrtl.nim2
-rwxr-xr-xlib/system/mmdisp.nim10
5 files changed, 58 insertions, 35 deletions
diff --git a/lib/system/cgprocs.nim b/lib/system/cgprocs.nim
index 40aca033b..99f802910 100644
--- a/lib/system/cgprocs.nim
+++ b/lib/system/cgprocs.nim
@@ -11,4 +11,16 @@
 
 proc addChar(s: NimString, c: char): NimString {.compilerProc.}
 
+type
+  TLibHandle = pointer       # private type
+  TProcAddr = pointer        # libary loading and loading of procs:
+
+proc nimLoadLibrary(path: string): TLibHandle {.compilerproc.}
+proc nimUnloadLibrary(lib: TLibHandle) {.compilerproc.}
+proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr {.compilerproc.}
+
+proc nimLoadLibraryError(path: string) {.compilerproc, noinline.}
+
+proc setStackBottom(theStackBottom: pointer) {.compilerRtl.}
+
 
diff --git a/lib/system/dyncalls.nim b/lib/system/dyncalls.nim
index cb665c5cb..d7be3d6ef 100755
--- a/lib/system/dyncalls.nim
+++ b/lib/system/dyncalls.nim
@@ -12,24 +12,28 @@
 # However, the interface has been designed to take platform differences into
 # account and been ported to all major platforms.
 
-type
-  TLibHandle = pointer       # private type
-  TProcAddr = pointer        # libary loading and loading of procs:
-
 const
   NilLibHandle: TLibHandle = nil
 
-proc nimLoadLibrary(path: string): TLibHandle {.compilerproc.}
-proc nimUnloadLibrary(lib: TLibHandle) {.compilerproc.}
-proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr {.compilerproc.}
-
-proc nimLoadLibraryError(path: string) {.compilerproc, noinline.} =
-  when true:
-    # carefully written to avoid memory allocation:
-    stdout.write("could not load: ")
-    quit(path)
-  else:
-    raise newException(EInvalidLibrary, "could not load: " & path)
+proc rawWrite(f: TFile, s: string) = 
+  # we cannot throw an exception here!
+  discard writeBuffer(f, cstring(s), s.len)
+
+proc nimLoadLibraryError(path: string) =
+  # carefully written to avoid memory allocation:
+  #stdout.write("could not load: ")
+  #quit(path)
+  stdout.rawWrite("could not load: ")
+  stdout.rawWrite(path)
+  stdout.rawWrite("\n")
+  quit(1)
+
+proc ProcAddrError(name: cstring) {.noinline.} =
+  # carefully written to avoid memory allocation:
+  stdout.rawWrite("could not import: ")
+  stdout.write(name)
+  stdout.rawWrite("\n")
+  quit(1)
 
 # this code was inspired from Lua's source code:
 # Lua - An Extensible Extension Language
@@ -65,7 +69,7 @@ when defined(posix):
 
   proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr =
     result = dlsym(lib, name)
-    if result == nil: nimLoadLibraryError($name)
+    if result == nil: ProcAddrError(name)
 
 elif defined(windows) or defined(dos):
   #
@@ -90,7 +94,7 @@ elif defined(windows) or defined(dos):
 
   proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr =
     result = GetProcAddress(cast[THINSTANCE](lib), name)
-    if result == nil: nimLoadLibraryError($name)
+    if result == nil: ProcAddrError(name)
 
 elif defined(mac):
   #
@@ -126,7 +130,7 @@ elif defined(mac):
       nss: NSSymbol
     nss = NSLookupSymbolInModule(NSModule(lib), name)
     result = TProcAddr(NSAddressOfSymbol(nss))
-    if result == nil: nimLoadLibraryError($name)
+    if result == nil: ProcAddrError(name)
 
 else:
   {.error: "no implementation for dyncalls".}
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index f21f5bc01..d1a3e8273 100755
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -214,11 +214,6 @@ proc prepareDealloc(cell: PCell) =
     (cast[TFinalizer](cell.typ.finalizer))(cellToUsr(cell))
     dec(recGcLock)
 
-proc setStackBottom(theStackBottom: pointer) {.compilerRtl.} =
-  # the first init must be the one that defines the stack bottom:
-  if stackBottom == nil:
-    stackBottom = theStackBottom
-
 proc PossibleRoot(gch: var TGcHeap, c: PCell) {.inline.} =
   if canbeCycleRoot(c): incl(gch.cycleRoots, c)
 
@@ -367,7 +362,7 @@ proc newSeq(typ: PNimType, len: int): pointer =
   cast[PGenericSeq](result).len = len
   cast[PGenericSeq](result).space = len
 
-proc growObj(old: pointer, newsize: int): pointer =
+proc growObj(old: pointer, newsize: int): pointer {.rtl.} =
   checkCollection()
   var ol = usrToCell(old)
   assert(ol.typ != nil)
@@ -487,6 +482,25 @@ proc markThreadStacks(gch: var TGcHeap) =
 # ----------------- stack management --------------------------------------
 #  inspired from Smart Eiffel
 
+when defined(sparc):
+  const stackIncreases = false
+elif defined(hppa) or defined(hp9000) or defined(hp9000s300) or
+     defined(hp9000s700) or defined(hp9000s800) or defined(hp9000s820):
+  const stackIncreases = true
+else:
+  const stackIncreases = false
+
+proc setStackBottom(theStackBottom: pointer) =
+  # the first init must be the one that defines the stack bottom:
+  if stackBottom == nil: stackBottom = theStackBottom
+  else:
+    var a = cast[TAddress](theStackBottom)
+    var b = cast[TAddress](stackBottom)
+    when stackIncreases:
+      stackBottom = cast[pointer](min(a, b))
+    else:
+      stackBottom = cast[pointer](max(a, b))
+
 proc stackSize(): int {.noinline.} =
   var stackTop: array[0..1, pointer]
   result = abs(cast[int](addr(stackTop[0])) - cast[int](stackBottom))
@@ -518,8 +532,7 @@ when defined(sparc): # For SPARC architecture.
 elif defined(ELATE):
   {.error: "stack marking code is to be written for this architecture".}
 
-elif defined(hppa) or defined(hp9000) or defined(hp9000s300) or
-     defined(hp9000s700) or defined(hp9000s800) or defined(hp9000s820):
+elif stackIncreases:
   # ---------------------------------------------------------------------------
   # Generic code for architectures where addresses increase as the stack grows.
   # ---------------------------------------------------------------------------
diff --git a/lib/system/inclrtl.nim b/lib/system/inclrtl.nim
index 28965b4b1..3db6a77ca 100755
--- a/lib/system/inclrtl.nim
+++ b/lib/system/inclrtl.nim
@@ -21,7 +21,7 @@ when defined(createNimRtl):
   when defined(useNimRtl): 
     {.error: "Cannot create and use nimrtl at the same time!".}
   elif appType != "lib":
-    {.error: "nimrtl must be build as a library!".}
+    {.error: "nimrtl must be built as a library!".}
 
 when defined(createNimRtl): 
   # NOTE: compilerproc cannot make use of name mangling!
diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim
index ff61ea1fe..f0685c5c3 100755
--- a/lib/system/mmdisp.nim
+++ b/lib/system/mmdisp.nim
@@ -117,7 +117,7 @@ when defined(boehmgc):
   proc growObj(old: pointer, newsize: int): pointer =
     result = realloc(old, newsize)
 
-  proc setStackBottom(theStackBottom: pointer) {.compilerproc.} = nil
+  proc setStackBottom(theStackBottom: pointer) = nil
   proc nimGCref(p: pointer) {.compilerproc, inline.} = nil
   proc nimGCunref(p: pointer) {.compilerproc, inline.} = nil
   
@@ -175,7 +175,7 @@ elif defined(nogc):
   proc growObj(old: pointer, newsize: int): pointer =
     result = realloc(old, newsize)
 
-  proc setStackBottom(theStackBottom: pointer) {.compilerproc.} = nil
+  proc setStackBottom(theStackBottom: pointer) = nil
   proc nimGCref(p: pointer) {.compilerproc, inline.} = nil
   proc nimGCunref(p: pointer) {.compilerproc, inline.} = nil
   
@@ -194,12 +194,6 @@ elif defined(useNimRtl):
   proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.}
   proc growObj(old: pointer, newsize: int): pointer {.rtl.}
     
-  proc setStackBottom(theStackBottom: pointer) {.compilerProc, inline.} = 
-    # This happens before setStackBottom has been loaded by dlsym(), so
-    # we simply provide a dummy implemenation here for the code gen. No
-    # harm is done by this.
-    nil
-    
   proc nimGCref(p: pointer) {.compilerRtl.}
   proc nimGCunref(p: pointer) {.compilerRtl.}