summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-10-14 12:03:18 +0200
committerAraq <rumpf_a@web.de>2012-10-14 12:03:18 +0200
commitb800b77a1a9c746248488bec0ca40adffe565344 (patch)
tree02bb250b819af3978401a0c890dadc4f0e0e7073
parent6fd4b8350d4d5a1a9c45cc633151762945fa1e73 (diff)
parent4ef96a7435b9565e2c971eb2c93464dba223a34f (diff)
downloadNim-b800b77a1a9c746248488bec0ca40adffe565344.tar.gz
Merge branch 'master' of github.com:Araq/Nimrod
-rwxr-xr-xcompiler/ast.nim5
-rwxr-xr-xcompiler/semtypinst.nim4
-rwxr-xr-xcompiler/sigmatch.nim17
-rwxr-xr-xcompiler/transf.nim2
-rwxr-xr-xcompiler/types.nim6
-rw-r--r--lib/wrappers/opengl/opengl.nim120
6 files changed, 85 insertions, 69 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim
index 340a14888..83bd360f2 100755
--- a/compiler/ast.nim
+++ b/compiler/ast.nim
@@ -287,6 +287,11 @@ type
     tyGenericInvokation, # ``T[a, b]`` for types to invoke
     tyGenericBody,       # ``T[a, b, body]`` last parameter is the body
     tyGenericInst,       # ``T[a, b, realInstance]`` instantiated generic type
+                         # realInstance will be a concrete type like tyObject
+                         # unless this is an instance of a generic alias type.
+                         # then realInstance will be the tyGenericInst of the
+                         # completely (recursively) resolved alias.
+                         
     tyGenericParam,      # ``a`` in the above patterns
     tyDistinct,
     tyEnum,
diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim
index d51e24c89..e12640945 100755
--- a/compiler/semtypinst.nim
+++ b/compiler/semtypinst.nim
@@ -171,6 +171,10 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
     result.flags = result.flags + newbody.flags
     newbody.callConv = body.callConv
     newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
+    # This type may be a generic alias and we want to resolve it here.
+    # One step is enough, because the recursive nature of
+    # handleGenericInvokation will handle the alias-to-alias-to-alias case
+    if newbody.isGenericAlias: newbody = newbody.skipGenericAlias
     rawAddSon(result, newbody)
     checkPartialConstructedType(cl.info, newbody)
   else:
diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim
index 8968e4e03..f1920a255 100755
--- a/compiler/sigmatch.nim
+++ b/compiler/sigmatch.nim
@@ -476,22 +476,23 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
     let ff = lastSon(f)
     if ff != nil: result = typeRel(c, ff, a)
   of tyGenericInvokation:
+    var x = a.skipGenericAlias
     assert(f.sons[0].kind == tyGenericBody)
-    if a.kind == tyGenericInvokation: 
+    if x.kind == tyGenericInvokation:
       #InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
       # simply no match for now:
       nil
-    elif a.kind == tyGenericInst and 
-          (f.sons[0].containerID == a.sons[0].containerID) and
-          (sonsLen(a) - 1 == sonsLen(f)): 
-      assert(a.sons[0].kind == tyGenericBody)
+    elif x.kind == tyGenericInst and 
+          (f.sons[0].containerID == x.sons[0].containerID) and
+          (sonsLen(x) - 1 == sonsLen(f)): 
+      assert(x.sons[0].kind == tyGenericBody)
       for i in countup(1, sonsLen(f) - 1): 
-        if a.sons[i].kind == tyGenericParam: 
+        if x.sons[i].kind == tyGenericParam: 
           InternalError("wrong instantiated type!")
-        elif typeRel(c, f.sons[i], a.sons[i]) <= isSubtype: return 
+        elif typeRel(c, f.sons[i], x.sons[i]) <= isSubtype: return 
       result = isGeneric
     else:
-      result = typeRel(c, f.sons[0], a)
+      result = typeRel(c, f.sons[0], x)
       if result != isNone:
         # we steal the generic parameters from the tyGenericBody:
         for i in countup(1, sonsLen(f) - 1):
diff --git a/compiler/transf.nim b/compiler/transf.nim
index 170f8ff0f..d1ee76cf1 100755
--- a/compiler/transf.nim
+++ b/compiler/transf.nim
@@ -603,7 +603,7 @@ proc transform(c: PTransf, n: PNode): PTransNode =
     dec c.inLoop
   of nkCaseStmt: result = transformCase(c, n)
   of nkContinueStmt:
-    result = PTransNode(newNode(nkBreakStmt))
+    result = PTransNode(newNodeI(nkBreakStmt, n.info))
     var labl = c.contSyms[c.contSyms.high]
     add(result, PTransNode(newSymNode(labl)))
   of nkBreakStmt: result = transformBreak(c, n)
diff --git a/compiler/types.nim b/compiler/types.nim
index e02d93233..90fffff40 100755
--- a/compiler/types.nim
+++ b/compiler/types.nim
@@ -905,6 +905,12 @@ proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]],
     a = a.sons[i]
   result = a.kind == last
 
+proc isGenericAlias*(t: PType): bool =
+  return t.kind == tyGenericInst and t.lastSon.kind == tyGenericInst
+
+proc skipGenericAlias*(t: PType): PType =
+  return if t.isGenericAlias: t.lastSon else: t
+
 proc matchTypeClass*(bindings: var TIdTable, typeClass, t: PType): bool =
   for i in countup(0, typeClass.sonsLen - 1):
     let req = typeClass.sons[i]
diff --git a/lib/wrappers/opengl/opengl.nim b/lib/wrappers/opengl/opengl.nim
index fab8183f5..a61159016 100644
--- a/lib/wrappers/opengl/opengl.nim
+++ b/lib/wrappers/opengl/opengl.nim
@@ -8,13 +8,13 @@
 #

 

 ## This module is a wrapper around `opengl`:idx:. If you define the symbol

-## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism, 
-## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
-## extension loading for the different operating systems is handled here.
-##
-## You need to call ``loadExtensions`` after a rendering context has been
+## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism, 

+## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even

+## extension loading for the different operating systems is handled here.

+##

+## You need to call ``loadExtensions`` after a rendering context has been

 ## created to load any extension proc that your code uses.

-
+

 when defined(linux):

   import X, XLib, XUtil

 elif defined(windows):

@@ -39,58 +39,58 @@ when defined(useGlew):
   {.pragma: wgl, header: "<GL/wglew.h>".}

   {.pragma: glu, dynlib: gludll.}

 else:

-  # quite complex ... thanks to extension support for various platforms:
-  import dynlib
-  
-  let oglHandle = LoadLib(ogldll)
-  if isNil(oglHandle): quit("could not load: " & ogldll)
-  
-  when defined(windows):
-    var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](
-      symAddr(oglHandle, "wglGetProcAddress"))
-  elif defined(linux):
-    var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](
-      symAddr(oglHandle, "glXGetProcAddress"))
-    var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](
-      symAddr(oglHandle, "glXGetProcAddressARB"))
-
-  proc glGetProc(h: TLibHandle; procName: cstring): pointer =
-    when defined(windows):
-      result = symAddr(h, procname)
-      if result != nil: return
-      if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)
-    elif defined(linux):
-      if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)
-      if result != nil: return 
-      if not isNil(glXGetProcAddressARB): 
-        result = glXGetProcAddressARB(ProcName)
-        if result != nil: return
-      result = symAddr(h, procname)
-    else:
-      result = symAddr(h, procName)
-    if result == nil: raiseInvalidLibrary(procName)
-
-  var gluHandle: TLibHandle
-  
-  proc gluGetProc(procname: cstring): pointer =
-    if gluHandle == nil:
-      gluHandle = LoadLib(gludll)
-      if gluHandle == nil: quit("could not load: " & gludll)
-    result = glGetProc(gluHandle, procname)
-  
-  # undocumented 'dynlib' feature: the string literal is replaced by
-  # the imported proc name:
-  {.pragma: ogl, dynlib: glGetProc(oglHandle, "").}

+  # quite complex ... thanks to extension support for various platforms:

+  import dynlib

+  

+  let oglHandle = LoadLib(ogldll)

+  if isNil(oglHandle): quit("could not load: " & ogldll)

+  

+  when defined(windows):

+    var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](

+      symAddr(oglHandle, "wglGetProcAddress"))

+  elif defined(linux):

+    var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](

+      symAddr(oglHandle, "glXGetProcAddress"))

+    var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](

+      symAddr(oglHandle, "glXGetProcAddressARB"))

+

+  proc glGetProc(h: TLibHandle; procName: cstring): pointer =

+    when defined(windows):

+      result = symAddr(h, procname)

+      if result != nil: return

+      if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)

+    elif defined(linux):

+      if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)

+      if result != nil: return 

+      if not isNil(glXGetProcAddressARB): 

+        result = glXGetProcAddressARB(ProcName)

+        if result != nil: return

+      result = symAddr(h, procname)

+    else:

+      result = symAddr(h, procName)

+    if result == nil: raiseInvalidLibrary(procName)

+

+  var gluHandle: TLibHandle

+  

+  proc gluGetProc(procname: cstring): pointer =

+    if gluHandle == nil:

+      gluHandle = LoadLib(gludll)

+      if gluHandle == nil: quit("could not load: " & gludll)

+    result = glGetProc(gluHandle, procname)

+  

+  # undocumented 'dynlib' feature: the string literal is replaced by

+  # the imported proc name:

+  {.pragma: ogl, dynlib: glGetProc(oglHandle, "0").}

   {.pragma: oglx, dynlib: glGetProc(oglHandle, "0").}

-  {.pragma: wgl, dynlib: glGetProc(oglHandle, "").}

-  {.pragma: glu, dynlib: gluGetProc("").}
-  
-  proc nimLoadProcs0() {.importc.}
-  
-  template loadExtensions*() =
-    ## call this after your rendering context has been setup if you use
-    ## extensions.
-    bind nimLoadProcs0
+  {.pragma: wgl, dynlib: glGetProc(oglHandle, "0").}

+  {.pragma: glu, dynlib: gluGetProc("").}

+  

+  proc nimLoadProcs0() {.importc.}

+  

+  template loadExtensions*() =

+    ## call this after your rendering context has been setup if you use

+    ## extensions.

+    bind nimLoadProcs0

     nimLoadProcs0()

 

 #==============================================================================

@@ -9104,7 +9104,7 @@ proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN*(rc: GLuint,
 proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint, 

     tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.}

   # window support functions

-when defined(windows): 
+when defined(windows): 

   when not defined(wglGetProcAddress):

     proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.}

   proc wglCopyContext*(p1: HGLRC, p2: HGLRC, p3: int): BOOL{.stdcall, importc, wgl.}

@@ -9446,11 +9446,11 @@ when defined(LINUX):
       stdcall, importc, oglx.}

   proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable, 

                             event_mask: PGLuint){.stdcall, importc, oglx.}

-    # GLX_VERSION_1_4
+    # GLX_VERSION_1_4

   when not defined(glXGetProcAddress):

     proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}

     # GLX_ARB_get_proc_address

-  when not defined(glXGetProcAddressARB):
+  when not defined(glXGetProcAddressARB):

     proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}

     # GLX_ARB_create_context

   proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig,