Compare commits

..

8 commits

Author SHA1 Message Date
Joey Yakimowich-Payne
fa9e66b4a3 Update cligen 2021-05-15 18:39:47 -06:00
Joey
a9b92647f3
Merge pull request #1 from nimterop/master
merge from upstream
2021-01-22 21:38:37 -07:00
Joey
b568863527
Fix #233: make shl/shr use the direct left operand for type casting (#235) 2020-10-20 12:08:52 -05:00
Joey Yakimowich-Payne
217bce386a Don't die on nimcheck for cached files 2020-09-17 19:59:41 -06:00
Joey Yakimowich-Payne
1b8aa46b8a Improve on getdefine 2020-09-12 15:36:37 -06:00
Joey Yakimowich-Payne
316a56107a Add ability to get a define value 2020-09-12 12:48:45 -06:00
Joey Yakimowich-Payne
00941e8925 Fix regen issues windows/linux 2020-09-12 10:59:14 -06:00
Joey Yakimowich-Payne
93c83728c7 Fix nimterop imports 2020-09-08 19:34:24 -06:00
5 changed files with 58 additions and 5 deletions

View file

@ -9,7 +9,7 @@ bin = @["nimterop/toast", "nimterop/loaf"]
installDirs = @["nimterop"]
# Dependencies
requires "nim >= 0.20.2", "regex >= 0.15.0", "cligen >= 1.0.0"
requires "nim >= 0.20.2", "regex >= 0.15.0", "cligen >= 1.5.3"
import nimterop/docs
import os

View file

@ -59,6 +59,17 @@ macro isDefined*(def: untyped): untyped =
false
)
macro getDefine*(def: untyped): untyped =
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):
result = "[0-9.\\-]*\\.dll"

View file

@ -206,13 +206,13 @@ 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}"
(result, ret) = execAction(cmd)
(result, ret) = execAction(cmd, die=false)
proc touchFile*(fullpath: string) =
## Touch file to update modified date

42
nimterop/enumtypepub.nim Normal file
View file

@ -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.}

View file

@ -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