Byte Code

Smalltalk Language byte codes (From the Blue Book):

[source methods] are translated by a compiler into sequences of 8-bit instructions called bytecodes. The compiler and bytecodes are the subject of this chapter's first section. The bytecodes produced by the compiler are instructions for an interpreter [⇒The Art of the Interpreter], which is described in the second section.

The center message is used to find the Point equidistant from a Rectangle's four sides.


^origin + corner/2

Source methods are translated by the system's compiler into sequences of instructions for a stack-oriented interpreter. The instructions are eight-bit numbers called bytecodes. For example, the bytecodes corresponding to the source method above are,

0, 1, 176, 119, 185, 124

The compiler creates an instance of CompiledMethod to hold the bytecode translation of a source method. In addition to the bytecodes themselves, a CompiledMethod contains a set of objects called its literal frame. The literal frame contains any objects that could not be referred to directly by bytecodes.

The interpreter understands 256 bytecode instructions that fall into five categories: pushes, stores, sends, returns, and jumps.

Please note that these are not necessarily in files, they do not contain an executable program (instead, they are embedded in objects that are interpreted by the Virtual Machine), they are fixed in size (well, they are 8 or 16 bits in length), and they are usually compiled (on the fly) into machine code for the target platform.

In particular, the purity of the Smalltalk environment (together with its metastructure) allows an implementation of the Smalltalk Virtual Machine to do cross-bytecode optimization during the compilation (to machine code) process.

The following link does not accurately describe Smalltalk bytecodes. I don't know enough about other Virtual Machines to comment on its accuracy for them.

See original on