I have a library written in Nim and I want to use it in ClojureScript since the lib written in ClojureScript is kind of slow. So I run
nim js -o:js-lib/index.js ./src/cirruParser.nim
and got a JavaScript file. Then I added exports.parseCirru = parseCirru at the end of the file for exporting the function parseCirru. It turned out to be faster than my ClojureScript version(despite that I need the data structure in ClojureScript).
I looked in to the generated code and saw something like:
framePtr = F;
F.line = 34;
var e_14207 = null;
F.line = 37;
e_14207 = {m_type: NTI3850, parent: null, name: null, message: null, trace: null, raiseId: 0, up: null};
F.line = 38;
e_14207.message = nimCopy(null, message_14066, NTI138);
F.line = 39;
raiseException(e_14207, "AssertionError");
framePtr = F.prev;
I got a question, is there something like "optimization level" in compiling to JavaScript? I'm not sure what these code means, it's like writing to F.line just with different numbers.
Also strange to me that I don't get exports.foo = funcFoo by default as I added {.exports.} since it's how most of us using JavaScript modules today.
Anything I need to know beyond tips listed on Nim Backend Integration?
Just tried as the docs says:
nim js -d:release -o:js-lib/index.js ./src/cirruParser.nim
but I got different result from previous one,
{
line: 1,
column: 0,
kind: 1,
text: null,
list: [ { line: 1, column: 2995672, kind: 1, text: null, list: [Array] } ]
}
Does -d:release change behaviors of my program?
-d:release will remove any assert calls, apart from that it shouldn't change any behaviour, so this may be a JS backend bug.
Make sure you aren't running any procedures that have side effects with assert as those statements will just be removed.