Executing Your Code
To the first approximation, SPARC programs only run on SPARC machines, Intel programs only run on Intel machines, and Perl programs only run on Perl machines. A Perl machine possesses those attributes that a Perl program would find ideal in a computer: memory that is automatically allocated and deallocated; fundamental data types that are dynamic strings, arrays, and hashes, and have no size limits; and systems that all behave pretty much the same way. The job of the Perl interpreter is to make whatever computer it happens to be running on appear to be one of these idealistic Perl machines.
This fictitious machine presents the illusion of a computer specially designed to do nothing but run Perl programs. Each opcode produced by the compiler is a fundamental command in this emulated instruction set. Instead of a hardware program counter, the interpreter just keeps track of the current opcode to execute. Instead of a hardware stack pointer, the interpreter has its own virtual stack. This stack is very important because the Perl virtual machine (which we refuse to call a PVM) is a stack-based machine. Perl opcodes are internally called PP codes (short for “push-pop codes”) because they manipulate the interpreter’s virtual stack to find all operands, process temporary values, and store all results.
If you’ve ever programmed in Forth or PostScript, or used an HP scientific calculator with RPN (“Reverse Polish Notation”) entry, you know how a stack machine works. Even ...