News for hackers. Stuff that matters.
Re:A Virtual Machine by joe_the_user on Friday April 06, 2018 @04:05PM (#16776892)
Thanks for the answer.

"No real way" is relative, of course. I happen to have constraints pushing for a VM as small as conceivably possible without code-blow-up, like single-instruction VM but implementing most logic/arithmetic primitives.

But which parts are dicier than others is worth considering.

Re:A Virtual Machine by chubot on Friday April 06, 2018 @04:23PM (#16777041)
Yeah I was a little wrong, and I edited my comment. But I am still confused by your question. There are lots of places where you might need to allocate memory -- it depends on the semantics of your source language, and it depends what you consider part of the VM proper, etc.

It sounds like you are describing something with more primitive types, like a CPU emulator or WebAssembly, rather than a dynamic language VM, which is the subject of this book.

Re:A Virtual Machine by e12e on Friday April 06, 2018 @08:09PM (#16778593)
Say you want to model a Turing machine. You can allocate a fixed length tape (making a linear bounded automaton), or a tape that can grow (closer to a "real" Turing machine).

Now, you could argue that writing to a part of the finite tape that's so far clear is "allocating memory" - but at the same time that could be a single section of statically allocated memory from the perspective of the Os that runs your vm...

For some related fun, I still think the nim "howistart" is great (but I haven't tried to follow along in a while, not sure if the code works straight away with up to date nim (but I see there's a notice mentioning a 2018 update, so I hope it's still /again working!)):

http://howistart.org/posts/nim/1/

Re:A Virtual Machine by e12e on Sunday April 08, 2018 @05:31AM (#16785378)
Although, looking at the github repo; I'm confused. Can't find the change related to 2018 update, but there's this:

https://github.com/howistart/howistart/pull/50/files

Re:A Virtual Machine by joe_the_user on Friday April 06, 2018 @04:48PM (#16777273)
Sure, that explains it. The VM has to allocate memory if it's interpreting a dynamic language. Sorry if the question was elementary.
Re:A Virtual Machine by chubot on Friday April 06, 2018 @05:14PM (#16777516)
OK no problem, it would be interesting to see a comparison between the two styles of VM! I remember that there is at least one talk here which goes into the difference:

http://soft-dev.org/events/vmss16/

I forget what the different names he used. He distinguished between runtimes like the JVM and runtimes like Xen, which emulate an operating system too. A CPU emulator seems closer to Xen than the JVM.

-----

EDIT: The names were "system" and "process" VMs, mentioned here:

https://news.ycombinator.com/item?id=16777564

So I think you are talking about a "system VM", where this book is more about "process" VMs. They are related, but distinct -- it even says so in that book's title!

It's definitely true that in something like Xen you would want to avoid allocating memory more than in something like a JavaScript VM. (And it would be easier to avoid allocating, too.)

I don't like that terminology, but it's a useful distinction.

Re:A Virtual Machine by 35bge57dtjku on Saturday April 07, 2018 @06:05AM (#16780118)
I don't think it's because it's a dynamic language like you seem to imply. How else would you implement both stack and heap in non-'dynamic' languages without constraining them to a fixed size?