Pattern 27Stack-Based Bytecode Interpreter

Purpose

This pattern executes bytecode instructions that store temporary values on an operand stack.

Discussion

A stack-based bytecode interpreter simulates a hardware processor with no general-purpose registers. That means that bytecode instructions must use an operand stack to hold temporary values. Temporary values include arithmetic operands, parameters, and return values. Because the introductory material for this chapter explained general bytecode interpreter architecture, we can focus on the details specific to stack machines.

Let’s look at the operand stack first, since it’s the key identifying feature. Any time we want to load a value from memory or compute a result, we push the result onto ...

Get Language Implementation Patterns now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.