I have a project https://github.com/calcit-lang/ternary-tree/blob/master/src/ternary_tree/list.nim#L831 and I wanted to compiled it to js. I tried and figured out I have to add {.exportc.} and then I got this error:
/Users/chen/repo/others/Nim/compiler/nim.nim(119) nim
/Users/chen/repo/others/Nim/compiler/nim.nim(84) handleCmdLine
/Users/chen/repo/others/Nim/compiler/main.nim(231) mainCommand
/Users/chen/repo/others/Nim/compiler/main.nim(204) compileToBackend
/Users/chen/repo/others/Nim/compiler/main.nim(118) commandCompileToJS
/Users/chen/repo/others/Nim/compiler/modules.nim(163) compileProject
/Users/chen/repo/others/Nim/compiler/modules.nim(91) compileModule
/Users/chen/repo/others/Nim/compiler/passes.nim(202) processModule
/Users/chen/repo/others/Nim/compiler/passes.nim(73) processTopLevelStmt
/Users/chen/repo/others/Nim/compiler/jsgen.nim(2667) myProcess
/Users/chen/repo/others/Nim/compiler/jsgen.nim(2654) genModule
/Users/chen/repo/others/Nim/compiler/jsgen.nim(2403) genStmt
/Users/chen/repo/others/Nim/compiler/jsgen.nim(2581) gen
/Users/chen/repo/others/Nim/compiler/jsgen.nim(1435) genSym
/Users/chen/repo/others/Nim/compiler/jsgen.nim(1364) genProcForSymIfNeeded
/Users/chen/repo/others/Nim/compiler/jsgen.nim(2334) genProc
/Users/chen/repo/others/Nim/lib/system/fatal.nim(49) sysFatal
Error: unhandled exception: index 7 not in 0 .. 6 [IndexDefect]
tried to read source code, not much information...
then I tried to export a very simple function, it worked.
proc add*(a, b: int): int {.exportc.} =
a + 1
So I guessed maybe generics is not supported in such a case?
proc add*[T](a, b: TernaryTreeList[T]): int {.exportc.} =
3 + 1
now I got same error again. So it's really not supported?
If you try another generic structure like seq, etc... what happens? These errors remind me of ones I've encountered before when working with JS but my memory is fuzzy.
For JS I've done exports with a JSObject, and that might work better.
Code that using seq looks fine.
proc count*(args: seq[int]): int {.exportc.} =
return 1
I guess add*[T] might be the special case.
yep.. that's what IndexDefect says.
I was wondering if that was a not-implemented-yet feature. js is dynamic and hard to say what should such code be compiled to...(not sure whether the author of that commit could see this..)