diff options
author | Araq <rumpf_a@web.de> | 2012-09-28 00:22:07 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-09-28 00:22:07 +0200 |
commit | 36efc380ddd59cd66543b1f6d7c818f0c3ce887b (patch) | |
tree | 275b3db2433baeae0167206e8fdd068587490b98 /compiler | |
parent | 5538727945d634272f9de03b626bc2ff4e6df873 (diff) | |
download | Nim-36efc380ddd59cd66543b1f6d7c818f0c3ce887b.tar.gz |
website improvements; better opengl wrapper (still broken)
Diffstat (limited to 'compiler')
-rwxr-xr-x | compiler/cgen.nim | 33 | ||||
-rwxr-xr-x | compiler/pragmas.nim | 8 |
2 files changed, 33 insertions, 8 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 78616ef30..7c9f2a0cd 100755 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -494,6 +494,11 @@ proc libCandidates(s: string, dest: var TStringSeq) = else: 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) = assert(lib != nil) if not lib.generated: @@ -536,17 +541,35 @@ proc mangleDynLibProc(sym: PSym): PRope = proc SymInDynamicLib(m: BModule, sym: PSym) = var lib = sym.annex + let isCall = isGetProcAddr(lib) var extname = sym.loc.r - loadDynamicLib(m, lib) + if not isCall: loadDynamicLib(m, lib) if gCmd == cmdCompileToLLVM: incl(sym.loc.flags, lfIndirect) var tmp = mangleDynLibProc(sym) sym.loc.r = tmp # from now on we only need the internal name sym.typ.sym = nil # generate a new 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))]) + if isCall: + let n = lib.path + var a: TLoc + 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", "$1 = linkonce global $2 zeroinitializer$n", [sym.loc.r, getTypeDesc(m, sym.loc.t)]) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 14bfedd95..99c2996fa 100755 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -201,16 +201,18 @@ proc getLib(c: PContext, kind: TLibKind, path: PNode): PLib = result.path = path Append(c.libs, result) -proc expectDynlibNode(c: PContext, n: PNode): PNode = - if n.kind != nkExprColonExpr: +proc expectDynlibNode(c: PContext, n: PNode): PNode = + if n.kind != nkExprColonExpr: LocalError(n.info, errStringLiteralExpected) # error correction: result = newEmptyStrNode(n) else: + # For the OpenGL wrapper we support: + # {.dynlib: myGetProcAddr(...).} result = c.semExpr(c, n.sons[1]) if result.kind == nkSym and result.sym.kind == skConst: 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) result = newEmptyStrNode(n) |