Feature #38

Implement Isinst instruction

Added by Phil Garcia 10 months ago. Updated 8 months ago.

Status:Closed Start date:07/14/2011
Priority:Normal Due date:
Assignee:Phil Garcia % Done:

0%

Category:Compiler Spent time: -
Target version:1.1
Difficulty:

Description

The Isinst opcode tests if an object reference is an instance of class, returning either a null reference or an instance of that class or interface.


Subtasks

Feature #40: Implement Castclass instructionNewPhil Garcia

History

Updated by Phil Garcia 10 months ago

The current implementation plan is to search the object hierarchy to determine if the given object reference (O) is an instance of the given class (T).

If T is an object reference (not an interface), this requires a linear search of O's method tables and base method tables. At compiler time, the address of T's method table is known. So it is simply a matter of traversing O's method table and base method tables until it hits T's method table or not. Each method table contains an address pointer to its base type's method table, unless System.Object is reached which has no base type; the base pointer is NULL in this case. Once the search reaches the address of T's method table, then we know the object implements T. If the search reaches NULL, then we know the object does not implement T.

If T is an interface type, only a simple bitmap lookup is required. Each interface type also has a unqie index value known at compiler time. Each method table contains an address to an interface bitmap. If the method table represents a type that does not implement any interface, then this address is NULL. If the corresponding position by index value in the bitmap is set, then the object implements the interface, otherwise not.

Finally, if O does implement T, the compiler uses an IR.Move instruction to preform the cast. If O does not implement T, the compiler uses an IR.Move instruction to passing NULL instead.

Updated by Phil Garcia 10 months ago

  • Subject changed from Implement Isinst opcode to Implement Isinst instruction

Updated by Phil Garcia 10 months ago

  • Assignee set to Phil Garcia

Updated by Simon Wollwage 9 months ago

  • Target version changed from 1.0 to 1.1

Updated by Phil Garcia 8 months ago

  • Status changed from New to Closed

Also available in: Atom PDF