Minor fixes
This commit is contained in:
parent
6adf7f075a
commit
3df901d2f0
5 changed files with 25 additions and 24 deletions
|
|
@ -102,8 +102,8 @@ proc getToast(fullpath: string, recurse: bool = false): string =
|
||||||
if gStateCT.symOverride.len != 0:
|
if gStateCT.symOverride.len != 0:
|
||||||
cmd.add &" --symOverride={gStateCT.symOverride.join(\",\")}"
|
cmd.add &" --symOverride={gStateCT.symOverride.join(\",\")}"
|
||||||
|
|
||||||
if gStateCT.pluginFile.nBl:
|
if gStateCT.pluginSourcePath.nBl:
|
||||||
cmd.add &" --pluginFile={gStateCT.pluginFile.quoteShell}"
|
cmd.add &" --pluginSourcePath={gStateCT.pluginSourcePath.quoteShell}"
|
||||||
|
|
||||||
cmd.add &" {fullpath.quoteShell}"
|
cmd.add &" {fullpath.quoteShell}"
|
||||||
echo cmd
|
echo cmd
|
||||||
|
|
@ -130,7 +130,7 @@ macro cOverride*(body): untyped =
|
||||||
##
|
##
|
||||||
## int svGetCallerInfo(const char** fileName, int *lineNumber);
|
## int svGetCallerInfo(const char** fileName, int *lineNumber);
|
||||||
##
|
##
|
||||||
## This might mapped to:
|
## This might map to:
|
||||||
##
|
##
|
||||||
## .. code-block:: nim
|
## .. code-block:: nim
|
||||||
##
|
##
|
||||||
|
|
@ -197,6 +197,8 @@ macro cPlugin*(body): untyped =
|
||||||
## - `nskField` for struct field names
|
## - `nskField` for struct field names
|
||||||
## - `nskEnumField` for enum (field) names, though they are in the global namespace as `nskConst`
|
## - `nskEnumField` for enum (field) names, though they are in the global namespace as `nskConst`
|
||||||
## - `nskProc` - for proc names
|
## - `nskProc` - for proc names
|
||||||
|
##
|
||||||
|
## `nimterop/plugins` is implicitly imported to provide access to standard plugin facilities.
|
||||||
runnableExamples:
|
runnableExamples:
|
||||||
cPlugin:
|
cPlugin:
|
||||||
import strutils
|
import strutils
|
||||||
|
|
@ -206,16 +208,15 @@ macro cPlugin*(body): untyped =
|
||||||
|
|
||||||
let
|
let
|
||||||
data = "import nimterop/plugin\n\n" & body.repr
|
data = "import nimterop/plugin\n\n" & body.repr
|
||||||
hash = data.hash()
|
hash = data.hash().abs()
|
||||||
phash = if hash<0: -hash else: hash
|
path = getTempDir() / "nimterop_" & $hash & ".nim"
|
||||||
path = getTempDir() / "nimterop_" & $phash & ".nim"
|
|
||||||
|
|
||||||
if not fileExists(path) or gStateCT.nocache or compileOption("forceBuild"):
|
if not fileExists(path) or gStateCT.nocache or compileOption("forceBuild"):
|
||||||
writeFile(path, data)
|
writeFile(path, data)
|
||||||
|
|
||||||
doAssert fileExists(path), "Unable to write plugin file: " & path
|
doAssert fileExists(path), "Unable to write plugin file: " & path
|
||||||
|
|
||||||
gStateCT.pluginFile = path
|
gStateCT.pluginSourcePath = path
|
||||||
|
|
||||||
proc cSearchPath*(path: string): string {.compileTime.}=
|
proc cSearchPath*(path: string): string {.compileTime.}=
|
||||||
## Get full path to file or directory ``path`` in search path configured
|
## 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:
|
if result.len == 0:
|
||||||
var found = false
|
var found = false
|
||||||
for inc in gStateCT.searchDirs:
|
for inc in gStateCT.searchDirs:
|
||||||
result = findPath(inc & "/" & path, fail = false)
|
result = findPath(inc / path, fail = false)
|
||||||
if result.len != 0:
|
if result.len != 0:
|
||||||
found = true
|
found = true
|
||||||
break
|
break
|
||||||
|
|
|
||||||
|
|
@ -329,18 +329,18 @@ proc dll*(path: string): string =
|
||||||
|
|
||||||
result = dir / (DynlibFormat % name)
|
result = dir / (DynlibFormat % name)
|
||||||
|
|
||||||
proc loadPlugin*(fullpath: string) =
|
proc loadPlugin*(sourcePath: string) =
|
||||||
doAssert fileExists(fullpath), "Plugin file does not exist: " & fullpath
|
doAssert fileExists(sourcePath), "Plugin file does not exist: " & sourcePath
|
||||||
|
|
||||||
let
|
let
|
||||||
pdll = fullpath.dll
|
pdll = sourcePath.dll
|
||||||
if not fileExists(pdll) or
|
if not fileExists(pdll) or
|
||||||
fullpath.getLastModificationTime() > pdll.getLastModificationTime():
|
sourcePath.getLastModificationTime() > pdll.getLastModificationTime():
|
||||||
discard execAction("nim c --app:lib " & fullpath)
|
discard execAction("nim c --app:lib " & sourcePath)
|
||||||
doAssert fileExists(pdll), "No plugin binary generated for " & fullpath
|
doAssert fileExists(pdll), "No plugin binary generated for " & sourcePath
|
||||||
|
|
||||||
let lib = loadLib(pdll)
|
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
|
doAssert gStateRT.onSymbol != nil, "onSymbol() load failed from " & pdll
|
||||||
|
|
|
||||||
|
|
@ -54,14 +54,14 @@ type
|
||||||
|
|
||||||
consts*, enums*, procs*, types*: HashSet[string]
|
consts*, enums*, procs*, types*: HashSet[string]
|
||||||
constStr*, debugStr*, enumStr*, procStr*, typeStr*: 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]]
|
ast*: Table[string, seq[ref Ast]]
|
||||||
data*: seq[tuple[name, val: string]]
|
data*: seq[tuple[name, val: string]]
|
||||||
when not declared(CIMPORT):
|
when not declared(CIMPORT):
|
||||||
grammar*: seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode) {.nimcall.}]]
|
grammar*: seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode) {.nimcall.}]]
|
||||||
|
|
||||||
onSymbol*: onSymbolType
|
onSymbol*: OnSymbol
|
||||||
|
|
||||||
var
|
var
|
||||||
gStateCT {.compiletime, used.}: State
|
gStateCT {.compiletime, used.}: State
|
||||||
|
|
|
||||||
|
|
@ -5,4 +5,4 @@ type
|
||||||
name*: string
|
name*: string
|
||||||
kind*: NimSymKind
|
kind*: NimSymKind
|
||||||
|
|
||||||
onSymbolType* = proc(sym: var Symbol) {.cdecl.}
|
OnSymbol* = proc(sym: var Symbol) {.cdecl.}
|
||||||
10
toast.nim
10
toast.nim
|
|
@ -113,7 +113,7 @@ proc main(
|
||||||
defines: seq[string] = @[],
|
defines: seq[string] = @[],
|
||||||
includeDirs: seq[string] = @[],
|
includeDirs: seq[string] = @[],
|
||||||
symOverride: seq[string] = @[],
|
symOverride: seq[string] = @[],
|
||||||
pluginFile: string = "",
|
pluginSourcePath: string = "",
|
||||||
source: seq[string],
|
source: seq[string],
|
||||||
) =
|
) =
|
||||||
|
|
||||||
|
|
@ -128,13 +128,13 @@ proc main(
|
||||||
defines: defines,
|
defines: defines,
|
||||||
includeDirs: includeDirs,
|
includeDirs: includeDirs,
|
||||||
symOverride: symOverride,
|
symOverride: symOverride,
|
||||||
pluginFile: pluginFile
|
pluginSourcePath: pluginSourcePath
|
||||||
)
|
)
|
||||||
|
|
||||||
gStateRT.symOverride = gStateRT.symOverride.getSplitComma()
|
gStateRT.symOverride = gStateRT.symOverride.getSplitComma()
|
||||||
|
|
||||||
if pluginFile.nBl:
|
if pluginSourcePath.nBl:
|
||||||
loadPlugin(pluginFile)
|
loadPlugin(pluginSourcePath)
|
||||||
|
|
||||||
if pgrammar:
|
if pgrammar:
|
||||||
parseGrammar()
|
parseGrammar()
|
||||||
|
|
@ -151,7 +151,7 @@ when isMainModule:
|
||||||
"defines": "definitions to pass to preprocessor",
|
"defines": "definitions to pass to preprocessor",
|
||||||
"includeDirs": "include directory to pass to preprocessor",
|
"includeDirs": "include directory to pass to preprocessor",
|
||||||
"symOverride": "skip generating specified symbols",
|
"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",
|
"preprocess": "run preprocessor on header",
|
||||||
"pgrammar": "print grammar",
|
"pgrammar": "print grammar",
|
||||||
"recurse": "process #include files",
|
"recurse": "process #include files",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue