summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <andreas@andreas-desktop>2010-08-04 07:57:51 +0200
committerAndreas Rumpf <andreas@andreas-desktop>2010-08-04 07:57:51 +0200
commitc9e011e36cf400e1a2e5466a1339f716623508f7 (patch)
tree6cad2aa1896296098f4625930e5bb3de032a861e /lib
parent03724c2952e4eea4d9e16f5b4eccec862a1ba21c (diff)
downloadNim-c9e011e36cf400e1a2e5466a1339f716623508f7.tar.gz
DLL generation of the stdlib for unix
Diffstat (limited to 'lib')
-rwxr-xr-xlib/nimbase.h2
-rwxr-xr-xlib/nimrtl.cfg5
-rwxr-xr-xlib/system.nim104
-rwxr-xr-x[-rw-r--r--]lib/system/cgprocs.nim2
-rwxr-xr-xlib/system/gc.nim3
5 files changed, 64 insertions, 52 deletions
diff --git a/lib/nimbase.h b/lib/nimbase.h
index 8e80b8261..5bc644dc9 100755
--- a/lib/nimbase.h
+++ b/lib/nimbase.h
@@ -431,4 +431,6 @@ struct NimException {
 };
 #endif
 
+#define NIM_POSIX_INIT  __attribute__((constructor)) 
+
 #endif
diff --git a/lib/nimrtl.cfg b/lib/nimrtl.cfg
new file mode 100755
index 000000000..b60de183a
--- /dev/null
+++ b/lib/nimrtl.cfg
@@ -0,0 +1,5 @@
+# The RTL.dll needs to be compiled with these options!
+
+--app:lib
+--define:createNimRtl
+
diff --git a/lib/system.nim b/lib/system.nim
index abad660f1..1addece93 100755
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -666,6 +666,56 @@ proc `&` * (x: char, y: string): string {.
 
 proc add*(x: var string, y: char) {.magic: "AppendStrCh", noSideEffect.}
 proc add*(x: var string, y: string) {.magic: "AppendStrStr", noSideEffect.}
+
+type
+  TEndian* = enum ## is a type describing the endianness of a processor.
+    littleEndian, bigEndian
+
+const
+  isMainModule* {.magic: "IsMainModule".}: bool = false
+    ## is true only when accessed in the main module. This works thanks to
+    ## compiler magic. It is useful to embed testing code in a module.
+
+  CompileDate* {.magic: "CompileDate"}: string = "0000-00-00"
+    ## is the date of compilation as a string of the form
+    ## ``YYYY-MM-DD``. This works thanks to compiler magic.
+
+  CompileTime* {.magic: "CompileTime"}: string = "00:00:00"
+    ## is the time of compilation as a string of the form
+    ## ``HH:MM:SS``. This works thanks to compiler magic.
+
+  NimrodVersion* {.magic: "NimrodVersion"}: string = "0.0.0"
+    ## is the version of Nimrod as a string.
+    ## This works thanks to compiler magic.
+
+  NimrodMajor* {.magic: "NimrodMajor"}: int = 0
+    ## is the major number of Nimrod's version.
+    ## This works thanks to compiler magic.
+
+  NimrodMinor* {.magic: "NimrodMinor"}: int = 0
+    ## is the minor number of Nimrod's version.
+    ## This works thanks to compiler magic.
+
+  NimrodPatch* {.magic: "NimrodPatch"}: int = 0
+    ## is the patch number of Nimrod's version.
+    ## This works thanks to compiler magic.
+
+  cpuEndian* {.magic: "CpuEndian"}: TEndian = littleEndian
+    ## is the endianness of the target CPU. This is a valuable piece of
+    ## information for low-level code only. This works thanks to compiler magic.
+    
+  hostOS* {.magic: "HostOS"}: string = ""
+    ## a string that describes the host operating system. Possible values:
+    ## "windows", "macosx", "linux", "netbsd", "freebsd", "openbsd", "solaris",
+    ## "aix".
+        
+  hostCPU* {.magic: "HostCPU"}: string = ""
+    ## a string that describes the host CPU. Possible values:
+    ## "i386", "alpha", "powerpc", "sparc", "amd64", "mips", "arm".
+  
+  appType* {.magic: "AppType"}: string = ""
+    ## a string that describes the application type. Possible values:
+    ## "console", "gui", "lib".
   
 include "system/inclrtl"
 include "system/cgprocs"
@@ -771,59 +821,10 @@ type # these work for most platforms:
     ## high value is large enough to disable bounds checking in practice.
     ## Use `cstringArrayToSeq` to convert it into a ``seq[string]``.
 
-  TEndian* = enum ## is a type describing the endianness of a processor.
-    littleEndian, bigEndian
-
   PFloat32* = ptr Float32 ## an alias for ``ptr float32``
   PFloat64* = ptr Float64 ## an alias for ``ptr float64``
   PInt64* = ptr Int64 ## an alias for ``ptr int64``
   PInt32* = ptr Int32 ## an alias for ``ptr int32``
-
-const
-  isMainModule* {.magic: "IsMainModule".}: bool = false
-    ## is true only when accessed in the main module. This works thanks to
-    ## compiler magic. It is useful to embed testing code in a module.
-
-  CompileDate* {.magic: "CompileDate"}: string = "0000-00-00"
-    ## is the date of compilation as a string of the form
-    ## ``YYYY-MM-DD``. This works thanks to compiler magic.
-
-  CompileTime* {.magic: "CompileTime"}: string = "00:00:00"
-    ## is the time of compilation as a string of the form
-    ## ``HH:MM:SS``. This works thanks to compiler magic.
-
-  NimrodVersion* {.magic: "NimrodVersion"}: string = "0.0.0"
-    ## is the version of Nimrod as a string.
-    ## This works thanks to compiler magic.
-
-  NimrodMajor* {.magic: "NimrodMajor"}: int = 0
-    ## is the major number of Nimrod's version.
-    ## This works thanks to compiler magic.
-
-  NimrodMinor* {.magic: "NimrodMinor"}: int = 0
-    ## is the minor number of Nimrod's version.
-    ## This works thanks to compiler magic.
-
-  NimrodPatch* {.magic: "NimrodPatch"}: int = 0
-    ## is the patch number of Nimrod's version.
-    ## This works thanks to compiler magic.
-
-  cpuEndian* {.magic: "CpuEndian"}: TEndian = littleEndian
-    ## is the endianness of the target CPU. This is a valuable piece of
-    ## information for low-level code only. This works thanks to compiler magic.
-    
-  hostOS* {.magic: "HostOS"}: string = ""
-    ## a string that describes the host operating system. Possible values:
-    ## "windows", "macosx", "linux", "netbsd", "freebsd", "openbsd", "solaris",
-    ## "aix".
-        
-  hostCPU* {.magic: "HostCPU"}: string = ""
-    ## a string that describes the host CPU. Possible values:
-    ## "i386", "alpha", "powerpc", "sparc", "amd64", "mips", "arm".
-  
-  appType* {.magic: "AppType"}: string = ""
-    ## a string that describes the application type. Possible values:
-    ## "console", "gui", "lib".
   
 proc toFloat*(i: int): float {.
   magic: "ToFloat", noSideEffect, importc: "toFloat".}
@@ -1305,7 +1306,10 @@ when not defined(EcmaScript) and not defined(NimrodVM):
   proc initGC()
 
   proc initStackBottom() {.inline.} = 
-    var locals: array[0..7, int]
+    # WARNING: This is very fragile! An array size of 8 does not work on my
+    # Linux 64bit system. Very strange, but we are at the will of GCC's 
+    # optimizer...
+    var locals {.volatile.}: pointer
     setStackBottom(addr(locals))
 
   var
diff --git a/lib/system/cgprocs.nim b/lib/system/cgprocs.nim
index 99f802910..cabdcafc4 100644..100755
--- a/lib/system/cgprocs.nim
+++ b/lib/system/cgprocs.nim
@@ -21,6 +21,6 @@ proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr {.compilerproc.}
 
 proc nimLoadLibraryError(path: string) {.compilerproc, noinline.}
 
-proc setStackBottom(theStackBottom: pointer) {.compilerRtl.}
+proc setStackBottom(theStackBottom: pointer) {.compilerRtl, noinline.}
 
 
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index d1a3e8273..2ad22d8b6 100755
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -491,10 +491,11 @@ else:
   const stackIncreases = false
 
 proc setStackBottom(theStackBottom: pointer) =
+  #c_fprintf(c_stdout, "stack bottom: %p;\n", theStackBottom)
   # the first init must be the one that defines the stack bottom:
   if stackBottom == nil: stackBottom = theStackBottom
   else:
-    var a = cast[TAddress](theStackBottom)
+    var a = cast[TAddress](theStackBottom) # and not PageMask - PageSize*2
     var b = cast[TAddress](stackBottom)
     when stackIncreases:
       stackBottom = cast[pointer](min(a, b))