mud++0.35/etc/
mud++0.35/etc/guilds/
mud++0.35/help/propert/
mud++0.35/mudC/
mud++0.35/player/
mud++0.35/src/interface/
mud++0.35/src/os/cygwin32/
mud++0.35/src/os/win32/
mud++0.35/src/os/win32/bcppbuilder/
mud++0.35/src/osaddon/
mud++0.35/src/util/
/*
....[@@@..[@@@..............[@.................. 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
------------------------------------------------------------------------------
vmachine.h
*/

#ifndef _VMACHINE_H
#define _VMACHINE_H

#include "string.h"
#include "llist.h"
#include "vmtypes.h"
#include "vmobject.h"
#include "vmacros.h"
#include "memoryblock.h"

const int TSTACK_SIZE = 10;
const int OSTACK_SIZE = 50; 
const int VSTACK_SIZE = 50;

extern bool vmachine_enabled;

typedef struct
{
	int funID;
	memorycell * focus;
	int var_count;
} vmtrace;


class VMachine : public MemoryCellBlock
{
	protected:
		vmtrace	* pstrace;	// trace stacks - calls trace
		vmstack * psobj;	// object stack - aritmetic, short-time vars

		vmstack * psvar;	// local variables stack - args, local vars -
							// - current bottom
		int var_count;	    // local variables allocated in current scope

		vmtrace tStack[TSTACK_SIZE];
		vmstack oStack[OSTACK_SIZE];
		vmstack vStack[VSTACK_SIZE];
		vmtrace * tStackCeiling;
		vmstack * oStackCeiling;
		vmstack * vStackCeiling;

		int funID;
		memorycell * low_border;
		memorycell * high_border;
		String * current_args;
		int to_sleep;
		bool live;
		u8 exitCode;

	public:
		VMachine() 
		{
			tStackCeiling = &tStack[TSTACK_SIZE-1];
			oStackCeiling = &oStack[OSTACK_SIZE-1];
			vStackCeiling = &vStack[VSTACK_SIZE-1];
			defaultValues();
		}

		void defaultValues();
		void reset() { defaultValues(); }
		void run( int funnumber );
		void run();
		void schedule();
		void crit_error(const char *);
		void collect_trace();
		void leave_trace(int offs = 0);
		void buildStackTrace( String & );
		void putToSleep( float seconds );
		int tick() { return (--to_sleep); }
		int bigTick( int );
		vmstack * initp( int );
		void mark();	// Mark referenced objects for GC

		void push( vmstack val )
		{
			psobj++;
			*psobj = val;
			psobj->val = reference_obj(psobj);
		}
		void push( vmtype type, vmptr val )
		{
			psobj++;
			psobj->type = type;
			psobj->val = reference_obj( type, val );
		}
		void push_int( int val )
		{
			psobj++;
			psobj->type = VMT_INT;
			psobj->val.i = val;
		}
		void push_float( float val )
		{
			psobj++;
			psobj->type = VMT_FLOAT;
			psobj->val.f = val;
		}

		void push_string( const String & str )
		{
			psobj++;
			psobj->type = VMT_STRING;
			psobj->val.s = new String( str );
		}

		void push_obj( vmtype type, VMObject * ptr)
		{
			psobj++;
			psobj->type = type;
			psobj->val.o = ptr;
		}

		void push_null_obj( vmtype type)
		{
			psobj++;
			psobj->type = type;
			psobj->val.o = NULL;
		}
};

VMachine * getFreeVM();
void createVMs();
void VMstatistic( String &);
void VMmark4GC();

#endif