75 lines
1.6 KiB
C
Raw Normal View History

#ifndef __ALEX_H
#define __ALEX_H
#ifndef __RECORDSET_H
#include <recset.h>
#endif
class TVariant_stack : public TObject
{
TArray _var;
int _sp;
public:
int items() const { return _sp; }
bool drop();
TVariant& pop();
TVariant& peek(int depth = 0);
void roll(int depth);
void push(const TVariant& var);
void push(long n);
void push(const real& n);
void push(const char* str);
void reset();
bool overflow() const;
TVariant_stack() : _sp(0) { }
};
// Generic bytecode for any language
class TBytecode : public TArray
{
TString _name;
public:
void set_name(const char* name) { _name = name; }
const TString& name() const { return _name; }
};
// ALEX = Another Language EXtension
class TAVM;
class TAlex_virtual_machine : public TObject
{
TAVM* _avm; // Chesire's cat class
protected:
TAVM& avm();
public:
virtual size_t get_usr_words(TString_array& names) const;
virtual bool execute_usr_word(unsigned int opcode, TVariant_stack& stack);
virtual bool get_usr_val(const TString& name, TVariant& var) const;
virtual bool set_usr_val(const TString& name, const TVariant& var);
const TString& get_last_error() const;
bool compile(istream& instr, TBytecode& bc);
bool compile(const char* cmd, TBytecode& bc);
bool execute(const TBytecode& bc, ostream& outstr);
bool execute(const TBytecode& bc, TString& outstr);
bool include(const char* fname);
void warm_restart();
void cold_restart();
void set_interactive(bool inter);
bool defined(const char* name);
TAlex_virtual_machine();
virtual ~TAlex_virtual_machine();
};
#endif