Recently, I saw this news: a new stdlib for Golang which removes the Go runtime, produce small binaries and should be mostly compatible with C. Go is known to have a really good HTTP implementation so that it is used in various production grade reverse proxies. Perhaps we could interface this code to Nim using a C wrapper and the stdlib just mentioned.
This is just a crazy idea but perhaps we could gain a good HTTP implementation this way.
a new stdlib for Golang
Kinda like https://github.com/juancarlospaco/cpython and https://github.com/juancarlospaco/nodejs
I mentioned it on discord a couple of times, but a non ideal idea for filling the ecosystem would be to write a typescript .d.ts file parser. With a bridge you could use them in the backend when targeting c/cpp (think of non-perf critical libs like redis, mongo, etc. although maybe bun is fast enough?) and on the frontend you just use them ad-hoc.
Something like this but at Nim's comp time: https://github.com/fable-compiler/ts2fable
But the problem is that the types will not match, eg a string in JS and TS will be actually an array of int in the generated JS of Nim etc.
So it's mapped to a cstring. A minor detail if we go from a small ecosystem to the whole TS ecosystem.
But the problem is that the types will not match, eg a string in JS and TS will be actually an array of int in the generated JS of Nim etc.
It could be solved by improving macro system, so it would transform the whole source AST. It may work as follows, at the top of the .nim file you specify
rules: js_runtime
echo "hi" # will be translated to JString.init("hi")
And the rules js_runtime.nim contains bunch of macros to be applied to nim sources
Pseudocode: replace any string `"anything"` into `JString.init("anything")`
# Also, you may add `fmt` by default,
Pseudocode: replace any string `"anything"` into `fmt"anything"`
And you write jstring.nim implementation.
With this approach you'll have seamless Nim interoperability with any library, like React, etc, it should even work with transpilers like Svelte.
The downside you won't be able to use Nim libraries that use string and don't use the js_runtime rules. But that's ok, as you barely need any Nim server side library in JS land.
You can already write custom backends with Nim's macro system, no new feature required.
Btw your rewrite rules are hopelessly naive.
I actually did something like that with Babel AST post-processing for CoffeeScript. And turned it into something like Ruby, with overloadable operators, safe built-in type extensions etc. it worked ok.
In JS you can replace any built-in objects with custom impl, and have things like 'o' in "some" and it will be translated into MyString("some").has('o'). Or, you can use Symbols and translate it into "some"[has_sym]('o') (even if the built-in prototype extended, it's still safe because JS symbols are unique).
I eventually given up, because I like type safety, and I don't know how to do the same with TypeScript and VSCode autocomplete.
Maybe in Nim there's more things to consider to achieve something similar, but in JS it worked more or less well....