diff options
-rwxr-xr-x | lib/system/dyncalls.nim | 5 | ||||
-rwxr-xr-x | rod/cgen.nim | 24 | ||||
-rwxr-xr-x | tests/tsplit.nim | 14 | ||||
-rwxr-xr-x | tests/ttuple1.nim | 16 |
4 files changed, 45 insertions, 14 deletions
diff --git a/lib/system/dyncalls.nim b/lib/system/dyncalls.nim index c0371d069..0946ee355 100755 --- a/lib/system/dyncalls.nim +++ b/lib/system/dyncalls.nim @@ -60,6 +60,7 @@ when defined(posix): proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr = result = dlsym(lib, name) + if result == nil: nimLoadLibraryError($name) elif defined(windows) or defined(dos): # @@ -84,6 +85,7 @@ elif defined(windows) or defined(dos): proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr = result = GetProcAddress(cast[THINSTANCE](lib), name) + if result == nil: nimLoadLibraryError($name) elif defined(mac): # @@ -114,11 +116,12 @@ elif defined(mac): NSDestroyObjectFileImage(img) result = TLibHandle(modul) - proc nimGetProcAddr(lib: TLibHandle, cname: string): TProcAddr = + proc nimGetProcAddr(lib: TLibHandle, name: cstring): TProcAddr = var nss: NSSymbol nss = NSLookupSymbolInModule(NSModule(lib), name) result = TProcAddr(NSAddressOfSymbol(nss)) + if result == nil: nimLoadLibraryError($name) else: {.error: "no implementation for dyncalls".} diff --git a/rod/cgen.nim b/rod/cgen.nim index a330790cc..c3b4f8b2d 100755 --- a/rod/cgen.nim +++ b/rod/cgen.nim @@ -319,11 +319,8 @@ proc genConstPrototype(m: BModule, sym: PSym) proc genProc(m: BModule, prc: PSym) proc genStmts(p: BProc, t: PNode) proc genProcPrototype(m: BModule, sym: PSym) -include - "ccgexprs.nim" -include - "ccgstmts.nim" +include "ccgexprs.nim", "ccgstmts.nim" # ----------------------------- dynamic library handling ----------------- # We don't finalize dynamic libs as this does the OS for us. @@ -367,8 +364,9 @@ proc loadDynamicLib(m: BModule, lib: PLib) = getTypeDesc(m, getSysType(tyString)), toRope(m.labels)]) appff(m.s[cfsDynLibInit], "if (!($1)) nimLoadLibraryError((NimStringDesc*) &$2);$n", - "XXX too implement", [loadlib, getStrLit(m, lib.path)]) #appf(m.s[cfsDynLibDeinit], - # 'if ($1 != NIM_NIL) nimUnloadLibrary($1);$n', [tmp]); + "XXX too implement", [loadlib, getStrLit(m, lib.path)]) + #appf(m.s[cfsDynLibDeinit], "if ($1 != NIM_NIL) nimUnloadLibrary($1);$n", + # [tmp]) useMagic(m, "nimLoadLibrary") useMagic(m, "nimUnloadLibrary") useMagic(m, "NimStringDesc") @@ -388,13 +386,14 @@ proc SymInDynamicLib(m: BModule, sym: PSym) = 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) - appff(m.s[cfsDynLibInit], "$1 = ($2) nimGetProcAddr($3, $4);$n", "%MOC$5 = load i8* $3$n" & + appff(m.s[cfsDynLibInit], + "$1 = ($2) nimGetProcAddr($3, $4);$n", "%MOC$5 = load i8* $3$n" & "%MOC$6 = call $2 @nimGetProcAddr(i8* %MOC$5, i8* $4)$n" & - "store $2 %MOC$6, $2* $1$n", [tmp, getTypeDesc(m, sym.typ), lib.name, cstringLit( - m, m.s[cfsDynLibInit], ropeToStr(extname)), toRope(m.labels), - toRope(m.labels - 1)]) + "store $2 %MOC$6, $2* $1$n", [tmp, getTypeDesc(m, sym.typ), + lib.name, cstringLit(m, m.s[cfsDynLibInit], ropeToStr(extname)), + toRope(m.labels), toRope(m.labels - 1)]) appff(m.s[cfsVars], "$2 $1;$n", "$1 = linkonce global $2 zeroinitializer$n", - [sym.loc.r, getTypeDesc(m, sym.loc.t)]) + [sym.loc.r, getTypeDesc(m, sym.loc.t)]) proc UseMagic(m: BModule, name: string) = var sym: PSym @@ -409,9 +408,8 @@ proc UseMagic(m: BModule, name: string) = rawMessage(errSystemNeeds, name) # don't be too picky here proc generateHeaders(m: BModule) = - var it: PStrEntry app(m.s[cfsHeaders], "#include \"nimbase.h\"" & tnl & tnl) - it = PStrEntry(m.headerFiles.head) + var it = PStrEntry(m.headerFiles.head) while it != nil: if not (it.data[0] in {'\"', '<'}): appf(m.s[cfsHeaders], "#include \"$1\"$n", [toRope(it.data)]) diff --git a/tests/tsplit.nim b/tests/tsplit.nim new file mode 100755 index 000000000..711696b9e --- /dev/null +++ b/tests/tsplit.nim @@ -0,0 +1,14 @@ +import strutils + +var s = "" +for w in split("|abc|xy|z", {'|'}): + s.add("#") + s.add(w) + +if s == "#abc#xy#z": + echo "true" +else: + echo "false" + +#OUT true + diff --git a/tests/ttuple1.nim b/tests/ttuple1.nim new file mode 100755 index 000000000..5787cc309 --- /dev/null +++ b/tests/ttuple1.nim @@ -0,0 +1,16 @@ +const romanNumbers = [ + ("M", 1000), ("D", 500), ("C", 100), + ("L", 50), ("X", 10), ("V", 5), ("I", 1) ] + +var c = 0 +for key, val in items(romanNumbers): + inc(c) + stdout.write(key & "=" & $val) + if c < romanNumbers.len: stdout.write(", ") else: echo"" +#echo"" + +proc PrintBiTuple(t: tuple[k: string, v: int]): int = + stdout.write(t.k & "=" & $t.v & ", ") + return 0 + + |