munificent / game-programming-patterns

Source repo for the book
http://gameprogrammingpatterns.com/
Other
4.13k stars 498 forks source link

Bytecode #119

Closed colms closed 10 years ago

colms commented 10 years ago

Some small things:

"composible" => "composable"

"My own little scripting language Wren is a simple stack-based bytecode interpreter." I'd add commas like: "My own little scripting language, Wren, is a simple stack-based bytecode interpreter." Also, maybe "uses" instead of "is".

There are lots of references to "you" that are referring to the VM (or maybe the stack / return stack?). For example: "The only difference is that the VM maintains a second return stack. When you do a "call" instruction, you push the current instruction index onto that stack before jumping to the bytecode being called. When you hit a "return", you pop that index and jump back to it." consider something like: "The only difference is that the VM maintains a second return stack. When the VM does a "call" instruction, it pushes the current instruction index onto that stack before jumping to the bytecode being called. When it hits a "return", it pops that index and jumps back to [it]."

I put that last "it" in brackets because that would have to be changed because "it" is now the VM. Maybe: "it pops that index and jumps back to the instruction index."

I'd also change the "do" or "does" to "perform" here. So: "When the VM does a "call" instruction" becomes "When the VM performs a "call" instruction".

"Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in it." I'm not sure if it is the VM or the stack.

I feel this sentence could be reworded for clarity: "You have to design the user experience for that format, and to execute it efficiently, you need to translate it into a lower-level form." Maybe some thing along the lines of: "You have to design the user experience for that format. To execute the format efficiently, you need to translate it into a lower-level form." but I don't think that's it exactly.

"It is real work" This is perfectly correct but in keeping with your style of preferring contractions when possible, it could also be: "It's real work"

I felt this to be reworded: "To do that, we need to make the data flow that brings parameters to the callsite that needs them implicit in the structure of the code."

Questions:

What's the difference between a VM and an interpreter?

On this bit of code: enum Instruction { INST_SET_HEALTH = 0x00, INST_SET_WISDOM = 0x01, INST_SET_AGILITY = 0x02, INST_PLAY_SOUND = 0x03, INST_SPAWN_PARTICLES = 0x04 };

Why are the enums hex?

Comments:

This chapter is really tight. It's one of those that made me read in all in one sitting. I thought it had the best introduction of all the chapters. It was just really flowing. Toward the end of the chapter I thought, "Bob should write a book on programming languages.". I can dream :)

munificent commented 10 years ago

"composible" => "composable"

Done!

"My own little scripting language, Wren, is a simple stack-based bytecode interpreter." Also, maybe "uses" instead of "is".

Commas done. I think I prefer "is".

"The only difference is that the VM maintains a second return stack. When the VM does a "call" instruction, it pushes the current instruction index onto that stack before jumping to the bytecode being called. When it hits a "return", it pops that index and jumps back to [it]."

Good call. That's something I try to keep in mind but I slip sometimes and accidentally anthropomorphize the machine. :)

I'd also change the "do" or "does" to "perform" here.

Changed to "execute".

"Register-based VMs still have a stack. The only difference is that instructions can read their inputs from deeper in it." I'm not sure if it is the VM or the stack.

I couldn't come up with a way to clarify this that didn't seem redundant. I think the next sentence helps already.

"You have to design the user experience for that format. To execute the format efficiently, you need to translate it into a lower-level form."

Yeah, that was a mouthful. Reworded.

"It is real work This is perfectly correct but in keeping with your style of preferring contractions when possible, it could also be:

I left it like that to draw a bit of emphasis on "is". I was hoping it would read as acknowledging that it's not as easy as I may make it sound. :)

"To do that, we need to make the data flow that brings parameters to the callsite that needs them implicit in the structure of the code."

Yeah, I never liked that sentence. Totally rewrote that paragraph.

What's the difference between a VM and an interpreter?

None. Added an aside clarifying that.

Why are the enums hex?

No real reason. I used hex numbers in the illustrations because I thought it helped clarify that they are they bytecode values being shown, then used them in the code to match that.

This chapter is really tight. It's one of those that made me read in all in one sitting. I thought it had the best introduction of all the chapters. It was just really flowing.

Thank you! That's really awesome to hear. It's the longest chapter in the book and I was afraid it dragged on.

Toward the end of the chapter I thought, "Bob should write a book on programming languages.". I can dream :)

A funny story about that...

I put this book on hiatus a few years ago. I felt really bad about abandoning it, but I wasn't really feeling like working on it either. Instead, I got super into programming languages (seriously, look at my github repos, SO MANY LANGS). I wrote a bunch of blog posts about them and spent a bunch of time talking language nerd stuff on reddit.

At some point, someone said I should write a book about programming languages. That sounded like a ton of fun. But I wouldn't let myself start another book when I'd failed to finish the first one. So... I started working on this one again. :)

I'm not promising to be crazy enough to write another book after I finish this one, but it's definitely on my mind. Hopefully, if I do, it won't take me another four years to write!