parent
731398c988
commit
5f70b01302
1 changed files with 11 additions and 6 deletions
|
|
@ -7,6 +7,11 @@ import "."/[getters, globals, lisp, treesitter/runtime]
|
||||||
type
|
type
|
||||||
Grammar = seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode, nimState: NimState) {.nimcall.}]]
|
Grammar = seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode, nimState: NimState) {.nimcall.}]]
|
||||||
|
|
||||||
|
proc genImportC(origName, nimName: string): string =
|
||||||
|
result = "importc"
|
||||||
|
if nimName != origName:
|
||||||
|
result.add &": \"{origName}\"" # used as {.importc: "foo".}
|
||||||
|
|
||||||
proc initGrammar(): Grammar =
|
proc initGrammar(): Grammar =
|
||||||
# #define X Y
|
# #define X Y
|
||||||
result.add(("""
|
result.add(("""
|
||||||
|
|
@ -166,6 +171,7 @@ proc initGrammar(): Grammar =
|
||||||
nimState.typeStr &= &"\n {name}* = {getPtrType(tptr&typ)}"
|
nimState.typeStr &= &"\n {name}* = {getPtrType(tptr&typ)}"
|
||||||
))
|
))
|
||||||
|
|
||||||
|
|
||||||
proc pDupTypeCommon(nname: string, fend: int, nimState: NimState, isEnum=false) =
|
proc pDupTypeCommon(nname: string, fend: int, nimState: NimState, isEnum=false) =
|
||||||
var
|
var
|
||||||
dname = nimState.data[^1].val
|
dname = nimState.data[^1].val
|
||||||
|
|
@ -183,7 +189,7 @@ proc initGrammar(): Grammar =
|
||||||
else:
|
else:
|
||||||
if nimState.identifiers.addNewIdentifer(ndname):
|
if nimState.identifiers.addNewIdentifer(ndname):
|
||||||
nimState.typeStr &=
|
nimState.typeStr &=
|
||||||
&"\n {ndname}* {{.importc: \"{dname}\", header: {nimState.currentHeader}, bycopy.}} = {dptr}{nname}"
|
&"\n {ndname}* {{.{genImportC(dname, ndname)}, header: {nimState.currentHeader}, bycopy.}} = {dptr}{nname}"
|
||||||
|
|
||||||
proc pStructCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int, nimState: NimState) =
|
proc pStructCommon(ast: ref Ast, node: TSNode, name: string, fstart, fend: int, nimState: NimState) =
|
||||||
var
|
var
|
||||||
|
|
@ -217,7 +223,8 @@ proc initGrammar(): Grammar =
|
||||||
if nimState.data.len == 1:
|
if nimState.data.len == 1:
|
||||||
nimState.typeStr &= &"\n {nname}* {{.bycopy.}} = object{union}"
|
nimState.typeStr &= &"\n {nname}* {{.bycopy.}} = object{union}"
|
||||||
else:
|
else:
|
||||||
nimState.typeStr &= &"\n {nname}* {{.importc: \"{prefix}{name}\", header: {nimState.currentHeader}, bycopy.}} = object{union}"
|
let importCDecl = genImportC(prefix & name, nname)
|
||||||
|
nimState.typeStr &= &"\n {nname}* {{.{importCDecl}, header: {nimState.currentHeader}, bycopy.}} = object{union}"
|
||||||
|
|
||||||
var
|
var
|
||||||
i = fstart
|
i = fstart
|
||||||
|
|
@ -491,12 +498,10 @@ proc initGrammar(): Grammar =
|
||||||
|
|
||||||
if fnname.nBl and nimState.identifiers.addNewIdentifer(fnname):
|
if fnname.nBl and nimState.identifiers.addNewIdentifer(fnname):
|
||||||
let ftyp = nimState.data[0].val.getIdentifier(nskType, fnname)
|
let ftyp = nimState.data[0].val.getIdentifier(nskType, fnname)
|
||||||
|
|
||||||
if fptr == "ptr " or ftyp != "object":
|
if fptr == "ptr " or ftyp != "object":
|
||||||
nimState.procStr &= &"\nproc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.importc: \"{fname}\", header: {nimState.currentHeader}.}}"
|
nimState.procStr &= &"\nproc {fnname}*({pout}): {getPtrType(fptr&ftyp)} {{.{genImportC(fname, fnname)}, header: {nimState.currentHeader}.}}"
|
||||||
else:
|
else:
|
||||||
nimState.procStr &= &"\nproc {fnname}*({pout}) {{.importc: \"{fname}\", header: {nimState.currentHeader}.}}"
|
nimState.procStr &= &"\nproc {fnname}*({pout}) {{.{genImportC(fname, fnname)}, header: {nimState.currentHeader}.}}"
|
||||||
|
|
||||||
))
|
))
|
||||||
|
|
||||||
proc initRegex(ast: ref Ast) =
|
proc initRegex(ast: ref Ast) =
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue