cleanup importjs implementation

This commit is contained in:
Andreas Rumpf
2019-09-21 11:19:00 +02:00
parent be82d11576
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]
```
- `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

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