src/parser/impcomp/OpSeq.h

00001 #ifndef OPSEQ_H_
00002 #define OPSEQ_H_
00003 
00004 #include <boost/shared_ptr.hpp>
00005 #include <vector>
00006 #include "engine/Variable.h"
00007 
00008 
00009 class SymbolTable;
00010 class VarTable;
00011 
00012 
00013 class ParseException
00014 {
00015 
00016 public:
00017         ParseException(char* inStr)
00018                 {
00019 
00020                 }
00021 };
00022 
00023 
00024 namespace green
00025 {
00026 
00027 class OpSeq
00028 {
00029 public:
00030 
00031 /*
00032         Var/Literal struture:
00033                 vartype-8 bin-8 reserved-16 offset/value-32
00034 
00035                 vartype- what type of the var is, literal or var; real or int
00036                         bit(from lowest):
00037                                 0: 0-var 1-literal
00038                                 1: 0-int 1-float
00039 
00040                 bin- which bin its from:
00041                         0-entity current
00042                         1-entity last
00043                         2-entity previous frame
00044                         3-behavior
00045                         4-local stack frame
00046                         5-local stack pointer (push and pop is really this)
00047                         6-heap ... eventually
00048                         7-globals ... also eventually
00049 
00050 
00051         Possable statements: each < > is a 32 bit int
00052                 Binary Operation: 8 long - this does a binary operation vars is dest
00053                         src1 src2
00054                         <OpCode> <Operator> <src1 var1> <src1 var2> <src2 var1> <src2 var2> <dest var 1> <dest var 2>
00055 
00056                 Unary Operation: 6 long - does a unary op on the source var and puts
00057                         it in the dest var
00058                         <OpCode> <Operator> <src1 var1> <src1 var2> <dest var 1> <dest var 2>
00059 
00060                 Goto: 3 long - unconditional jump, a variable is a jump to a variable
00061                         place, a literal is a jump to a fixed place, a float literal is
00062                         an error.
00063                         <OpCode> <dest var1> <dest var2>
00064 
00065                 Goto if: 8 long - conditional goto, evaluates expression on the right
00066                         uses that to decide jump, 2 kinds jump if true or jump if false
00067                         <OpCode> <Operator> <goto var1> <goto var2> <src1 var1> <src1 var2> <src2 var1> <src2 var2>
00068 
00069                 Push/Pop: 2 long - allocates or deallocates a size on the stack
00070                         <OpCode> <size>
00071 
00072                 Function Call: variable - calls the function handler, there are
00073                         probably internal functions implemented by push return address
00074                         jumps and such that is not this
00075                         <OpCode> <funcid> <var1-1> <var1-2> <var2-1> <var2-2> ... <ENDTERM>
00076 
00077                 Return: 1 - terminates parsing, every sequence must have atleast one
00078                         <OpCode>
00079 */
00080 
00081 
00082         enum OpCodeEnum
00083                 {
00084                 C_IBIN, //any integer binary operation
00085                 C_FBIN, //float binary operation
00086                 C_UNARY,        //unary op, this checks var type
00087 
00088                 C_GOTO,         //unconditional goto
00089                 C_GOTO_IF,      //goto if true
00090                 C_GOTO_IFN,     //goto if false
00091 
00092                 C_DECL_INT,     //declare an int
00093                 C_DECL_FLOAT,   //declare a float
00094                 C_FUNC,         //function call
00095 
00096                 C_ENDTERM,      //the terminator for variable length expressions
00097                 C_RETURN                //ends parsing
00098                 };
00099 
00100         enum OperatorEnum
00101                 {
00102                 O_BIN_ADD,      //binary ops
00103                 O_BIN_SUB,
00104                 O_BIN_MUL,
00105                 O_BIN_DIV,
00106                 O_BIN_MOD,
00107 
00108                 O_BIN_LT,
00109                 O_BIN_GT,
00110                 O_BIN_LE,
00111                 O_BIN_GE,
00112                 O_BIN_EQ,
00113                 O_BIN_NE,
00114 
00115                 O_BIN_AND,
00116                 O_BIN_OR,
00117 
00118                 O_UNARY_NEG,    //unary ops, these do type converting between int and float
00119                 O_UNARY_NOT,  //except this one which only accepts ints
00120                 O_UNARY_NOTH //does nothing operator, used for copying, 
00121                 };
00122 
00123         static const int BIN_ENUM_COUNT = 6;
00124         enum BinEnum
00125                 {
00126                 B_ETHIS = 0,
00127                 B_EPREV = 1,
00128                 B_ELAST = 2,
00129                 B_BEH = 3,
00130                 B_LOCAL = 4,
00131                 B_PARAM = 5
00132                 };
00133 
00134         enum FuncEnum
00135                 {
00136                 F_SPAWN,
00137                 F_DELETE,
00138                 F_SEND,
00139                 F_RECIEVE,
00140                 F_GETMSGNUM
00141                 };
00142 
00143 private:
00144         std::vector<uint> seqData;
00145 
00146 //Helper functions
00147         void dispVarFormat(int& cur);
00148 
00149 public:
00150 
00151         OpSeq();
00152         OpSeq(int* inSeq);
00153 
00154         void addValue(int value);
00155         void addVar(int isLit,Variable::Type typeIn,OpSeq::BinEnum binNo,int offset);
00156 
00157 
00158         int getSize();
00159 
00160         void dumpScreen();
00161 
00162 //private:
00163         std::vector<uint>::iterator getSequence();
00164 };
00165 
00166 typedef boost::shared_ptr<OpSeq> OpSeqPtr;
00167 
00168 };
00169 
00170 #endif

Generated on Fri Apr 27 10:27:38 2007 for Green Engine by  doxygen 1.5.1