Open tekknolagi opened 7 years ago
I want my own server in the cloud running zero code touched by the conventional C toolchain. That's it! But it has to be within a factor of 2 of C's performance.
The JVM shows that you're not going to get that by targeting a stack VM. Not without tons of JIT effort. To me that disqualifies stack VMs as any sort of intermediate disk format.
If our non-stack VM turns out to be too slow we'll need to translate it to native. Unless we planned ahead and it was already mostly like native.
Okay, I see what you mean. Sounds reasonable, then. But I think we should have some polyfills -- and this is a good time to figure out what they are.
My approach would be to start building simple programs ASAP, and then start adding polyfills as we feel the need. That said, here's Mu's list:
$print
-- for debugging in non-raw modetrace
-- add a line to the trace or log. Useful for whitebox testing as well as debugging in raw mode.$system
$dump-memory
random
-- for random number generationmake-random-nondeterministic
hash
-- works for any type using type informationVarious terminal helpers:
open-console
-- switch to raw mode where you can control cursor position and read input unbufferedclose-console
print-character
cursor-position
window-width
and window-height
wait-for-event
File-system/network client helpers:
$open-file-for-reading
and $open-file-for-writing
and $close-file
$read-from-file
and $write-to-file
$open-client-socket
and $open-server-socket
and $close-socket
$read-from-socket
and $write-to-socket
Oh yes, allocation:
new
-- takes a type and an optional number for allocating an array.
(Mu has no delete
. When an allocation's refcount drops to zero it gets reclaimed. To trigger reclamation you clear addresses.)
local-scope
-- allocate a stack frame on the heap that will be reclaimed when you exit, clearing any addresses in it.
To allocate stack frames that you don't want reclaimed, just use new
directly rather than local-scope
.
@akkartik what do you think about generalizing both file modes and combining files and sockets into the same data type?
Also do we really want a refcount in the VM...?
No, we don't want a refcount. That's one of the big causes of slowdown in Mu.
We can play lots of games with the OS side of things, but if you're thinking of them as polyfills that will eventually be replaced -- it doesn't seem like a priority to innovate there. Just get something working and move on. And we don't really need them yet anyway.
I think also the idea of building sample programs is a good idea. Anything from factorial to cat
to wc
or something of the sort.
I don't know if they are slotted to be eventually replaced in my mind.
Register VM: https://github.com/tekknolagi/stackx/issues/8
Stack VM: https://github.com/tekknolagi/stackx/issues/9