Skip to Main Content
Language Implementation Patterns
book

Language Implementation Patterns

by Terence Parr
December 2009
Intermediate to advanced content levelIntermediate to advanced
380 pages
9h 2m
English
Pragmatic Bookshelf
Content preview from Language Implementation Patterns
Pattern 28Register-Based Bytecode Interpreter

Purpose

This pattern executes bytecode instructions that store function parameters, local variables, and temporary values in simulated registers.

Discussion

A register-based bytecode interpreter is identical to a stack-based interpreter except for the instruction set and where it keeps local variables, parameters, return values, and any temporary values. The instructions use registers instead of an operand stack. Our simulated machine gives each stack frame an “infinite” set of registers.

Table 9. Register-based arithmetic bytecode instructions

Instruction

Description

iadd ri, rj, rk isub ri, rj, rk imul ri, rj, rk

Arithmetic operators for integers. rk=ri op rj

fadd ri, rj, rk fsub ri, rj, rk fmul ri, ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Implementation Patterns

Implementation Patterns

Kent Beck

Publisher Resources

ISBN: 9781680500097Errata Page