mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-24 11:55:10 +00:00
Merge branch 'master' of github.com:Araq/Nimrod
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user