/* ....[@@@..[@@@..............[@.................. MUD++ is a written from ....[@..[@..[@..[@..[@..[@@@@@....[@......[@.... scratch multi-user swords and ....[@..[@..[@..[@..[@..[@..[@..[@@@@@..[@@@@@.. sorcery game written in C++. ....[@......[@..[@..[@..[@..[@....[@......[@.... This server is an ongoing ....[@......[@..[@@@@@..[@@@@@.................. development project. All ................................................ contributions are welcome. ....Copyright(C).1995.Melvin.Smith.............. Enjoy. ------------------------------------------------------------------------------ Melvin Smith (aka Fusion) msmith@hom.net MUD++ development mailing list mudpp@van.ml.org ------------------------------------------------------------------------------ vmacros.h */ #ifndef _VMACROS_H #define _VMACROS_H #define VM_SECURITY_LEVEL 2 inline vmptr reference_obj( vmtype type, vmptr ptr ) { if ( type == VMT_STRING ) { vmptr a; a.s = new String(*ptr.s); return a; } else return ptr; } inline void dereference_obj( vmtype type, vmptr ptr ) { if ( type == VMT_STRING ) delete ptr.s; } inline vmptr reference_obj( vmstack * st ) { if ( st->type == VMT_STRING ) { vmptr a; a.s = new String(*st->val.s); return a; } else return st->val; } inline void dereference_obj( vmstack * st ) { if ( st->type == VMT_STRING ) delete st->val.s; } #if VM_SECURITY_LEVEL >= 1 #define VM_SECURE_1( cond, txt ); if ( cond ) { crit_error( txt ); break; } #define NEED_OSTACK( x ); if ( (oStackCeiling - psobj) < x )\ {crit_error("Object stack exceeded."); break;} #define NEED_VSTACK( x ); if ( (vStackCeiling - psvar - var_count) < x )\ {crit_error("Variable stack exceeded."); break;} #define NEED_TSTACK(); \ if ( pstrace >= tStackCeiling ) \ {crit_error("Trace stack exceeded."); break;} #else #define VM_SECURE_1( cond, txt ); #define NEED_OSTACK( x ); #define NEED_VSTACK( x ); #define NEED_TSTACK(); #endif #if VM_SECURITY_LEVEL >= 2 #define VM_SECURE_2( cond, txt ); if ( cond ) { crit_error( txt ); break; } #define ASSURE_SSIZE( x ); if ( psobj < &oStack[x] ) { crit_error( "Not "\ "enough items on stack"); break;} #define ASSURE_STACK1( x ); \ if ( psobj < &oStack[1] ) { crit_error( "No items on stack"); break;} \ if ( psobj->type != x ) { crit_error( "Wrong type on stack"); break;} #define ASSURE_STACK2( x, y ); \ if ( psobj < &oStack[2] ) { crit_error( "Only one item on stack"); break;} \ if ( (psobj->type != y) || ((psobj-1)->type != x) ) { crit_error( "Wrong type on stack"); break;} #define ACCESS_VSTACK( x ); \ if ( x >= var_count ) { crit_error( "Tried to access not allocated variable"); break; } #define ACCESS_VSTACKT( x, t ); \ if ( x >= var_count ) { crit_error( "Tried to access not allocated variable"); break; } \ if ( psvar[x].type != t ) { crit_error( "Wrong type of local variable"); break; } #else #define VM_SECURE_2( cond, txt ); #define ASSURE_SSIZE( x ); #define ASSURE_STACK1( x ); #define ASSURE_STACK2( x, y ); #define ACCESS_VSTACK( x ); #define ACCESS_VSTACK( x, t ); #endif #define FLAG_CONDITION( a ) \ ( \ ( (cell.s.conds & VMFLAG_EQUAL) && ( a==0 ) ) || \ ( (cell.s.conds & VMFLAG_GREATER) && ( a > 0 ) ) || \ ( (cell.s.conds & VMFLAG_LESSER) && ( a < 0) ) \ ) #define BOOL_FLAG_CONDITION( a ) \ ( \ ( (cell.s.conds & VMFLAG_EQUAL ) && ( a ) ) || \ ( (cell.s.conds & VMFLAG_NOT_EQUAL) && ( !(a) ) ) \ ) #endif