[squeak-dev] Not Squeak but... Ni goes multithreaded
Göran Krampe
goran at krampe.se
Tue Feb 2 15:44:46 UTC 2016
Hey!
On 02/02/2016 02:48 PM, David T. Lewis wrote:
> Cool.
>
> Are the numbers in the factorial example values on the stack, or are
> they "objects" in the Smalltalk sense? I'm curious how Ni might be
> approaching a shared object space for the interpreters.
In Ni everything is a "node" as in an AST Node. ints and floats are
boxed Nim ints/floats. Strings are boxed Nim strings and blocks are
boxed Nim seq (dynamic array). Dictionaries are boxed Nim OrderedTables.
true, false, nil and undef are singleton objects.
So they are Nim objects (which means the VM can actually do dynamic
dispatch on them using Nim's mechanism for that) but in Ni they are
"primitive types".
BUT... the model I am working on for "OO" in Ni is centered around
instance tagging (!) and dynamic dispatch using these tags of Ni funcs.
Since everything (ints floats etc) are nodes, they can be tagged and
thus "methods" can be polymorphically dispatched on everything.
And since Ni (just like Nim) offers "infix functions with more than one
argument, optionally using keyword syntax" you should get a very OO-ish
model.
So Ni uses Nim objects for the AST nodes and thus also uses Nim's GC (it
has 5 different ones!). The reified stack is also built with Nim objects
as a spaghetti stack so it too is GCd by Nim.
Nim has several interesting things going in the multithreading space. It
has an asynch model and it also has channels one can use between native
threads - the latter is used in a very nice article that Dennis Felsing
just wrote:
http://hookrace.net/blog/writing-an-async-logger-in-nim/
In fact, Dennis blog has a whole slew of brilliant Nim articles.
Exactly how Ni will piggy back on all these options is unclear at this
point - and oh, it uses FlowVars too.
But do note that the Nim GC runs *per thread* so to do memory sharing
between native threads in Nim you would need to use special shared
constructs. However... stuff is brewing in that area too in Nim.
But generally I am inclined towards a shared nothing model between
native threads (as I have now) but perhaps implementing coroutines or
something within a single thread. That is also why I need to go
stackless, so that I can manipulate the Ni stack without being hindered
by the Nim (C) stack.
regards, Göran
PS. I am still waiting for someone to join me in this coding adventure.
:) This is fresh ground here, but we have a tremendous solid base in the
Nim eco system.
More information about the Squeak-dev
mailing list
|