Writing built-in functions
Low-level languages such as C have no built-in functions; they have standard libraries that contain functions available to all programs. Linking a function to your program and calling it is conceptually the same action, whether it is a library function or a user-defined function. The higher the language level, the more conspicuous the difference between what is written for its runtime system in a lower-level implementation language, and what is written by end users in the language itself. This section uses the words function and method interchangeably. Let's consider how to implement built-ins in the bytecode interpreter.
Adding built-in functions to the bytecode interpreter
Let's implement System.out.println()
in the bytecode interpreter. One of our design options is to implement a new bytecode machine instruction for each built-in function, including println()
. This doesn't scale well to thousands of built-in functions. We could implement...