OpenMW
|
00001 #ifndef COMPILER_GENERATOR_H_INCLUDED 00002 #define COMPILER_GENERATOR_H_INCLUDED 00003 00004 #include <vector> 00005 #include <string> 00006 #include <cassert> 00007 00008 #include <components/interpreter/types.hpp> 00009 00010 namespace Compiler 00011 { 00012 class Literals; 00013 00014 namespace Generator 00015 { 00016 typedef std::vector<Interpreter::Type_Code> CodeContainer; 00017 00018 inline Interpreter::Type_Code segment0 (unsigned int c, unsigned int arg0) 00019 { 00020 assert (c<64); 00021 return (c<<24) | (arg0 & 0xffffff); 00022 } 00023 00024 inline Interpreter::Type_Code segment1 (unsigned int c, unsigned int arg0, 00025 unsigned int arg1) 00026 { 00027 assert (c<64); 00028 return 0x40000000 | (c<<24) | ((arg0 & 0xfff)<<12) | (arg1 & 0xfff); 00029 } 00030 00031 inline Interpreter::Type_Code segment2 (unsigned int c, unsigned int arg0) 00032 { 00033 assert (c<1024); 00034 return 0x80000000 | (c<<20) | (arg0 & 0xfffff); 00035 } 00036 00037 inline Interpreter::Type_Code segment3 (unsigned int c, unsigned int arg0) 00038 { 00039 assert (c<262144); 00040 return 0xc0000000 | (c<<8) | (arg0 & 0xff); 00041 } 00042 00043 inline Interpreter::Type_Code segment4 (unsigned int c, unsigned int arg0, 00044 unsigned int arg1) 00045 { 00046 assert (c<1024); 00047 return 0xc4000000 | (c<<16) | ((arg0 & 0xff)<<8) | (arg1 & 0xff); 00048 } 00049 00050 inline Interpreter::Type_Code segment5 (unsigned int c) 00051 { 00052 assert (c<67108864); 00053 return 0xc8000000 | c; 00054 } 00055 00056 void pushInt (CodeContainer& code, Literals& literals, int value); 00057 00058 void pushFloat (CodeContainer& code, Literals& literals, float value); 00059 00060 void pushString (CodeContainer& code, Literals& literals, const std::string& value); 00061 00062 void assignToLocal (CodeContainer& code, char localType, 00063 int localIndex, const CodeContainer& value, char valueType); 00064 00065 void negate (CodeContainer& code, char valueType); 00066 00067 void add (CodeContainer& code, char valueType1, char valueType2); 00068 00069 void sub (CodeContainer& code, char valueType1, char valueType2); 00070 00071 void mul (CodeContainer& code, char valueType1, char valueType2); 00072 00073 void div (CodeContainer& code, char valueType1, char valueType2); 00074 00075 void convert (CodeContainer& code, char fromType, char toType); 00076 00077 void squareRoot (CodeContainer& code); 00078 00079 void exit (CodeContainer& code); 00080 00081 void message (CodeContainer& code, Literals& literals, const std::string& message, 00082 int buttons); 00083 00084 void report (CodeContainer& code, Literals& literals, const std::string& message); 00085 00086 void fetchLocal (CodeContainer& code, char localType, int localIndex); 00087 00088 void jump (CodeContainer& code, int offset); 00089 00090 void jumpOnZero (CodeContainer& code, int offset); 00091 00092 void jumpOnNonZero (CodeContainer& code, int offset); 00093 00094 void compare (CodeContainer& code, char op, char valueType1, char valueType2); 00095 00096 void menuMode (CodeContainer& code); 00097 00098 void assignToGlobal (CodeContainer& code, Literals& literals, char localType, 00099 const std::string& name, const CodeContainer& value, char valueType); 00100 00101 void fetchGlobal (CodeContainer& code, Literals& literals, char localType, 00102 const std::string& name); 00103 00104 void assignToMember (CodeContainer& code, Literals& literals, char memberType, 00105 const std::string& name, const std::string& id, const CodeContainer& value, char valueType); 00106 00107 void fetchMember (CodeContainer& code, Literals& literals, char memberType, 00108 const std::string& name, const std::string& id); 00109 00110 void random (CodeContainer& code); 00111 00112 void scriptRunning (CodeContainer& code); 00113 00114 void startScript (CodeContainer& code); 00115 00116 void stopScript (CodeContainer& code); 00117 00118 void getDistance (CodeContainer& code, Literals& literals, const std::string& id); 00119 00120 void getSecondsPassed (CodeContainer& code); 00121 00122 void getDisabled (CodeContainer& code, Literals& literals, const std::string& id); 00123 00124 void enable (CodeContainer& code, Literals& literals, const std::string& id); 00125 00126 void disable (CodeContainer& code, Literals& literals, const std::string& id); 00127 } 00128 } 00129 00130 #endif