[m-dev.] for review: bytecode interpreter

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Dec 9 11:10:58 AEDT 2000


Levi writes:

bytecode/mb_machine.h:
> /* Don't directly access data from a machine state; go through the
> ** wrappers below which provide some measure of error checking
> ** (C++, C++, oh where art thou C++?)
> */
> typedef struct MB_Machine_State_Tag {
> 	MB_Word ip;			/* next instruction pointer*/
...
> } MB_Machine_State;
...
> /* Get the value of a register */
> MB_Word		MB_reg_get(MB_Machine_State* ms, MB_Word idx);
...

The way to enforce abstraction in C is to put the struct definition
in the .c file, and to just use

	struct MB_Machine_State_Tag;
	typedef struct MB_Machine_State_Tag MB_Machine_State;

in the header file.

Enforcing abstraction and getting good performance are often mutually
exclusive in C, since this technique prevents the use of macros
or inline functions.  However, the code there does not make use
of the struct definition in the header file, so you could just
as easily put it in the .c file.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list