Creating IR code for classes and virtual functions
Many modern programming languages support object orientation using classes. A class is a high-level language construct, and in this section, we will explore how we can map a class construct into LLVM IR.
Implementing single inheritance
A class is a collection of data and methods. A class can inherit from another class, potentially adding more data fields and methods, or overriding existing virtual methods. Let’s illustrate this with classes in Oberon-2, which is also a good model for tinylang
. A Shape
class defines an abstract shape with a color and an area:
TYPE Shape = RECORD color: INTEGER; PROCEDURE (VAR s: Shape) GetColor(): INTEGER; PROCEDURE (VAR...