December 2009
Intermediate to advanced
380 pages
9h 2m
English
Programming a bytecode interpreter is very much like programming a real processor. The biggest difference is that bytecode instruction sets are much simpler and slightly higher-level. For example, we don’t have to worry about running out of registers in a register-based interpreter. (We can assume there are an infinite number of registers.)
Like the assembly language for a physical processor, each instruction only does a tiny amount of work. For example, it takes four instructions to say print 1+2 in the assembly language syntax of Pattern 28, Register-Based Bytecode Interpreter:
| | iload r1, 1 ; load int 1 into register one: r1 = 1 |
| | iload r2, 2 ; r2 = 2 |
| | iadd r1, r2, r3 ; r3 = r1 + r2 |
| | print r3 ; print value ... |
Read now
Unlock full access