Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
commit
b800b77a1a
6 changed files with 85 additions and 69 deletions
|
|
@ -287,6 +287,11 @@ type
|
||||||
tyGenericInvokation, # ``T[a, b]`` for types to invoke
|
tyGenericInvokation, # ``T[a, b]`` for types to invoke
|
||||||
tyGenericBody, # ``T[a, b, body]`` last parameter is the body
|
tyGenericBody, # ``T[a, b, body]`` last parameter is the body
|
||||||
tyGenericInst, # ``T[a, b, realInstance]`` instantiated generic type
|
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
|
tyGenericParam, # ``a`` in the above patterns
|
||||||
tyDistinct,
|
tyDistinct,
|
||||||
tyEnum,
|
tyEnum,
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,10 @@ proc handleGenericInvokation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result.flags = result.flags + newbody.flags
|
result.flags = result.flags + newbody.flags
|
||||||
newbody.callConv = body.callConv
|
newbody.callConv = body.callConv
|
||||||
newbody.n = ReplaceTypeVarsN(cl, lastSon(body).n)
|
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)
|
rawAddSon(result, newbody)
|
||||||
checkPartialConstructedType(cl.info, newbody)
|
checkPartialConstructedType(cl.info, newbody)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -476,22 +476,23 @@ proc typeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
let ff = lastSon(f)
|
let ff = lastSon(f)
|
||||||
if ff != nil: result = typeRel(c, ff, a)
|
if ff != nil: result = typeRel(c, ff, a)
|
||||||
of tyGenericInvokation:
|
of tyGenericInvokation:
|
||||||
|
var x = a.skipGenericAlias
|
||||||
assert(f.sons[0].kind == tyGenericBody)
|
assert(f.sons[0].kind == tyGenericBody)
|
||||||
if a.kind == tyGenericInvokation:
|
if x.kind == tyGenericInvokation:
|
||||||
#InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
|
#InternalError("typeRel: tyGenericInvokation -> tyGenericInvokation")
|
||||||
# simply no match for now:
|
# simply no match for now:
|
||||||
nil
|
nil
|
||||||
elif a.kind == tyGenericInst and
|
elif x.kind == tyGenericInst and
|
||||||
(f.sons[0].containerID == a.sons[0].containerID) and
|
(f.sons[0].containerID == x.sons[0].containerID) and
|
||||||
(sonsLen(a) - 1 == sonsLen(f)):
|
(sonsLen(x) - 1 == sonsLen(f)):
|
||||||
assert(a.sons[0].kind == tyGenericBody)
|
assert(x.sons[0].kind == tyGenericBody)
|
||||||
for i in countup(1, sonsLen(f) - 1):
|
for i in countup(1, sonsLen(f) - 1):
|
||||||
if a.sons[i].kind == tyGenericParam:
|
if x.sons[i].kind == tyGenericParam:
|
||||||
InternalError("wrong instantiated type!")
|
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
|
result = isGeneric
|
||||||
else:
|
else:
|
||||||
result = typeRel(c, f.sons[0], a)
|
result = typeRel(c, f.sons[0], x)
|
||||||
if result != isNone:
|
if result != isNone:
|
||||||
# we steal the generic parameters from the tyGenericBody:
|
# we steal the generic parameters from the tyGenericBody:
|
||||||
for i in countup(1, sonsLen(f) - 1):
|
for i in countup(1, sonsLen(f) - 1):
|
||||||
|
|
|
||||||
|
|
@ -603,7 +603,7 @@ proc transform(c: PTransf, n: PNode): PTransNode =
|
||||||
dec c.inLoop
|
dec c.inLoop
|
||||||
of nkCaseStmt: result = transformCase(c, n)
|
of nkCaseStmt: result = transformCase(c, n)
|
||||||
of nkContinueStmt:
|
of nkContinueStmt:
|
||||||
result = PTransNode(newNode(nkBreakStmt))
|
result = PTransNode(newNodeI(nkBreakStmt, n.info))
|
||||||
var labl = c.contSyms[c.contSyms.high]
|
var labl = c.contSyms[c.contSyms.high]
|
||||||
add(result, PTransNode(newSymNode(labl)))
|
add(result, PTransNode(newSymNode(labl)))
|
||||||
of nkBreakStmt: result = transformBreak(c, n)
|
of nkBreakStmt: result = transformBreak(c, n)
|
||||||
|
|
|
||||||
|
|
@ -905,6 +905,12 @@ proc matchType*(a: PType, pattern: openArray[tuple[k:TTypeKind, i:int]],
|
||||||
a = a.sons[i]
|
a = a.sons[i]
|
||||||
result = a.kind == last
|
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 =
|
proc matchTypeClass*(bindings: var TIdTable, typeClass, t: PType): bool =
|
||||||
for i in countup(0, typeClass.sonsLen - 1):
|
for i in countup(0, typeClass.sonsLen - 1):
|
||||||
let req = typeClass.sons[i]
|
let req = typeClass.sons[i]
|
||||||
|
|
|
||||||
|
|
@ -8,13 +8,13 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
## This module is a wrapper around `opengl`:idx:. If you define the symbol
|
## This module is a wrapper around `opengl`:idx:. If you define the symbol
|
||||||
## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism,
|
## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism,
|
||||||
## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
|
## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
|
||||||
## extension loading for the different operating systems is handled here.
|
## extension loading for the different operating systems is handled here.
|
||||||
##
|
##
|
||||||
## You need to call ``loadExtensions`` after a rendering context has been
|
## You need to call ``loadExtensions`` after a rendering context has been
|
||||||
## created to load any extension proc that your code uses.
|
## created to load any extension proc that your code uses.
|
||||||
|
|
||||||
when defined(linux):
|
when defined(linux):
|
||||||
import X, XLib, XUtil
|
import X, XLib, XUtil
|
||||||
elif defined(windows):
|
elif defined(windows):
|
||||||
|
|
@ -39,58 +39,58 @@ when defined(useGlew):
|
||||||
{.pragma: wgl, header: "<GL/wglew.h>".}
|
{.pragma: wgl, header: "<GL/wglew.h>".}
|
||||||
{.pragma: glu, dynlib: gludll.}
|
{.pragma: glu, dynlib: gludll.}
|
||||||
else:
|
else:
|
||||||
# quite complex ... thanks to extension support for various platforms:
|
# quite complex ... thanks to extension support for various platforms:
|
||||||
import dynlib
|
import dynlib
|
||||||
|
|
||||||
let oglHandle = LoadLib(ogldll)
|
let oglHandle = LoadLib(ogldll)
|
||||||
if isNil(oglHandle): quit("could not load: " & ogldll)
|
if isNil(oglHandle): quit("could not load: " & ogldll)
|
||||||
|
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](
|
var wglGetProcAddress = cast[proc (s: cstring): pointer {.stdcall.}](
|
||||||
symAddr(oglHandle, "wglGetProcAddress"))
|
symAddr(oglHandle, "wglGetProcAddress"))
|
||||||
elif defined(linux):
|
elif defined(linux):
|
||||||
var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](
|
var glXGetProcAddress = cast[proc (s: cstring): pointer {.cdecl.}](
|
||||||
symAddr(oglHandle, "glXGetProcAddress"))
|
symAddr(oglHandle, "glXGetProcAddress"))
|
||||||
var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](
|
var glXGetProcAddressARB = cast[proc (s: cstring): pointer {.cdecl.}](
|
||||||
symAddr(oglHandle, "glXGetProcAddressARB"))
|
symAddr(oglHandle, "glXGetProcAddressARB"))
|
||||||
|
|
||||||
proc glGetProc(h: TLibHandle; procName: cstring): pointer =
|
proc glGetProc(h: TLibHandle; procName: cstring): pointer =
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
result = symAddr(h, procname)
|
result = symAddr(h, procname)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)
|
if not isNil(wglGetProcAddress): result = wglGetProcAddress(ProcName)
|
||||||
elif defined(linux):
|
elif defined(linux):
|
||||||
if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)
|
if not isNil(glXGetProcAddress): result = glXGetProcAddress(ProcName)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
if not isNil(glXGetProcAddressARB):
|
if not isNil(glXGetProcAddressARB):
|
||||||
result = glXGetProcAddressARB(ProcName)
|
result = glXGetProcAddressARB(ProcName)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
result = symAddr(h, procname)
|
result = symAddr(h, procname)
|
||||||
else:
|
else:
|
||||||
result = symAddr(h, procName)
|
result = symAddr(h, procName)
|
||||||
if result == nil: raiseInvalidLibrary(procName)
|
if result == nil: raiseInvalidLibrary(procName)
|
||||||
|
|
||||||
var gluHandle: TLibHandle
|
var gluHandle: TLibHandle
|
||||||
|
|
||||||
proc gluGetProc(procname: cstring): pointer =
|
proc gluGetProc(procname: cstring): pointer =
|
||||||
if gluHandle == nil:
|
if gluHandle == nil:
|
||||||
gluHandle = LoadLib(gludll)
|
gluHandle = LoadLib(gludll)
|
||||||
if gluHandle == nil: quit("could not load: " & gludll)
|
if gluHandle == nil: quit("could not load: " & gludll)
|
||||||
result = glGetProc(gluHandle, procname)
|
result = glGetProc(gluHandle, procname)
|
||||||
|
|
||||||
# undocumented 'dynlib' feature: the string literal is replaced by
|
# undocumented 'dynlib' feature: the string literal is replaced by
|
||||||
# the imported proc name:
|
# the imported proc name:
|
||||||
{.pragma: ogl, dynlib: glGetProc(oglHandle, "").}
|
{.pragma: ogl, dynlib: glGetProc(oglHandle, "0").}
|
||||||
{.pragma: oglx, dynlib: glGetProc(oglHandle, "0").}
|
{.pragma: oglx, dynlib: glGetProc(oglHandle, "0").}
|
||||||
{.pragma: wgl, dynlib: glGetProc(oglHandle, "").}
|
{.pragma: wgl, dynlib: glGetProc(oglHandle, "0").}
|
||||||
{.pragma: glu, dynlib: gluGetProc("").}
|
{.pragma: glu, dynlib: gluGetProc("").}
|
||||||
|
|
||||||
proc nimLoadProcs0() {.importc.}
|
proc nimLoadProcs0() {.importc.}
|
||||||
|
|
||||||
template loadExtensions*() =
|
template loadExtensions*() =
|
||||||
## call this after your rendering context has been setup if you use
|
## call this after your rendering context has been setup if you use
|
||||||
## extensions.
|
## extensions.
|
||||||
bind nimLoadProcs0
|
bind nimLoadProcs0
|
||||||
nimLoadProcs0()
|
nimLoadProcs0()
|
||||||
|
|
||||||
#==============================================================================
|
#==============================================================================
|
||||||
|
|
@ -9104,7 +9104,7 @@ proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fSUN*(rc: GLuint,
|
||||||
proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint,
|
proc glReplacementCodeuiTexCoord2fColor4fNormal3fVertex3fvSUN*(rc: PGLuint,
|
||||||
tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.}
|
tc: PGLfloat, c: PGLfloat, n: PGLfloat, v: PGLfloat){.stdcall, importc, ogl.}
|
||||||
# window support functions
|
# window support functions
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
when not defined(wglGetProcAddress):
|
when not defined(wglGetProcAddress):
|
||||||
proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.}
|
proc wglGetProcAddress*(ProcName: cstring): Pointer{.stdcall, importc, wgl.}
|
||||||
proc wglCopyContext*(p1: HGLRC, p2: HGLRC, p3: int): BOOL{.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.}
|
stdcall, importc, oglx.}
|
||||||
proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable,
|
proc glXGetSelectedEvent*(dpy: PDisplay, draw: GLXDrawable,
|
||||||
event_mask: PGLuint){.stdcall, importc, oglx.}
|
event_mask: PGLuint){.stdcall, importc, oglx.}
|
||||||
# GLX_VERSION_1_4
|
# GLX_VERSION_1_4
|
||||||
when not defined(glXGetProcAddress):
|
when not defined(glXGetProcAddress):
|
||||||
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
|
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
|
||||||
# GLX_ARB_get_proc_address
|
# GLX_ARB_get_proc_address
|
||||||
when not defined(glXGetProcAddressARB):
|
when not defined(glXGetProcAddressARB):
|
||||||
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}
|
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.}
|
||||||
# GLX_ARB_create_context
|
# GLX_ARB_create_context
|
||||||
proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig,
|
proc glXCreateContextAttribsARB*(dpy: PDisplay, config: GLXFBConfig,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue