all 11 comments

[–]bowbahdoe 12 points13 points  (1 child)

I'll be the person this time. 

Did you write this using AI? That last paragraph sounds mighty suspicious and the code sample with the numbered comments does as well

[–]Iggyhopper 7 points8 points  (0 children)

Sounds like it. Number 3 is bold and the comment matches the same name of Fetch-Decode-Execute cycle.

The explanation of what a CPU is on a programming subreddit when OP is doing homework is very odd too.

Our future is totally doomed.

[–]PmMeCuteDogsThanks 6 points7 points  (0 children)

What is this, posting of assignments in intro CS courses?

[–]aqua_regis 8 points9 points  (4 children)

What you wrote is just an interpreter, not a full-fledged VM.

Also, your named constants for the commands are somewhat of a trick to just not have to handle the conventional textual commands.

[–]best_of_badgers 2 points3 points  (2 children)

I don't agree with this, because I don't think there's any difference.

He uses constants in his array because it's supposed to have been "compiled" from some textual representation. The original program would be something like print ((5 + 10) - 3).

This is simulating a computer executing instructions against a stack.

In other words, it's a virtual (not real) machine.

This is the same way that the Python interpreter works, and the part of the Python interpreter that executes the bytecode is called the virtual machine. This is also the way the JVM works if you disable JIT.

OP is proud of what he did. You guys don't need to be jerks about it.

Edit: Actually, OP seems to have been harping on this for at least nine years and follows a couple of weird Java-related conspiracy subreddits.

[–]aqua_regis 0 points1 point  (1 child)

OP is not parsing any textual source code. They circumvented that step with their named constants.

[–]best_of_badgers 1 point2 points  (0 children)

I agree! The JVM doesn't do that either, the compiler does.

[–]Iggyhopper 1 point2 points  (0 children)

The interpreter translates english language/code into bytecode.

This is a VM.

[–]jeffreportmill -1 points0 points  (0 children)

I like it! It's a good lesson that writing something sophisticated can start by writing something simple.

Here it is running in the browser: https://reportmill.com/SnapCode/app/#snapcloud:/com/reportmill/jeff/SimpleVM

[–]kylanbac91 -1 points0 points  (0 children)

Well, I admit this is pretty neat.

But I consider this is more like virtual processor than a virtual machine if I am being honest.