Minor fixes

This commit is contained in:
Ganesh Viswanathan 2019-01-27 17:07:20 -06:00 committed by genotrance
commit ef0a250066
5 changed files with 25 additions and 24 deletions

View file

@ -102,8 +102,8 @@ proc getToast(fullpath: string, recurse: bool = false): string =
if gStateCT.symOverride.len != 0:
cmd.add &" --symOverride={gStateCT.symOverride.join(\",\")}"
if gStateCT.pluginFile.nBl:
cmd.add &" --pluginFile={gStateCT.pluginFile.quoteShell}"
if gStateCT.pluginSourcePath.nBl:
cmd.add &" --pluginSourcePath={gStateCT.pluginSourcePath.quoteShell}"
cmd.add &" {fullpath.quoteShell}"
echo cmd
@ -130,7 +130,7 @@ macro cOverride*(body): untyped =
##
## int svGetCallerInfo(const char** fileName, int *lineNumber);
##
## This might mapped to:
## This might map to:
##
## .. code-block:: nim
##
@ -197,6 +197,8 @@ macro cPlugin*(body): untyped =
## - `nskField` for struct field names
## - `nskEnumField` for enum (field) names, though they are in the global namespace as `nskConst`
## - `nskProc` - for proc names
##
## `nimterop/plugins` is implicitly imported to provide access to standard plugin facilities.
runnableExamples:
cPlugin:
import strutils
@ -206,16 +208,15 @@ macro cPlugin*(body): untyped =
let
data = "import nimterop/plugin\n\n" & body.repr
hash = data.hash()
phash = if hash<0: -hash else: hash
path = getTempDir() / "nimterop_" & $phash & ".nim"
hash = data.hash().abs()
path = getTempDir() / "nimterop_" & $hash & ".nim"
if not fileExists(path) or gStateCT.nocache or compileOption("forceBuild"):
writeFile(path, data)
doAssert fileExists(path), "Unable to write plugin file: " & path
gStateCT.pluginFile = path
gStateCT.pluginSourcePath = path
proc cSearchPath*(path: string): string {.compileTime.}=
## Get full path to file or directory ``path`` in search path configured
@ -231,7 +232,7 @@ proc cSearchPath*(path: string): string {.compileTime.}=
if result.len == 0:
var found = false
for inc in gStateCT.searchDirs:
result = findPath(inc & "/" & path, fail = false)
result = findPath(inc / path, fail = false)
if result.len != 0:
found = true
break

View file

@ -329,18 +329,18 @@ proc dll*(path: string): string =
result = dir / (DynlibFormat % name)
proc loadPlugin*(fullpath: string) =
doAssert fileExists(fullpath), "Plugin file does not exist: " & fullpath
proc loadPlugin*(sourcePath: string) =
doAssert fileExists(sourcePath), "Plugin file does not exist: " & sourcePath
let
pdll = fullpath.dll
pdll = sourcePath.dll
if not fileExists(pdll) or
fullpath.getLastModificationTime() > pdll.getLastModificationTime():
discard execAction("nim c --app:lib " & fullpath)
doAssert fileExists(pdll), "No plugin binary generated for " & fullpath
sourcePath.getLastModificationTime() > pdll.getLastModificationTime():
discard execAction("nim c --app:lib " & sourcePath)
doAssert fileExists(pdll), "No plugin binary generated for " & sourcePath
let lib = loadLib(pdll)
doAssert lib != nil, "Plugin $1 compiled to $2 failed to load" % [fullpath, pdll]
doAssert lib != nil, "Plugin $1 compiled to $2 failed to load" % [sourcePath, pdll]
gStateRT.onSymbol = cast[onSymbolType](lib.symAddr("onSymbol"))
gStateRT.onSymbol = cast[OnSymbol](lib.symAddr("onSymbol"))
doAssert gStateRT.onSymbol != nil, "onSymbol() load failed from " & pdll

View file

@ -54,14 +54,14 @@ type
consts*, enums*, procs*, types*: HashSet[string]
constStr*, debugStr*, enumStr*, procStr*, typeStr*: string
code*, currentHeader*, mode*, pluginFile*, sourceFile*: string
code*, currentHeader*, mode*, pluginSourcePath*, sourceFile*: string
ast*: Table[string, seq[ref Ast]]
data*: seq[tuple[name, val: string]]
when not declared(CIMPORT):
grammar*: seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode) {.nimcall.}]]
onSymbol*: onSymbolType
onSymbol*: OnSymbol
var
gStateCT {.compiletime, used.}: State

View file

@ -5,4 +5,4 @@ type
name*: string
kind*: NimSymKind
onSymbolType* = proc(sym: var Symbol) {.cdecl.}
OnSymbol* = proc(sym: var Symbol) {.cdecl.}

View file

@ -113,7 +113,7 @@ proc main(
defines: seq[string] = @[],
includeDirs: seq[string] = @[],
symOverride: seq[string] = @[],
pluginFile: string = "",
pluginSourcePath: string = "",
source: seq[string],
) =
@ -128,13 +128,13 @@ proc main(
defines: defines,
includeDirs: includeDirs,
symOverride: symOverride,
pluginFile: pluginFile
pluginSourcePath: pluginSourcePath
)
gStateRT.symOverride = gStateRT.symOverride.getSplitComma()
if pluginFile.nBl:
loadPlugin(pluginFile)
if pluginSourcePath.nBl:
loadPlugin(pluginSourcePath)
if pgrammar:
parseGrammar()
@ -151,7 +151,7 @@ when isMainModule:
"defines": "definitions to pass to preprocessor",
"includeDirs": "include directory to pass to preprocessor",
"symOverride": "skip generating specified symbols",
"pluginFile": "Nim file to build and load as a plugin",
"pluginSourcePath": "Nim file to build and load as a plugin",
"preprocess": "run preprocessor on header",
"pgrammar": "print grammar",
"recurse": "process #include files",