Fix execAction, enum expressions, union cleanup, no forceClean
This commit is contained in:
parent
3e9dc2fb0f
commit
e293172cf2
5 changed files with 61 additions and 16 deletions
|
|
@ -45,7 +45,7 @@ proc execAction*(cmd: string, retry = 0, nostderr = false): string =
|
||||||
sleep(500)
|
sleep(500)
|
||||||
result = execAction(cmd, retry = retry - 1)
|
result = execAction(cmd, retry = retry - 1)
|
||||||
else:
|
else:
|
||||||
doAssert true, "Command failed: " & $(ret, nostderr) & "\ncmd: " & ccmd & "\nresult:\n" & result
|
doAssert false, "Command failed: " & $(ret, nostderr) & "\ncmd: " & ccmd & "\nresult:\n" & result
|
||||||
|
|
||||||
proc findExe*(exe: string): string =
|
proc findExe*(exe: string): string =
|
||||||
## Find the specified executable using the `which`/`where` command - supported
|
## Find the specified executable using the `which`/`where` command - supported
|
||||||
|
|
@ -148,6 +148,7 @@ proc getProjectCacheDir*(name: string, forceClean = true): string =
|
||||||
result = getNimteropCacheDir() / name
|
result = getNimteropCacheDir() / name
|
||||||
|
|
||||||
if forceClean and compileOption("forceBuild"):
|
if forceClean and compileOption("forceBuild"):
|
||||||
|
echo "# Removing " & result
|
||||||
rmDir(result)
|
rmDir(result)
|
||||||
|
|
||||||
proc extractZip*(zipfile, outdir: string) =
|
proc extractZip*(zipfile, outdir: string) =
|
||||||
|
|
|
||||||
|
|
@ -332,12 +332,54 @@ proc getPxName*(node: TSNode, offset: int): string =
|
||||||
if count == offset and not np.tsNodeIsNull():
|
if count == offset and not np.tsNodeIsNull():
|
||||||
return $np.tsNodeType()
|
return $np.tsNodeType()
|
||||||
|
|
||||||
proc getNimExpression*(expr: string): string =
|
proc getNimExpression*(nimState: NimState, expr: string): string =
|
||||||
return expr.multiReplace([
|
var
|
||||||
(" ", ""),
|
clean = expr.multiReplace([("\n", " "), ("\r", "")])
|
||||||
("<<", " shl "), (">>", " shr "),
|
ident = ""
|
||||||
("^", " xor "), ("&", " and "), ("|", " or "),
|
gen = ""
|
||||||
("~", " not "), ("\n", " "), ("\r", "")
|
hex = false
|
||||||
|
|
||||||
|
for i in 0 .. clean.len:
|
||||||
|
if i != clean.len:
|
||||||
|
if clean[i] == '_' and ident.len == 0:
|
||||||
|
gen = $clean[i]
|
||||||
|
elif clean[i] in IdentChars:
|
||||||
|
if clean[i] in Digits and ident.len == 0:
|
||||||
|
gen = $clean[i]
|
||||||
|
elif clean[i] in HexDigits and hex == true:
|
||||||
|
gen = $clean[i]
|
||||||
|
elif i > 0 and i < clean.len-1 and clean[i] in ['x', 'X'] and
|
||||||
|
clean[i-1] == '0' and clean[i+1] in HexDigits:
|
||||||
|
gen = $clean[i]
|
||||||
|
hex = true
|
||||||
|
else:
|
||||||
|
ident &= clean[i]
|
||||||
|
hex = false
|
||||||
|
else:
|
||||||
|
gen = (block:
|
||||||
|
if (i == 0 or clean[i-1] != '\'') or
|
||||||
|
(i == clean.len - 1 or clean[i+1] != '\''):
|
||||||
|
case clean[i]
|
||||||
|
of '^': " xor "
|
||||||
|
of '&': " and "
|
||||||
|
of '|': " or "
|
||||||
|
of '~': " not "
|
||||||
|
else: $clean[i]
|
||||||
|
else:
|
||||||
|
$clean[i]
|
||||||
|
)
|
||||||
|
hex = false
|
||||||
|
|
||||||
|
if i == clean.len or gen.len != 0:
|
||||||
|
if ident.len != 0:
|
||||||
|
ident = nimState.getIdentifier(ident, nskConst)
|
||||||
|
result &= ident
|
||||||
|
ident = ""
|
||||||
|
result &= gen
|
||||||
|
gen = ""
|
||||||
|
|
||||||
|
result = result.multiReplace([
|
||||||
|
("<<", " shl "), (">>", " shr ")
|
||||||
])
|
])
|
||||||
|
|
||||||
proc getSplitComma*(joined: seq[string]): seq[string] =
|
proc getSplitComma*(joined: seq[string]): seq[string] =
|
||||||
|
|
|
||||||
|
|
@ -238,7 +238,7 @@ proc initGrammar(): Grammar =
|
||||||
prefix = "struct "
|
prefix = "struct "
|
||||||
of "union_specifier":
|
of "union_specifier":
|
||||||
prefix = "union "
|
prefix = "union "
|
||||||
union = " {.union.}"
|
union = ", union"
|
||||||
of "type_definition":
|
of "type_definition":
|
||||||
if node.getTSNodeNamedChildCountSansComments() != 0:
|
if node.getTSNodeNamedChildCountSansComments() != 0:
|
||||||
for i in 0 .. node.tsNodeNamedChildCount()-1:
|
for i in 0 .. node.tsNodeNamedChildCount()-1:
|
||||||
|
|
@ -252,23 +252,25 @@ proc initGrammar(): Grammar =
|
||||||
of "union_specifier":
|
of "union_specifier":
|
||||||
if fstart == 1:
|
if fstart == 1:
|
||||||
prefix = "union "
|
prefix = "union "
|
||||||
union = " {.union.}"
|
union = ", union"
|
||||||
break
|
break
|
||||||
|
|
||||||
if nname.nBl and nimState.addNewIdentifer(nname):
|
if nname.nBl and nimState.addNewIdentifer(nname):
|
||||||
if nimState.data.len == 1:
|
if nimState.data.len == 1:
|
||||||
nimState.typeStr &= &"{nimState.getComments()}\n {nname}* {{.bycopy.}} = object{union}"
|
nimState.typeStr &= &"{nimState.getComments()}\n {nname}* {{.bycopy{union}.}} = object"
|
||||||
else:
|
else:
|
||||||
var
|
var
|
||||||
pragmas: seq[string] = @[]
|
pragmas: seq[string] = @[]
|
||||||
if nimState.gState.dynlib.len == 0:
|
if nimState.gState.dynlib.len == 0:
|
||||||
pragmas.add nimState.getImportC(prefix & name, nname)
|
pragmas.add nimState.getImportC(prefix & name, nname)
|
||||||
pragmas.add "bycopy"
|
pragmas.add "bycopy"
|
||||||
|
if union.len != 0:
|
||||||
|
pragmas.add "union"
|
||||||
|
|
||||||
let
|
let
|
||||||
pragma = nimState.getPragma(pragmas)
|
pragma = nimState.getPragma(pragmas)
|
||||||
|
|
||||||
nimState.typeStr &= &"{nimState.getComments()}\n {nname}*{pragma} = object{union}"
|
nimState.typeStr &= &"{nimState.getComments()}\n {nname}*{pragma} = object"
|
||||||
|
|
||||||
var
|
var
|
||||||
i = fstart
|
i = fstart
|
||||||
|
|
@ -283,7 +285,7 @@ proc initGrammar(): Grammar =
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if nimState.data[i].name notin ["field_identifier", "pointer_declarator", "array_pointer_declarator"]:
|
if nimState.data[i].name notin ["field_identifier", "pointer_declarator", "array_pointer_declarator"]:
|
||||||
ftyp = nimState.data[i].val.getType()
|
ftyp = nimState.getIdentifier(nimState.data[i].val, nskType, nname).getType()
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
while i < nimState.data.len-fend and "pointer" in nimState.data[i].name:
|
while i < nimState.data.len-fend and "pointer" in nimState.data[i].name:
|
||||||
|
|
@ -299,7 +301,7 @@ proc initGrammar(): Grammar =
|
||||||
|
|
||||||
if i+1 < nimState.data.len-fend and nimState.data[i+1].name in gEnumVals:
|
if i+1 < nimState.data.len-fend and nimState.data[i+1].name in gEnumVals:
|
||||||
let
|
let
|
||||||
flen = nimState.data[i+1].val.getNimExpression()
|
flen = nimState.getNimExpression(nimState.data[i+1].val)
|
||||||
nimState.typeStr &= &"{nimState.getComments()}\n {fname}*: {aptr}array[{flen}, {getPtrType(fptr&ftyp)}]"
|
nimState.typeStr &= &"{nimState.getComments()}\n {fname}*: {aptr}array[{flen}, {getPtrType(fptr&ftyp)}]"
|
||||||
i += 2
|
i += 2
|
||||||
elif i+1 < nimState.data.len-fend and nimState.data[i+1].name == "bitfield_clause":
|
elif i+1 < nimState.data.len-fend and nimState.data[i+1].name == "bitfield_clause":
|
||||||
|
|
@ -461,7 +463,7 @@ proc initGrammar(): Grammar =
|
||||||
if i+1 < nimState.data.len-fend and
|
if i+1 < nimState.data.len-fend and
|
||||||
nimState.data[i+1].name in gEnumVals:
|
nimState.data[i+1].name in gEnumVals:
|
||||||
if fname.nBl and nimState.addNewIdentifer(fname):
|
if fname.nBl and nimState.addNewIdentifer(fname):
|
||||||
nimState.constStr &= &"{nimState.getComments()}\n {fname}* = ({nimState.data[i+1].val.getNimExpression()}).{nname}"
|
nimState.constStr &= &"{nimState.getComments()}\n {fname}* = ({nimState.getNimExpression(nimState.data[i+1].val)}).{nname}"
|
||||||
try:
|
try:
|
||||||
count = nimState.data[i+1].val.parseInt() + 1
|
count = nimState.data[i+1].val.parseInt() + 1
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import os
|
||||||
import "."/build
|
import "."/build
|
||||||
|
|
||||||
const
|
const
|
||||||
cacheDir* = getProjectCacheDir("nimterop")
|
cacheDir* = getProjectCacheDir("nimterop", forceClean = false)
|
||||||
|
|
||||||
proc nimteropRoot*(): string =
|
proc nimteropRoot*(): string =
|
||||||
currentSourcePath.parentDir.parentDir
|
currentSourcePath.parentDir.parentDir
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue