website improvements; better opengl wrapper (still broken)

This commit is contained in:
Araq 2012-09-28 00:22:07 +02:00
commit 36efc380dd
8 changed files with 137 additions and 101 deletions

View file

@ -494,6 +494,11 @@ proc libCandidates(s: string, dest: var TStringSeq) =
else: else:
add(dest, s) add(dest, s)
proc isGetProcAddr(lib: PLib): bool =
let n = lib.path
result = n.kind in nkCallKinds and n.typ != nil and
n.typ.kind in {tyPointer, tyProc}
proc loadDynamicLib(m: BModule, lib: PLib) = proc loadDynamicLib(m: BModule, lib: PLib) =
assert(lib != nil) assert(lib != nil)
if not lib.generated: if not lib.generated:
@ -536,17 +541,35 @@ proc mangleDynLibProc(sym: PSym): PRope =
proc SymInDynamicLib(m: BModule, sym: PSym) = proc SymInDynamicLib(m: BModule, sym: PSym) =
var lib = sym.annex var lib = sym.annex
let isCall = isGetProcAddr(lib)
var extname = sym.loc.r var extname = sym.loc.r
loadDynamicLib(m, lib) if not isCall: loadDynamicLib(m, lib)
if gCmd == cmdCompileToLLVM: incl(sym.loc.flags, lfIndirect) if gCmd == cmdCompileToLLVM: incl(sym.loc.flags, lfIndirect)
var tmp = mangleDynLibProc(sym) var tmp = mangleDynLibProc(sym)
sym.loc.r = tmp # from now on we only need the internal name sym.loc.r = tmp # from now on we only need the internal name
sym.typ.sym = nil # generate a new name sym.typ.sym = nil # generate a new name
inc(m.labels, 2) inc(m.labels, 2)
appcg(m, m.s[cfsDynLibInit], if isCall:
"$1 = ($2) #nimGetProcAddr($3, $4);$n", let n = lib.path
[tmp, getTypeDesc(m, sym.typ), var a: TLoc
lib.name, cstringLit(m, m.s[cfsDynLibInit], ropeToStr(extname))]) initLocExpr(m.initProc, n[0], a)
var params = con(rdLoc(a), "(")
for i in 1 .. n.len-2:
initLocExpr(m.initProc, n[i], a)
params.app(rdLoc(a))
params.app(", ")
#app(m.s[cfsVars], p.s(cpsLocals))
#app(m.s[cfsDynLibInit], p.s(cpsInit))
#app(m.s[cfsDynLibInit], p.s(cpsStmts))
appcg(m, m.initProc.s(cpsStmts),
"$1 = ($2) ($3$4));$n",
[tmp, getTypeDesc(m, sym.typ),
params, cstringLit(m, m.s[cfsDynLibInit], ropeToStr(extname))])
else:
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))])
appff(m.s[cfsVars], "$2 $1;$n", appff(m.s[cfsVars], "$2 $1;$n",
"$1 = linkonce global $2 zeroinitializer$n", "$1 = linkonce global $2 zeroinitializer$n",
[sym.loc.r, getTypeDesc(m, sym.loc.t)]) [sym.loc.r, getTypeDesc(m, sym.loc.t)])

View file

@ -207,10 +207,12 @@ proc expectDynlibNode(c: PContext, n: PNode): PNode =
# error correction: # error correction:
result = newEmptyStrNode(n) result = newEmptyStrNode(n)
else: else:
# For the OpenGL wrapper we support:
# {.dynlib: myGetProcAddr(...).}
result = c.semExpr(c, n.sons[1]) result = c.semExpr(c, n.sons[1])
if result.kind == nkSym and result.sym.kind == skConst: if result.kind == nkSym and result.sym.kind == skConst:
result = result.sym.ast # look it up result = result.sym.ast # look it up
if result.typ == nil or result.typ.kind != tyString: if result.typ == nil or result.typ.kind notin {tyPointer, tyString, tyProc}:
LocalError(n.info, errStringLiteralExpected) LocalError(n.info, errStringLiteralExpected)
result = newEmptyStrNode(n) result = newEmptyStrNode(n)

View file

@ -21,19 +21,22 @@ proc LoadLib*(path: string): TLibHandle
proc UnloadLib*(lib: TLibHandle) proc UnloadLib*(lib: TLibHandle)
## unloads the library `lib` ## unloads the library `lib`
proc symAddr*(lib: TLibHandle, name: string): pointer proc raiseInvalidLibrary*(name: cstring) {.noinline, noreturn.} =
## raises an `EInvalidLibrary` exception.
var e: ref EInvalidLibrary
new(e)
e.msg = "could not find symbol: " & $name
raise e
proc symAddr*(lib: TLibHandle, name: cstring): pointer
## retrieves the address of a procedure/variable from `lib`. Returns nil ## retrieves the address of a procedure/variable from `lib`. Returns nil
## if the symbol could not be found. ## if the symbol could not be found.
proc checkedSymAddr*(lib: TLibHandle, name: string): pointer = proc checkedSymAddr*(lib: TLibHandle, name: cstring): pointer =
## retrieves the address of a procedure/variable from `lib`. Raises ## retrieves the address of a procedure/variable from `lib`. Raises
## `EInvalidLibrary` if the symbol could not be found. ## `EInvalidLibrary` if the symbol could not be found.
result = symAddr(lib, name) result = symAddr(lib, name)
if result == nil: if result == nil: raiseInvalidLibrary(name)
var e: ref EInvalidLibrary
new(e)
e.msg = "could not find symbol: " & name
raise e
when defined(posix): when defined(posix):
# #
@ -55,7 +58,7 @@ when defined(posix):
proc LoadLib(path: string): TLibHandle = return dlopen(path, RTLD_NOW) proc LoadLib(path: string): TLibHandle = return dlopen(path, RTLD_NOW)
proc UnloadLib(lib: TLibHandle) = dlclose(lib) proc UnloadLib(lib: TLibHandle) = dlclose(lib)
proc symAddr(lib: TLibHandle, name: string): pointer = proc symAddr(lib: TLibHandle, name: cstring): pointer =
return dlsym(lib, name) return dlsym(lib, name)
elif defined(windows) or defined(dos): elif defined(windows) or defined(dos):
@ -77,7 +80,7 @@ elif defined(windows) or defined(dos):
result = cast[TLibHandle](winLoadLibrary(path)) result = cast[TLibHandle](winLoadLibrary(path))
proc UnloadLib(lib: TLibHandle) = FreeLibrary(cast[THINSTANCE](lib)) proc UnloadLib(lib: TLibHandle) = FreeLibrary(cast[THINSTANCE](lib))
proc symAddr(lib: TLibHandle, name: string): pointer = proc symAddr(lib: TLibHandle, name: cstring): pointer =
result = GetProcAddress(cast[THINSTANCE](lib), name) result = GetProcAddress(cast[THINSTANCE](lib), name)
else: else:

View file

@ -8,8 +8,27 @@
# #
## 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 (which ## ``useGlew`` this wrapper does not use Nimrod's ``dynlib`` mechanism,
## ends up calling ``dlsym`` or ``GetProcAddress``), but `glew`:idx: instead. ## but `glew`:idx: instead. However, this shouldn't be necessary anymore; even
## extension loading for the different operating systems is handled here.
when defined(linux):
import X, XLib, XUtil
elif defined(windows):
import winlean, os
when defined(windows):
const
ogldll* = "OpenGL32.dll"
gludll* = "GLU32.dll"
elif defined(macosx):
const
ogldll* = "libGL.dylib"
gludll* = "libGLU.dylib"
else:
const
ogldll* = "libGL.so.1"
gludll* = "libGLU.so.1"
when defined(useGlew): when defined(useGlew):
{.pragma: ogl, header: "<GL/glew.h>".} {.pragma: ogl, header: "<GL/glew.h>".}
@ -17,11 +36,51 @@ 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:
{.pragma: ogl, dynlib: ogldll.} # quite complex ... thanks to extension support for various platforms:
{.pragma: oglx, dynlib: ogldll.} import dynlib
{.pragma: wgl, dynlib: ogldll.}
{.pragma: glu, dynlib: gludll.}
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 empty string literal is replaced by
# the imported proc name:
{.pragma: ogl, dynlib: glGetProc(oglHandle, "").}
{.pragma: oglx, dynlib: glGetProc(oglHandle, "").}
{.pragma: wgl, dynlib: glGetProc(oglHandle, "").}
{.pragma: glu, dynlib: gluGetProc("").}
#============================================================================== #==============================================================================
# #
@ -398,27 +457,6 @@ else:
{.deadCodeElim: on.} {.deadCodeElim: on.}
when defined(LINUX):
import
X, XLib, XUtil
when defined(windows):
import
winlean, os
when defined(windows):
const
ogldll* = "OpenGL32.dll"
gludll* = "GLU32.dll"
elif defined(macosx):
const
ogldll* = "libGL.dylib"
gludll* = "libGLU.dylib"
else:
const
ogldll* = "libGL.so.1"
gludll* = "libGLU.so.1"
type type
PPointer* = ptr Pointer PPointer* = ptr Pointer
GLenum* = int GLenum* = int
@ -9397,9 +9435,11 @@ when defined(LINUX):
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
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.} when not defined(glXGetProcAddress):
proc glXGetProcAddress*(name: cstring): pointer{.stdcall, importc, oglx.}
# GLX_ARB_get_proc_address # GLX_ARB_get_proc_address
proc glXGetProcAddressARB*(name: cstring): pointer{.stdcall, importc, oglx.} when not defined(glXGetProcAddressARB):
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,
share_context: GLXContext, direct: GLboolean, share_context: GLXContext, direct: GLboolean,

View file

@ -1,6 +1,7 @@
version 0.9.2 version 0.9.2
============= =============
- fix broken expr/stmt handling for proc bodies
- make 'bind' default for templates and introduce 'mixin' - make 'bind' default for templates and introduce 'mixin'
- implicit deref for parameter matching; overloading based on 'var T' - implicit deref for parameter matching; overloading based on 'var T'
- optimize genericAssign in the code generator - optimize genericAssign in the code generator

View file

@ -34,20 +34,10 @@
</ul> </ul>
</div> </div>
<div id="column1"> <div id="column1">
# if len(c.ticker) > 0:
<div class="sidebaritem">
<div class="sbihead">
<h1>latest news</h1>
</div>
<div class="sbicontent">
$c.ticker
</div>
</div>
# end if
# if len(c.links) > 0: # if len(c.links) > 0:
<div class="sidebaritem"> <div class="sidebaritem">
<div class="sbihead"> <div class="sbihead">
<h1>additional links</h1> <h1>projects</h1>
</div> </div>
<div class="sbilinks"> <div class="sbilinks">
<!-- **** INSERT ADDITIONAL LINKS HERE **** --> <!-- **** INSERT ADDITIONAL LINKS HERE **** -->
@ -58,6 +48,16 @@
</ul> </ul>
</div> </div>
</div> </div>
# end if
# if len(c.ticker) > 0:
<div class="sidebaritem">
<div class="sbihead">
<h1>latest news</h1>
</div>
<div class="sbicontent">
$c.ticker
</div>
</div>
# end if # end if
</div> </div>
<div id="column2"> <div id="column2">
@ -65,9 +65,11 @@
</div> </div>
</div> </div>
<div id="footer"> <div id="footer">
copyright &copy; 2012 $c.authors | Last update: ${getDateStr()} &copy; 2012 $c.authors | Last update: ${getDateStr()}
| <a class="reference" href="http://validator.w3.org/check?uri=referer">XHTML 1.1</a> <!-- | <iframe style="border: 0; margin: 0; padding: 0;"
| <a class="reference" href="http://jigsaw.w3.org/css-validator/check/referer">CSS</a> src="https://www.gittip.com/Araq/widget.html"
width="48pt" height="15pt"></iframe> -->
| <a class="reference" href="http://www.dcarter.co.uk">design by dcarter</a> | <a class="reference" href="http://www.dcarter.co.uk">design by dcarter</a>
</div> </div>
</div> </div>

View file

@ -2,11 +2,12 @@
Name: "Nimrod" Name: "Nimrod"
Title: "Nimrod Programming Language" Title: "Nimrod Programming Language"
Logo: "efficient, expressive, elegant" Logo: "efficient, expressive, elegant"
Authors: "Andreas Rumpf" Authors: "Andreas Rumpf and contributors"
[Links] [Links]
GCC: "http://gcc.gnu.org" FORUM: "http://forum.nimrod-code.org"
LLVM: "http://llvm.org" APORIA: "https://github.com/nimrod-code/Aporia"
NIMBUILD: "http://build.nimrod-code.org"
[Tabs] [Tabs]
# Menu entry: filename # Menu entry: filename

View file

@ -14,39 +14,3 @@
| `2010-03-14`:newsdate: | `2010-03-14`:newsdate:
| Nimrod version 0.8.8 has been released! | Nimrod version 0.8.8 has been released!
| `2009-12-21`:newsdate:
| Nimrod version 0.8.6 has been released!
| `2009-10-21`:newsdate:
| Nimrod version 0.8.2 has been released!
| `2009-09-12`:newsdate:
| Nimrod version 0.8.0 has been released!
| `2009-06-08`:newsdate:
| Nimrod version 0.7.10 has been released!
| `2009-05-08`:newsdate:
| Nimrod version 0.7.8 has been released!
| `2009-04-22`:newsdate:
| Nimrod version 0.7.6 has been released!
| `2009-01-22`:newsdate:
| Forum added!
| `2009-01-07`:newsdate:
| Nimrod version 0.7.4 has been released!
| `2008-12-12`:newsdate:
| Nimrod version 0.7.2 has been released!
| `2008-11-16`:newsdate:
| Nimrod version 0.7.0 has been released!
| `2008-08-22`:newsdate:
| Nimrod version 0.6.0 has been released!
| `2008-06-22`:newsdate:
| This page is finally online!