[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

3.4 Pragma directives

Apart from the standard commands, the interpreter can be given specific instructions regarding certain object behaviour. This is done with a special #pragma directive to the interpreter at the top of the file.

A number of #pragma directives exist:

`#pragma strict_types'

This is perhaps the most important, most useful interpreter directive there is. It instructs the interpreter to require all functions to be strictly typed. I.e. the type of the function has to match the type of what is returned by the function, and the type of the variable recieving the function result has to match the function type as well.

Without this pragma, the interpreter treats all functions as 'mixed', which perhaps is convenient but invariably results in buggy code. Consistent and frequent use of this pragma enhances both short-time code quality and improves maintainability immensly.

There are times when mixed functions are useful, but it's perfectly legal - and advisable - still to use the strict_types pragma and then explicitly declare such functions as mixed rather than default all of them to mixed.

`#pragma no_clone'

This pragma prevents the object from being cloned. Instead a run-time error indicating that a master object is missing is generated.

This is useful for 'abstract classes' of objects, i.e. object that are intended to be used as base classes only and never to be instanciated on their own.

`#pragma no_inherit'

This pragma prevents an object from being inherited. This is sometimes useful for items that are intended to work as end-use objects only.

`#pragma resident'

This directive causes an object to remain in memory indefinately. Usually when the last reference to an object is removed (by destructing the master of an object after all the clones have been destructed) the master program is removed from memory to make room for new ones.

However, if an object is likely to re-appear very quickly it can make sense never to allow the interpreter to forget it. That way no unneccesary effort needs to be spent compiling the object the next time it's called upon.

NB! Almost needless to say; use this directive with extreme caution as it clobbers the available memory. Memory is a precious enough commodity as it is without having resident objects hogging the room!

`#pragma save_binary'

This directive instructs the interpreter to store the precompiled version of the object to disk. I.e. the result of the preparser is then stored to file in a special directory. The next time the object is loaded the interpreter will first check that special dir for a precompiled version, and if it exists load that. That makes for speed improvements, particularly noticable after reboot when a lot of objects need to load almost at the same time.

NB! This pragma is slightly obsolete, as it is globally defined. It won't harm to put it into the program, but it won't do anything that isn't already done either.

`#pragma no_shadow'

This directive prevents an object from being shadowed using the shadow kfun.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

This document was generated by Hekay Permer on April, 20 2005 using texi2html