cleanup importjs implementation

This commit is contained in:
Andreas Rumpf 2019-09-21 11:19:00 +02:00
commit b04ef2973d
2 changed files with 9 additions and 13 deletions

View file

@ -100,7 +100,10 @@ iterator myitems[T](x: openarray[T]): lent T
iterator mypairs[T](x: openarray[T]): tuple[idx: int, val: lent T] iterator mypairs[T](x: openarray[T]): tuple[idx: int, val: lent T]
``` ```
- `importjs` can now be used to import for ffi on the JS target - Added an `importjs` pragma that can now be used instead of `importcpp`
and `importc` to import symbols from JavaScript. `importjs` for routines always
takes a "pattern" for maximum flexibility.
## Language changes ## Language changes

View file

@ -805,20 +805,13 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
processImportCpp(c, sym, getOptionalStr(c, it, "$1"), it.info) processImportCpp(c, sym, getOptionalStr(c, it, "$1"), it.info)
of wImportJs: of wImportJs:
if c.config.cmd != cmdCompileToJS: if c.config.cmd != cmdCompileToJS:
localError(c.config, it.info, "importjs pragma only supported when compiling to js.") localError(c.config, it.info, "`importjs` pragma requires the JavaScript target")
var strArg: PNode = nil let name = getOptionalStr(c, it, "$1")
if it.kind in nkPragmaCallKinds:
strArg = it[1]
if strArg.kind notin {nkStrLit..nkTripleStrLit}:
localError(c.config, it.info, errStringLiteralExpected)
incl(sym.flags, sfImportc) incl(sym.flags, sfImportc)
incl(sym.flags, sfInfixCall) incl(sym.flags, sfInfixCall)
if strArg == nil: if sym.kind in skProcKinds and {'(', '#', '@'} notin name:
if sym.kind in skProcKinds: localError(c.config, n.info, "`importjs` for routines requires a pattern")
message(c.config, n.info, warnDeprecated, "procedure import should have an import pattern") setExternName(c, sym, name, it.info)
setExternName(c, sym, sym.name.s, it.info)
else:
setExternName(c, sym, strArg.strVal, it.info)
of wImportObjC: of wImportObjC:
processImportObjC(c, sym, getOptionalStr(c, it, "$1"), it.info) processImportObjC(c, sym, getOptionalStr(c, it, "$1"), it.info)
of wAlign: of wAlign: