checking out the latest in the JS flavor of the month and came really impressed with bun.sh
they even shoutout nimlang in the docs, hwoever, unfortunately only provide examples for Rust and Zig (bun is developed in zig)
Thats good news - i suppose they want the nim-stdlib, cos Zig cannot provide such, yet :)
As i'm working on improving the QuickJS4Nim-project i'd say - lets have a nice competition here.
class SomeClass:
static:
const someConst = 42
var counter: int
# class-member-fn
method getCounter(): int = SomeClass.counter
var x: int # defines a instance var
# constructor
method init(): SomeClass = returns a instance
method add( this: SomeClass, y: int ) = this.x += y
The code above is a blueprint for a JS-Class. The code will never be used on the Nim-side. It's scanned by a macro and then produces a JS-Class including : de-/allocation on the JS-side, registration of the class, etc by calling the QuickJS-APIs. A opaque Nim-Type works almost the same. It registers a opaque-type with the VM including allocation/deallocation, ctor, etc. If somebody would know a way to scan the surface of a nim-module with a macro. Then one could save most of the following declarations for e.g. a PackedSet/IntSet :
NimType IntSet :
static:
method init*() :IntSet =
result = initIntSet()
method from*( val: JSValue ) :IntSet =
echo "static::fromIter"
method IntSet*( ctx: JSContext, args: varargs[int] ) :IntSet =
var iset = IntSet_init()
for v in args :
iset.incl v
let t = JSIntSet()
result = iset
# QuickJS implements operator-overloading
method `-`*( this: var IntSet, other: IntSet ) =
echo "operator minus"
intsets.excl this, other
method `+`*( this: var IntSet, other: IntSet ) =
echo "operator plus"
intsets.incl this,other
method `()`*( this, other: IntSet ) :IntSet =
echo "call-operator"
method incl*( this: var IntSet, other :IntSet ) =
intsets.incl this, other
method excl*( this: var IntSet, other :IntSet ) =
intsets.excl this, other
method union*( this, other: IntSet ) :IntSet =
intsets.union this, other
method disjoint*( this, other: IntSet ) :bool =
intsets.disjoint this, other
This gives you ECMA2020+ JS-Engine which will be highly portable. The imports are hooked, so that one can import form uris like sql://dbfile.db/modulestable/modulename or directly from https://bluesky-api or what have you. So one can keep modules, bytecode and JS-apps (codemirror, JSON-Buddy, etc.) inside sqlite - that makes it portable on a USB-stick. With the integration of Nim-types and modules you effectively end up with a dynamic/static-environment that lets you prototype with plainJS, CoffeeScript / Civet / Imba - whatever compiles to JS on the surface and have opaque-nimtypes (think of ArrayMancer ) as a foundation for excellent performance. Minus a NodeJS-installation, cos were portable.. QuickJS is math-gearded, comes with BigInt/BigFloat and operator overloading. Sqlite will be a first class citizen, including 'Simple-Graph' as a built-in. Now putting one of these JS-Symbol.Int64- creatures on the JS-Set would give you a Nim-Set-of-Int64 - which IMHO is what Typescript always tried to do :). Beeing able to scan the surface of a Nim-Module - just reading the const/routine-exports - would make such integrations even easier ? Rumor has it there would be some 'dirty'-strategies to achieve this ?