From 93c83728c71132a63c69ecfaab84c4c91bb05615 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sun, 23 Aug 2020 17:11:18 -0600 Subject: [PATCH 01/13] Fix nimterop imports --- nimterop/enumtypepub.nim | 42 +++++++++++++++++++++++++++++++++++ nimterop/toastlib/getters.nim | 2 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 nimterop/enumtypepub.nim diff --git a/nimterop/enumtypepub.nim b/nimterop/enumtypepub.nim new file mode 100644 index 0000000..7700e30 --- /dev/null +++ b/nimterop/enumtypepub.nim @@ -0,0 +1,42 @@ +import macros + +macro defineEnum*(typ: untyped): untyped = + result = newNimNode(nnkStmtList) + + # Enum mapped to distinct cint + result.add quote do: + type `typ`* = distinct cint + + for i in ["+", "-", "*", "div", "mod", "shl", "shr", "or", "and", "xor", "<", "<=", "==", ">", ">="]: + let + ni = newIdentNode(i) + typout = if i[0] in "<=>": newIdentNode("bool") else: typ # comparisons return bool + if i[0] == '>': # cannot borrow `>` and `>=` from templates + let + nopp = if i.len == 2: newIdentNode("<=") else: newIdentNode("<") + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` = `nopp`(y, x) + proc `ni`*(x: cint, y: `typ`): `typout` = `nopp`(y, x) + proc `ni`*(x, y: `typ`): `typout` = `nopp`(y, x) + else: + result.add quote do: + proc `ni`*(x: `typ`, y: cint): `typout` {.borrow.} + proc `ni`*(x: cint, y: `typ`): `typout` {.borrow.} + proc `ni`*(x, y: `typ`): `typout` {.borrow.} + result.add quote do: + proc `ni`*(x: `typ`, y: int): `typout` = `ni`(x, y.cint) + proc `ni`*(x: int, y: `typ`): `typout` = `ni`(x.cint, y) + + let + divop = newIdentNode("/") # `/`() + dlrop = newIdentNode("$") # `$`() + notop = newIdentNode("not") # `not`() + result.add quote do: + proc `divop`*(x, y: `typ`): `typ` = `typ`((x.float / y.float).cint) + proc `divop`*(x: `typ`, y: cint): `typ` = `divop`(x, `typ`(y)) + proc `divop`*(x: cint, y: `typ`): `typ` = `divop`(`typ`(x), y) + proc `divop`*(x: `typ`, y: int): `typ` = `divop`(x, y.cint) + proc `divop`*(x: int, y: `typ`): `typ` = `divop`(x.cint, y) + + proc `dlrop`*(x: `typ`): string {.borrow.} + proc `notop`*(x: `typ`): `typ` {.borrow.} diff --git a/nimterop/toastlib/getters.nim b/nimterop/toastlib/getters.nim index f0a4735..2e1ac4c 100644 --- a/nimterop/toastlib/getters.nim +++ b/nimterop/toastlib/getters.nim @@ -31,7 +31,7 @@ yield""".split(Whitespace).toHashSet() const # Enum macro read from file - written into wrapper when required - gEnumMacroConst = staticRead(currentSourcePath.parentDir().parentDir() / "enumtype.nim") + gEnumMacroConst = "import nimterop / enumtypepub" var gEnumMacro* = gEnumMacroConst -- 2.49.1 From 00941e892588503d18b3d271a65b0596bc6d857b Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sat, 12 Sep 2020 10:59:14 -0600 Subject: [PATCH 02/13] Fix regen issues windows/linux --- nimterop/build/shell.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nimterop/build/shell.nim b/nimterop/build/shell.nim index f0af561..e5a70a8 100644 --- a/nimterop/build/shell.nim +++ b/nimterop/build/shell.nim @@ -206,9 +206,9 @@ proc getFileDate*(fullpath: string): string = when defined(Windows): let (head, tail) = fullpath.splitPath() - &"cmd /c forfiles /P {head.sanitizePath()} /M {tail.sanitizePath} /C \"cmd /c echo @fdate @ftime @fsize\"" + &"forfiles /P {head.sanitizePath()} /M {tail.sanitizePath} /C \"cmd /c echo @fdate @ftime\"" elif defined(Linux): - &"stat -c %y {fullpath.sanitizePath}" + &"stat -c %Y {fullpath.sanitizePath}" elif defined(OSX) or defined(FreeBSD): &"stat -f %m {fullpath.sanitizePath}" -- 2.49.1 From 316a56107a4ccfcc0773d5a5b7f59abf0e05f922 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sat, 12 Sep 2020 12:48:45 -0600 Subject: [PATCH 03/13] Add ability to get a define value --- nimterop/build/getheader.nim | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nimterop/build/getheader.nim b/nimterop/build/getheader.nim index 4549894..bbc810a 100644 --- a/nimterop/build/getheader.nim +++ b/nimterop/build/getheader.nim @@ -59,6 +59,11 @@ macro isDefined*(def: untyped): untyped = false ) +macro getDefine*(def: untyped): untyped = + if gDefines.hasKey(def.strVal()): + return newStrLitNode(gDefines[def.strVal()]) + return newStrLitNode("") + proc getDynlibExt(): string = when defined(Windows): result = "[0-9.\\-]*\\.dll" -- 2.49.1 From 1b8aa46b8a5b8254cee5aa0c5d73e29881ca7ed9 Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Sat, 12 Sep 2020 15:24:29 -0600 Subject: [PATCH 04/13] Improve on getdefine --- nimterop/build/getheader.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/nimterop/build/getheader.nim b/nimterop/build/getheader.nim index bbc810a..36dd50c 100644 --- a/nimterop/build/getheader.nim +++ b/nimterop/build/getheader.nim @@ -60,9 +60,15 @@ macro isDefined*(def: untyped): untyped = ) macro getDefine*(def: untyped): untyped = - if gDefines.hasKey(def.strVal()): - return newStrLitNode(gDefines[def.strVal()]) - return newStrLitNode("") + let version = newIdentNode(def.strVal()) + let verVal = + if gDefines.hasKey(def.strVal()): + gDefines[def.strVal()] + else: + "" + result = quote do: + const `version` {.strdefine.} = `verVal` + `version` proc getDynlibExt(): string = when defined(Windows): -- 2.49.1 From 217bce386a2ef7119e4914b19461d18e0fae821a Mon Sep 17 00:00:00 2001 From: Joey Yakimowich-Payne Date: Thu, 17 Sep 2020 19:59:41 -0600 Subject: [PATCH 05/13] Don't die on nimcheck for cached files --- nimterop/build/shell.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimterop/build/shell.nim b/nimterop/build/shell.nim index e5a70a8..a8511c2 100644 --- a/nimterop/build/shell.nim +++ b/nimterop/build/shell.nim @@ -212,7 +212,7 @@ proc getFileDate*(fullpath: string): string = elif defined(OSX) or defined(FreeBSD): &"stat -f %m {fullpath.sanitizePath}" - (result, ret) = execAction(cmd) + (result, ret) = execAction(cmd, die=false) proc touchFile*(fullpath: string) = ## Touch file to update modified date -- 2.49.1 From 60cc0d26efb79e4becb064e2db3bf5973bd25b89 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Fri, 2 Oct 2020 17:46:27 -0500 Subject: [PATCH 06/13] Add musl support --- nimterop/build/ccompiler.nim | 4 +++- nimterop/build/conan.nim | 30 ++++++++++++++++++++++-------- nimterop/build/jbb.nim | 26 +++++++++++++++++++------- nimterop/build/shell.nim | 29 ++++++----------------------- 4 files changed, 50 insertions(+), 39 deletions(-) diff --git a/nimterop/build/ccompiler.nim b/nimterop/build/ccompiler.nim index 550e1b2..f21f45a 100644 --- a/nimterop/build/ccompiler.nim +++ b/nimterop/build/ccompiler.nim @@ -75,7 +75,7 @@ proc getGccLibPaths*(mode: string): seq[string] = when defined(osx): result.add "/usr/lib" -proc getGccInfo*(): tuple[arch, os, compiler, version: string] = +proc getGccInfo*(): tuple[arch, os, compiler, version, libc: string] = let (outp, _) = execAction(&"{getCompiler()} -v") for line in outp.splitLines(): @@ -101,3 +101,5 @@ proc getGccInfo*(): tuple[arch, os, compiler, version: string] = result.compiler = "clang" else: result.compiler = "gcc" + if "musl" in outp: + result.libc = "musl" diff --git a/nimterop/build/conan.nim b/nimterop/build/conan.nim index 6df25d8..ac74089 100644 --- a/nimterop/build/conan.nim +++ b/nimterop/build/conan.nim @@ -16,6 +16,8 @@ type channel*: string recipes*: OrderedTableRef[string, seq[ConanBuild]] + arch*, os*, compiler*, compversion*: string + bhash*: string shared*: bool sharedLibs*: seq[string] @@ -89,6 +91,11 @@ proc `==`*(pkg1, pkg2: ConanPackage): bool = pkg1.user == pkg2.user and pkg1.channel == pkg2.channel and + pkg1.arch == pkg2.arch and + pkg1.os == pkg2.os and + pkg1.compiler == pkg2.compiler and + pkg1.compversion == pkg2.compversion and + pkg1.bhash == pkg2.bhash and pkg1.shared == pkg2.shared) @@ -101,6 +108,15 @@ proc newConanPackage*(name, version, user = "_", channel = "_", bhash = "", shar result.channel = channel result.recipes = newOrderedTable[string, seq[ConanBuild]](2) + let + (arch, os, compiler, compversion, libc) = getGccInfo() + doAssert libc != "musl", "Conan does not provide precompiled binaries using musl" + + result.arch = arch + result.os = os + result.compiler = compiler + result.compversion = compversion + result.bhash = bhash result.shared = shared @@ -189,9 +205,7 @@ proc getConanBuilds*(pkg: ConanPackage, filter = "") = ## `filter` can be used to tweak search terms ## e.g. build_type=Debug&compiler=clang let - (arch, os, compiler, version) = getGccInfo() - - vsplit = version.split('.') + vsplit = pkg.compversion.split('.') vfilter = when defined(OSX): @@ -203,18 +217,18 @@ proc getConanBuilds*(pkg: ConanPackage, filter = "") = if pkg.bhash.Bl: block: var - query = &"?q=arch={arch}&os={os.capitalizeAscii()}" + query = &"?q=arch={pkg.arch}&os={pkg.os.capitalizeAscii()}" if "build_type" notin filter: query &= "&build_type=Release" if "shared=" notin filter: query &= &"&options.shared={($pkg.shared).capitalizeAscii()}" if filter.nBl: query &= &"&{filter}" - if "compiler=" notin filter and os != "windows": - query &= &"&compiler={compiler}&compiler.version=" & vfilter - if "compiler.runtime=" notin filter and os == "windows": + if "compiler=" notin filter and pkg.os != "windows": + query &= &"&compiler={pkg.compiler}&compiler.version=" & vfilter + if "compiler.runtime=" notin filter and pkg.os == "windows": query &= &"&compiler.runtime=MD" - if "compiler.version=" notin filter and os == "windows": + if "compiler.version=" notin filter and pkg.os == "windows": query &= &"&compiler.version=14" query.replace("&", "%20and%20") diff --git a/nimterop/build/jbb.nim b/nimterop/build/jbb.nim index c8d86c3..392f848 100644 --- a/nimterop/build/jbb.nim +++ b/nimterop/build/jbb.nim @@ -17,6 +17,8 @@ type url*: string # Download URL + arch*, os*, libc*: string # Target + sharedLibs*: seq[string] staticLibs*: seq[string] requires*: seq[JBBPackage] @@ -39,7 +41,11 @@ proc `==`*(pkg1, pkg2: JBBPackage): bool = ## Check if two JBBPackage objects are equal (not pkg1.isNil and not pkg2.isNil and pkg1.name == pkg2.name and - pkg1.version == pkg2.version) + pkg1.version == pkg2.version and + + pkg1.arch == pkg2.arch and + pkg1.os == pkg2.os and + pkg1.libc == pkg2.libc) proc newJBBPackage*(name, version: string): JBBPackage = ## Create a new JBBPackage with specified name and version @@ -49,6 +55,12 @@ proc newJBBPackage*(name, version: string): JBBPackage = result.baseUrl = jbbBaseUrl result.isGit = true + let + (arch, os, _, _, libc) = getGccInfo() + result.arch = arch + result.os = os + result.libc = libc + proc parseJBBProject(pkg: JBBPackage, outdir: string) = # Get all dependencies from Project.toml let @@ -87,8 +99,6 @@ proc parseJBBArtifacts(pkg: JBBPackage, outdir: string) = let file = outdir / jbbArtifacts - (arch, os, _, _) = getGccInfo() - if fileExists(file): let data = readFile(file) @@ -109,12 +119,14 @@ proc parseJBBArtifacts(pkg: JBBPackage, outdir: string) = # Match arch, os and glibc on Linux to find download URL case name of "arch": - if val == arch and not found: found = true + if val == pkg.arch and not found: found = true of "os": - if val != os and found: found = false + if val != pkg.os and found: found = false of "libc": when defined(Linux): - if val != "glibc" and found: found = false + if found: + let libc = if pkg.libc.nBl: pkg.libc else: "glibc" + if val != libc: found = false of "url": if found: pkg.url = val @@ -125,7 +137,7 @@ proc parseJBBArtifacts(pkg: JBBPackage, outdir: string) = proc findJBBLibs(pkg: JBBPackage, outdir: string) = pkg.sharedLibs = findFiles("(bin|lib)[\\\\/].*\\.(so|dll|dylib)[0-9.]*", outdir) - for lib in findFiles("lib[\\\\/].*\\.(a|lib)$", outdir): + for lib in findFiles("lib[\\\\/].*\\.(a|lib)", outdir): if not lib.endsWith(".dll.a"): pkg.staticLibs.add lib diff --git a/nimterop/build/shell.nim b/nimterop/build/shell.nim index f0af561..d0a10fb 100644 --- a/nimterop/build/shell.nim +++ b/nimterop/build/shell.nim @@ -414,22 +414,8 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s ## ## Turn off recursive search with `recurse` var - cmd = - when defined(Windows): - "nimgrep --filenames --oneline --nocolor $1 \"$2\" $3" - elif defined(linux): - "find $3 $1 -regextype egrep -regex $2" - elif defined(osx) or defined(FreeBSD): - "find -E $3 $1 -regex $2" - - recursive = "" - - if recurse: - when defined(Windows): - recursive = "--recursive" - else: - when not defined(Windows): - recursive = "-maxdepth 1" + cmd = "nimgrep --follow --filenames --oneline --nocolor $1 \"$2\" $3" + recursive = if recurse: "--recursive" else: "" var dir = dir @@ -443,20 +429,17 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s file = file.extractFilename - cmd = cmd % [recursive, (".*[\\\\/]" & file & "$").quoteShell, dir.sanitizePath] + cmd = cmd % [recursive, (".*[\\\\/]" & file & "$"), dir.sanitizePath] let (files, ret) = execAction(cmd, die = false) if ret == 0: for line in files.splitLines(): let f = - when defined(Windows): - if ": " in line: - line.split(": ", maxsplit = 1)[1] - else: - "" + if ": " in line: + line.split(": ", maxsplit = 1)[1] else: - line + "" if f.len != 0: result.add f -- 2.49.1 From 13e5ce7e221f9e675d6747857cd3f9dbef961d40 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Mon, 5 Oct 2020 12:17:36 -0500 Subject: [PATCH 07/13] Add loaf, replace find --- nimterop.nimble | 6 +++++- nimterop/build/shell.nim | 16 +++++++--------- nimterop/loaf.nim | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 nimterop/loaf.nim diff --git a/nimterop.nimble b/nimterop.nimble index 49c40d0..8e12ee8 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -5,7 +5,7 @@ author = "genotrance" description = "C/C++ interop for Nim" license = "MIT" -bin = @["nimterop/toast"] +bin = @["nimterop/toast", "nimterop/loaf"] installDirs = @["nimterop"] # Dependencies @@ -33,6 +33,9 @@ proc execTest(test: string, flags = "", runDocs = true) = task buildTimeit, "build timer": exec "nim c --hints:off -d:danger tests/timeit" +task buildLoaf, "build loaf": + execCmd("nim c --hints:off -d:danger nimterop/loaf.nim") + task buildToast, "build toast": execCmd("nim c --hints:off -d:danger nimterop/toast.nim") @@ -89,6 +92,7 @@ task test, "Test": rmFile("tests/timeit.txt") buildTimeitTask() + buildLoafTask() buildToastTask() basicTask() diff --git a/nimterop/build/shell.nim b/nimterop/build/shell.nim index d0a10fb..7c65b71 100644 --- a/nimterop/build/shell.nim +++ b/nimterop/build/shell.nim @@ -407,6 +407,9 @@ proc gitTags*(outdir: string): seq[string] = if tag.len != 0: result.add tag +proc loafExePath(): string = + currentSourcePath.parentDir.parentDir / ("loaf".addFileExt ExeExt) + proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[string] = ## Find all matching files in the specified directory ## @@ -414,8 +417,8 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s ## ## Turn off recursive search with `recurse` var - cmd = "nimgrep --follow --filenames --oneline --nocolor $1 \"$2\" $3" - recursive = if recurse: "--recursive" else: "" + cmd = loafExePath().quoteShell & " find --rexp $1 \"$2\" $3" + recursive = if recurse: "--recurse" else: "" var dir = dir @@ -435,13 +438,8 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s (files, ret) = execAction(cmd, die = false) if ret == 0: for line in files.splitLines(): - let f = - if ": " in line: - line.split(": ", maxsplit = 1)[1] - else: - "" - if f.len != 0: - result.add f + if line.len != 0: + result.add line proc findFile*(file: string, dir: string, recurse = true, first = false, regex = false): string = ## Find the file in the specified directory diff --git a/nimterop/loaf.nim b/nimterop/loaf.nim new file mode 100644 index 0000000..04b377e --- /dev/null +++ b/nimterop/loaf.nim @@ -0,0 +1,39 @@ +import system except find + +import os + +import cligen + +import strutils except find +import regex except find + +proc findRec(dir: string, pattern: string | Regex, recurse: bool) = + for kind, path in walkDir(dir): + if kind in [pcDir, pcLinkToDir]: + if recurse: findRec(path, pattern, recurse) + elif pattern in path: + echo path.absolutePath() + +proc find(recurse = false, rexp = false, args: seq[string]) = + var + pat = "" + rpat: Regex + for arg in args: + if not arg.startsWith("-"): + if dirExists(arg): + if rexp: + findRec(arg, rpat, recurse) + else: + findRec(arg, pat, recurse) + else: + pat = arg + if rexp: rpat = re(arg) + +when isMainModule: + dispatchMulti([ + find, help = { + "recurse": "recursive search", + "rexp": "patterns are regular expressions", + "args": "pattern1 dir1 dir2 pattern2 dir3 ..." + } + ]) -- 2.49.1 From 94b3b04e6d72d1e8f02bc116abb6e8d05a90c54e Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Mon, 5 Oct 2020 13:33:54 -0500 Subject: [PATCH 08/13] Fix build error messaging --- nimterop/build/getheader.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nimterop/build/getheader.nim b/nimterop/build/getheader.nim index 4549894..918e923 100644 --- a/nimterop/build/getheader.nim +++ b/nimterop/build/getheader.nim @@ -208,11 +208,12 @@ proc buildLibrary(lname, outdir, conFlags, cmakeFlags, makeFlags: string, buildT var lpath = findFile(lname, outdir, regex = true) makePath = outdir + buildStatus: BuildStatus + errors: seq[string] if lpath.nBl: return lpath - var buildStatus: BuildStatus for buildType in buildTypes: case buildType @@ -223,6 +224,8 @@ proc buildLibrary(lname, outdir, conFlags, cmakeFlags, makeFlags: string, buildT if buildStatus.built: break + elif buildStatus.error.nBl: + errors.add buildStatus.error if buildStatus.buildPath.len > 0: let libraryExists = findFile(lname, buildStatus.buildPath, regex = true).len > 0 @@ -231,7 +234,7 @@ proc buildLibrary(lname, outdir, conFlags, cmakeFlags, makeFlags: string, buildT make(buildStatus.buildPath, lname, makeFlags, regex = true) buildStatus.built = true - let error = if buildStatus.error.len > 0: buildStatus.error else: "No build files found in " & outdir + let error = if errors.len > 0: errors.join("\n") else: "No build files found in " & outdir doAssert buildStatus.built, &"\nBuild configuration failed - {error}\n" result = findFile(lname, outdir, regex = true) -- 2.49.1 From 0c2ca16f7ad9b1798f1c28ca0a3268d98e845a8d Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Mon, 5 Oct 2020 21:25:35 -0500 Subject: [PATCH 09/13] v0.6.12 --- nimterop.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimterop.nimble b/nimterop.nimble index 8e12ee8..6d4306c 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -1,6 +1,6 @@ # Package -version = "0.6.11" +version = "0.6.12" author = "genotrance" description = "C/C++ interop for Nim" license = "MIT" -- 2.49.1 From 0e003b5dba306143beb586231f17e013a946e4b2 Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Thu, 8 Oct 2020 23:17:43 -0500 Subject: [PATCH 10/13] Build loaf for minitest --- nimterop.nimble | 1 + 1 file changed, 1 insertion(+) diff --git a/nimterop.nimble b/nimterop.nimble index 6d4306c..9a9083f 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -49,6 +49,7 @@ task docs, "Generate docs": buildDocs(@["nimterop/all.nim"], "build/htmldocs") task minitest, "Test for Nim CI": + exec "nim c -f -d:danger nimterop/loaf.nim" exec "nim c -f -d:danger nimterop/toast" exec "nim c -f -d:checkAbi -r tests/tast2.nim" exec "nim c -f -d:checkAbi -d:zlibJBB -d:zlibSetVer=1.2.11 -r tests/zlib.nim" -- 2.49.1 From e987b50610c4756a1f5acaaba8fb865c6e0c8693 Mon Sep 17 00:00:00 2001 From: n5m <72841454+n5m@users.noreply.github.com> Date: Thu, 15 Oct 2020 13:48:39 +0000 Subject: [PATCH 11/13] ensure loaf exists before finding (#256) --- nimterop/build/shell.nim | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nimterop/build/shell.nim b/nimterop/build/shell.nim index 7c65b71..24075cf 100644 --- a/nimterop/build/shell.nim +++ b/nimterop/build/shell.nim @@ -416,8 +416,14 @@ proc findFiles*(file: string, dir: string, recurse = true, regex = false): seq[s ## `file` is a regular expression if `regex` is true ## ## Turn off recursive search with `recurse` + let + loafExe = loafExePath() + + doAssert fileExists(loafExe), "loaf not compiled: " & loafExe.sanitizePath & + " make sure 'nimble build' or 'nimble install' built it" + var - cmd = loafExePath().quoteShell & " find --rexp $1 \"$2\" $3" + cmd = loafExe.quoteShell & " find --rexp $1 \"$2\" $3" recursive = if recurse: "--recurse" else: "" var -- 2.49.1 From f7cee5c983650336f93fde5d4fea087863ac0e5e Mon Sep 17 00:00:00 2001 From: Ganesh Viswanathan Date: Thu, 15 Oct 2020 08:48:57 -0500 Subject: [PATCH 12/13] v0.6.13 --- nimterop.nimble | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nimterop.nimble b/nimterop.nimble index 9a9083f..15a8ed1 100644 --- a/nimterop.nimble +++ b/nimterop.nimble @@ -1,6 +1,6 @@ # Package -version = "0.6.12" +version = "0.6.13" author = "genotrance" description = "C/C++ interop for Nim" license = "MIT" -- 2.49.1 From b568863527d8b700922774e64a41db50f9b701cb Mon Sep 17 00:00:00 2001 From: Joey Date: Tue, 20 Oct 2020 11:08:52 -0600 Subject: [PATCH 13/13] Fix #233: make shl/shr use the direct left operand for type casting (#235) --- nimterop/toastlib/exprparser.nim | 16 +++++++++++++--- tests/include/tast2.h | 1 + tests/tast2.nim | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/nimterop/toastlib/exprparser.nim b/nimterop/toastlib/exprparser.nim index a77dbf9..a67ed59 100644 --- a/nimterop/toastlib/exprparser.nim +++ b/nimterop/toastlib/exprparser.nim @@ -379,18 +379,28 @@ proc processBinaryExpression(gState: State, node: TSNode, typeofNode: var PNode) result.add gState.getIdent(nimSym) let leftNode = gState.processTSNode(left, typeofNode) + var tyNode = typeofNode if typeofNode.isNil: typeofNode = nkCall.newTree( gState.getIdent("typeof"), leftNode ) + tyNode = typeofNode - let rightNode = gState.processTSNode(right, typeofNode) + # Special case of setting the shift left/right type + # to be the type of the direct left operand + if binarySym in [">>", "<<"]: + tyNode = nkCall.newTree( + gState.getIdent("typeof"), + leftNode + ) + + let rightNode = gState.processTSNode(right, tyNode) result.add leftNode result.add nkCall.newTree( - typeofNode, + tyNode, rightNode ) if binarySym == "/": @@ -399,7 +409,7 @@ proc processBinaryExpression(gState: State, node: TSNode, typeofNode: var PNode) # So we need to emulate C here and cast the whole # expression to the type of the first arg result = nkCall.newTree( - typeofNode, + tyNode, result ) diff --git a/tests/include/tast2.h b/tests/include/tast2.h index 38c5f18..ede71d5 100644 --- a/tests/include/tast2.h +++ b/tests/include/tast2.h @@ -35,6 +35,7 @@ extern "C" { #define EQ4 AVAL < BVAL #define EQ5 AVAL != BVAL #define EQ6 AVAL == BVAL +#define SX_NEAR_ZERO (1.0f / (1 << 28)) // testing integer out of long int range #define INT_FAST16_MIN (-9223372036854775807L-1) diff --git a/tests/tast2.nim b/tests/tast2.nim index a410de4..e301fb5 100644 --- a/tests/tast2.nim +++ b/tests/tast2.nim @@ -134,6 +134,8 @@ assert EQ4 == (AVAL < BVAL) assert EQ5 == (AVAL != BVAL) assert EQ6 == (AVAL == BVAL) +assert SX_NEAR_ZERO == 3.725290298461914e-09 + assert SIZEOF == 1 assert COERCE == 645635670332'u64 -- 2.49.1