by JustSomeNobody · 9y ago · 0 comments
Does anyone have a link to a simple one that supports concurrency, by chance?
The language is based on Scheme and Common Lisp.
The instruction set is derived from one described in the book Paradigms of Artificial Intelligence Programming by Peter Norvig.
The concurrency primitives are inspired by Erlang.
It's implemented in (old-fashioned) JavaScript but the compiler is self-hosting.
edit: So basically, if one had the p-code machine[0], how might it handle concurrency/threading?
Given a single-CPU VM, you can write an assembly program that implements context switching and the thread control block data structure. Then you write a scheduler (OK, the VM needs a timer/interrupt to trigger the scheduler). thread.start(function) allocates some stack memory and a thread control block, which contains a pointer to `function` and to the stack memory you just allocated. Then `thread.start` inserts our TCB into the scheduler queue. All this stuff is implemented as software in the VM's machine language, it is not part of the VM itself. pthread_create and the Linux scheduler are not implemented in hardware either.
I guess if you want memory protection, you would need the VM to simulate a MMU.
On the other hand, if you actually want programs on the VM to be able to run on multiple CPUs of the host machine, then I agree you need some special support in the VM to do that.