summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-07-16 08:11:37 +0200
committerAraq <rumpf_a@web.de>2012-07-16 08:11:37 +0200
commit4215686cce1aaebd4021c856d504103f7e9a9586 (patch)
tree1ef722361e3d539fcd5046c04b6c3516fdf4ade0
parent089e7db08a8088ac6ed885fbdb4ee215033bbbf3 (diff)
downloadNim-4215686cce1aaebd4021c856d504103f7e9a9586.tar.gz
x11 example compiles again; updated python wrapper; compiler supports variables in DLLs
-rwxr-xr-xcompiler/cgen.nim27
-rwxr-xr-xdoc/manual.txt2
-rwxr-xr-xexamples/pythonex.nim1
-rwxr-xr-xexamples/x11ex.nim10
-rwxr-xr-xlib/wrappers/python.nim30
-rwxr-xr-xtodo.txt1
-rwxr-xr-xweb/news.txt1
7 files changed, 51 insertions, 21 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim
index e437cbb66..2c2230be9 100755
--- a/compiler/cgen.nim
+++ b/compiler/cgen.nim
@@ -418,9 +418,20 @@ proc assignLocalVar(p: BProc, s: PSym) =
 
 include ccgthreadvars
 
+proc VarInDynamicLib(m: BModule, sym: PSym)
+proc mangleDynLibProc(sym: PSym): PRope
+
 proc assignGlobalVar(p: BProc, s: PSym) = 
   if s.loc.k == locNone: 
     fillLoc(s.loc, locGlobalVar, s.typ, mangleName(s), OnHeap)
+  
+  if lfDynamicLib in s.loc.flags:
+    var q = findPendingModule(p.module, s)
+    if q != nil and not ContainsOrIncl(q.declaredThings, s.id): 
+      VarInDynamicLib(q, s)
+    else:
+      s.loc.r = mangleDynLibProc(s)
+    return
   useHeader(p.module, s)
   if lfNoDecl in s.loc.flags: return
   if sfThread in s.flags: 
@@ -537,6 +548,21 @@ proc SymInDynamicLib(m: BModule, sym: PSym) =
       "$1 = linkonce global $2 zeroinitializer$n", 
       [sym.loc.r, getTypeDesc(m, sym.loc.t)])
 
+proc VarInDynamicLib(m: BModule, sym: PSym) = 
+  var lib = sym.annex
+  var extname = sym.loc.r
+  loadDynamicLib(m, lib)
+  incl(sym.loc.flags, lfIndirect)
+  var tmp = mangleDynLibProc(sym)
+  sym.loc.r = tmp             # from now on we only need the internal name
+  inc(m.labels, 2)
+  appcg(m, m.s[cfsDynLibInit], 
+      "$1 = ($2*) #nimGetProcAddr($3, $4);$n", 
+      [tmp, getTypeDesc(m, sym.typ), 
+      lib.name, cstringLit(m, m.s[cfsDynLibInit], ropeToStr(extname))])
+  appf(m.s[cfsVars], "$2* $1;$n",
+      [sym.loc.r, getTypeDesc(m, sym.loc.t)])
+
 proc SymInDynamicLibPartial(m: BModule, sym: PSym) =
   sym.loc.r = mangleDynLibProc(sym)
   sym.typ.sym = nil           # generate a new name
@@ -751,6 +777,7 @@ proc genVarPrototype(m: BModule, sym: PSym) =
     else:
       app(m.s[cfsVars], "extern ")
       app(m.s[cfsVars], getTypeDesc(m, sym.loc.t))
+      if lfDynamicLib in sym.loc.flags: app(m.s[cfsVars], "*")
       if sfRegister in sym.flags: app(m.s[cfsVars], " register")
       if sfVolatile in sym.flags: app(m.s[cfsVars], " volatile")
       appf(m.s[cfsVars], " $1;$n", [sym.loc.r])
diff --git a/doc/manual.txt b/doc/manual.txt
index 543d5d3c1..31b2b6585 100755
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -3589,7 +3589,7 @@ strings automatically:
 

 Dynlib pragma for import

 ------------------------

-With the `dynlib`:idx: pragma a procedure can be imported from

+With the `dynlib`:idx: pragma a procedure or a variable can be imported from

 a dynamic library (``.dll`` files for Windows, ``lib*.so`` files for UNIX). 
 The non-optional argument has to be the name of the dynamic library:

 

diff --git a/examples/pythonex.nim b/examples/pythonex.nim
index e2664f350..310d80151 100755
--- a/examples/pythonex.nim
+++ b/examples/pythonex.nim
@@ -9,4 +9,3 @@ Py_Initialize()
 discard PyRun_SimpleString("from time import time,ctime\L" &
                            "print 'Today is',ctime(time())\L")
 Py_Finalize()
-
diff --git a/examples/x11ex.nim b/examples/x11ex.nim
index a32094be4..eb4ae9274 100755
--- a/examples/x11ex.nim
+++ b/examples/x11ex.nim
@@ -5,7 +5,7 @@ const
   WINDOW_HEIGHT = 300
   
 var
-  width, height: cint
+  width, height: cuint
   display: PDisplay
   screen: cint
   depth: int
@@ -29,10 +29,10 @@ proc create_window =
                             XBlackPixel(display, screen),
                             XWhitePixel(display, screen))
   size_hints.flags = PSize or PMinSize or PMaxSize
-  size_hints.min_width =  width
-  size_hints.max_width =  width
-  size_hints.min_height = height
-  size_hints.max_height = height
+  size_hints.min_width =  width.cint
+  size_hints.max_width =  width.cint
+  size_hints.min_height = height.cint
+  size_hints.max_height = height.cint
   discard XSetStandardProperties(display, win, "Simple Window", "window",
                          0, nil, 0, addr(size_hints))
   discard XSelectInput(display, win, ButtonPressMask or KeyPressMask or 
diff --git a/lib/wrappers/python.nim b/lib/wrappers/python.nim
index 0801b1ae5..3c5fd46db 100755
--- a/lib/wrappers/python.nim
+++ b/lib/wrappers/python.nim
@@ -60,12 +60,14 @@ import
 
 
 when defined(windows): 
-  const dllname = "python(26|25|24|23|22|21|20|16|15).dll"
+  const dllname = "python(27|26|25|24|23|22|21|20|16|15).dll"
 elif defined(macosx):
-  const dllname = "libpython(2.6|2.5|2.4|2.3|2.2|2.1|2.0|1.6|1.5).dylib"
+  const dllname = "libpython(2.7|2.6|2.5|2.4|2.3|2.2|2.1|2.0|1.6|1.5).dylib"
 else: 
   const dllver = ".1"
-  const dllname = "libpython(2.6|2.5|2.4|2.3|2.2|2.1|2.0|1.6|1.5).so" & dllver
+  const dllname = "libpython(2.7|2.6|2.5|2.4|2.3|2.2|2.1|2.0|1.6|1.5).so" & 
+                  dllver
+
   
 const 
   PYT_METHOD_BUFFER_INCREASE* = 10
@@ -1545,26 +1547,28 @@ proc init(lib: TLibHandle) =
   PyEnum_Type = cast[PPyTypeObject](symAddr(lib, "PyEnum_Type"))
 
 # Unfortunately we have to duplicate the loading mechanism here, because Nimrod
-# does not support variables from dynamic libraries. Well designed API's don't
-# require this anyway. Python is an exception.
+# used to not support variables from dynamic libraries. Well designed API's
+# don't require this anyway. Python is an exception.
 
 var
   lib: TLibHandle
 
-when defined(windows): 
+when defined(windows):
   const
-    LibNames = ["python26.dll", "python25.dll", 
-      "python24.dll", "python23.dll", "python22.dll", "python21.dll", 
+    LibNames = ["python27.dll", "python26.dll", "python25.dll",
+      "python24.dll", "python23.dll", "python22.dll", "python21.dll",
       "python20.dll", "python16.dll", "python15.dll"]
 elif defined(macosx):
   const
-    LibNames = ["libpython2.6.dylib", "libpython2.5.dylib", 
-      "libpython2.4.dylib", "libpython2.3.dylib", "libpython2.2.dylib", 
-      "libpython2.1.dylib", "libpython2.0.dylib",
+    LibNames = ["libpython2.7.dylib", "libpython2.6.dylib",
+      "libpython2.5.dylib", "libpython2.4.dylib", "libpython2.3.dylib", 
+      "libpython2.2.dylib", "libpython2.1.dylib", "libpython2.0.dylib",
       "libpython1.6.dylib", "libpython1.5.dylib"]
-else: 
+else:
   const
-    LibNames = ["libpython2.6.so" & dllver, 
+    LibNames = [
+      "libpython2.7.so" & dllver,
+      "libpython2.6.so" & dllver, 
       "libpython2.5.so" & dllver, 
       "libpython2.4.so" & dllver, 
       "libpython2.3.so" & dllver, 
diff --git a/todo.txt b/todo.txt
index 751f8413d..afa90cc70 100755
--- a/todo.txt
+++ b/todo.txt
@@ -1,7 +1,6 @@
 version 0.9.0
 =============
 
-- implement ``dynlib`` for variables
 - implicit deref for parameter matching
 - deprecate ``var x, y = 0`` as it's confusing for tuple consistency
 - test sequence of closures; especially that the GC does not leak for those!
diff --git a/web/news.txt b/web/news.txt
index be9e5bf08..df81b952c 100755
--- a/web/news.txt
+++ b/web/news.txt
@@ -112,6 +112,7 @@ Compiler Additions
   via the ``doc2`` command. This new generator uses all of the semantic passes
   of the compiler and can thus generate documentation for symbols hiding in
   macros.
+- The compiler now supports the ``dynlib`` pragma for variables.
 
 
 Language Additions