As mentioned in the nimrod compiler user guide the javascript target doesn't support file management. For example trying to import strtabs will then fail since it depends on the os module which includes file procs.
While such files could be sprinkled with when not defined(js) blocks, maybe such modules should use a subset define like when not fsAvailable which would be more generic and also of use in embedded environments? The same document mentions defines for embedded systems but is javascript an embedded target or just one which lacks file management?
Also, what would be the correct way to patch the standard library, remove the problematic procs or provide dummy procs or wrappers which may do similar things to the original (eg: echo in js does append strings to the HTML body, while I thought it would just log to the debug console somehow).
Also, what would be the correct way to patch the standard library...?
Depends on the particular patch, but don't bother to make the whole stdlib "JS compatible". It's not feasible. What should be made to work however are the collection and string handling libraries.
Ah that's what you're after. Well a dummy wrapper for TFile looks like a good idea. We could even go further and provide a small file system emulation layer so that writeFile("foo.txt", "test"); echo readFile("foo.txt") produces "test". But then we end up emulating os.getEnv for strtabs and perhaps createDir for the compiler ... I don't know. Could be great for porting, could be horrible. But if we go that route, symbols like fsAvailable or emulateFS make sense.
Or maybe move the IO related procs to a submodule breaking current code, so in the future rstgen only works on memory and rstgen_io has the additional js incompatible procs?
We can also make rstgen work on streams and provide a streams implementation for JS. I think it can be done without breaking code when you provide a new rstgen_streams module that rstgen uses (use export perhaps?).
So the essence is: I don't know. Emulation surely makes lots of sense when we're after porting Nimrod's tooling.
Why do you guys not just compiled to C -> use emscripten, skip the whole writing the JS backend yourself?