[ Prev ] [ Index ] [ Next ]

Dispatched Object

Created Tuesday 07 October 2008

Status

To be implemented

Abstract

This specifications aims at making it possible to compile separately different modules at the price of reduced performances when accessing slots from objects from another module.

This approach was taken because virtual function tables seems not to be a possible implementation in Lisaac because of:

The problem is clearly the dynamism of Lisaac.

Idea

Currently, objects that may have a static type that is different from their dynamic type include in their object structure their type_id, which is a number that corresponds to a type for the current module. This may change across different compilation, so it can't be used to identify the type across different module compiled separately.

The idea would be to use a special type_id value that would tell the runtime to look for the slot dynamically. In many languages this is done using virtual function tables, but because of the dynamism of Lisaac, this specification specify it differently.

Main Part

A dispatched object is an object that resolve dynamically slot addresses at runtime. Dispatched objects share the following common structure:

struct dispatched_object {
	uint_32		type_id;
	dispatcher_t	dispatcher;
	// ...
};

// (1)
typedef void (*dispatcher_t)(
	void* object,
	uint_32 slot_id,
	void* args);

// (1)
typedef void*(*dispatcher_t)(
	void* object,
	uint_32 slot_id);

For an object that is not a dispatched object, type_id is free, for a dispatched object type_id must be set to 0. When an object that has a dynamic type different than the static type has type_id set to 0, it implies that it is a dispatched object.

For dispatched objects, the second field is a pointer to a dispatcher function. The function take as first argument the pointer to the object to dispatch, as second argument an identifier for the slot accessed.

Then, there are two choices in implementation. Either the dispatcher function take a third argument that is a pointer to a structure where are serialised the parameter to send to the slot and the return parameters of the slot, or the dispatcher function simply returns a pointer to the function that must be called to access the slot.

Lisaac Syntax

If prototypes are exported from a module to another module, they must be dispatched objects. To make it possible, the following slot is added to the Section Header:

Section Header

  - mode := Normal|Dispatched;

If a prototype is dispatched, that do not imply that within a module, the dispatching is forced to occur and that flow analysis is forbidden. The compiler can still optimise out the dispatching. But it is left to the discretion of the compiler (until there is a specification for it) how this could be done (or not).

TODO


Backlinks: :Computer:Lisaac:Specs