46 unsigned char *code_pos;
47 unsigned char *code_ptr;
48 unsigned char *prog_ptr;
49 unsigned char *prog_end_ptr;
58 unsigned int prev_opcode_pos;
60 int m_iVarStackOffset;
61 int m_iInternalMaxVarStackOffset;
62 int m_iMaxExternalVarStackOffset;
63 int m_iMaxCallStackOffset;
66 unsigned char *apucBreakJumpLocations[BREAK_JUMP_LOCATION_COUNT];
67 int iBreakJumpLocCount;
68 unsigned char *apucContinueJumpLocations[CONTINUE_JUMP_LOCATION_COUNT];
69 int iContinueJumpLocCount;
73 static int current_label;
79 unsigned char PrevOpcode();
80 signed char PrevVarStackOffset();
81 void AbsorbPrevOpcode();
82 void ClearPrevOpcode();
83 void AccumulatePrevOpcode(
int opcode,
int iVarStackOffset);
85 void AddBreakJumpLocation(
unsigned char *pos);
86 void AddContinueJumpLocation(
unsigned char *pos);
87 void AddJumpLocation(
unsigned char *pos);
88 void AddJumpBackLocation(
unsigned char *pos);
89 void AddJumpToLocation(
unsigned char *pos);
91 bool BuiltinReadVariable(
unsigned int sourcePos,
int type,
int eventnum);
92 bool BuiltinWriteVariable(
unsigned int sourcePos,
int type,
int eventnum);
94 void EmitAssignmentStatement(sval_t lhs,
unsigned int sourcePos);
96 void EmitBoolJumpFalse(
unsigned int sourcePos);
97 void EmitBoolJumpTrue(
unsigned int sourcePos);
98 void EmitBoolNot(
unsigned int sourcePos);
99 void EmitBoolToVar(
unsigned int sourcePos);
101 void EmitBreak(
unsigned int sourcePos);
102 void EmitCatch(sval_t val,
unsigned char *try_begin_code_pos,
unsigned int sourcePos);
103 void EmitConstArray(sval_t lhs, sval_t rhs,
unsigned int sourcePos);
104 void EmitConstArrayOpcode(
int iCount);
105 void EmitContinue(
unsigned int sourcePos);
106 void EmitDoWhileJump(sval_t while_stmt, sval_t while_expr,
unsigned int sourcePos);
107 void EmitEof(
unsigned int sourcePos);
108 void EmitField(sval_t listener_val, sval_t field_val,
unsigned int sourcePos);
109 void EmitFloat(
float value,
unsigned int sourcePos);
110 void EmitFunc1(
int opcode,
unsigned int sourcePos);
112 void EmitIfElseJump(sval_t if_stmt, sval_t else_stmt,
unsigned int sourcePos);
113 void EmitIfJump(sval_t if_stmt,
unsigned int sourcePos);
114 void EmitInteger(
unsigned int value,
unsigned int sourcePos);
115 void EmitJump(
unsigned char *pos,
unsigned int sourcePos);
116 void EmitJumpBack(
unsigned char *pos,
unsigned int sourcePos);
117 void EmitLabel(
const char *name,
unsigned int sourcePos);
118 void EmitLabel(
int name,
unsigned int sourcePos);
119 void EmitLabelParameterList(sval_t parameter_list,
unsigned int sourcePos);
120 void EmitLabelPrivate(
const char *name,
unsigned int sourcePos);
121 void EmitAndJump(sval_t logic_stmt,
unsigned int sourcePos);
122 void EmitOrJump(sval_t logic_stmt,
unsigned int sourcePos);
123 void EmitMakeArray(sval_t val);
124 void EmitMethodExpression(
int iParamCount,
int eventnum,
unsigned int sourcePos);
125 void EmitNil(
unsigned int sourcePos);
127 int EmitNot(
unsigned int sourcePos);
128 void EmitOpcode(
int opcode,
unsigned int sourcePos);
129 void EmitParameter(
sval_u lhs,
unsigned int sourcePos);
130 int EmitParameterList(sval_t event_parameter_list);
131 void EmitRef(sval_t val,
unsigned int sourcePos);
132 void EmitStatementList(sval_t val);
133 void EmitString(
str value,
unsigned int sourcePos);
134 void EmitSwitch(sval_t val,
unsigned int sourcePos);
135 void EmitValue(sval_t val);
137 void EmitVarToBool(
unsigned int sourcePos);
138 void EmitWhileJump(sval_t while_expr, sval_t while_stmt, sval_t inc_stmt,
unsigned int sourcePos);
142 void ProcessBreakJumpLocations(
int iStartBreakJumpLocCount);
143 void ProcessContinueJumpLocations(
int iStartContinueJumpLocCount);
145 unsigned char *GetPosition();
148 void CompileError(
unsigned int sourcePos,
const char *format, ...);
150 scriptmacro_t *GetMacro(
char *sourceLine);
152 char *Preprocess(
char *sourceBuffer);
153 void Preclean(
char *processedBuffer);
154 bool Parse(
GameScript *m_GameScript,
char *sourceBuffer,
const char *type,
size_t& outLength);
155 bool Compile(
GameScript *m_GameScript,
unsigned char *progBuffer,
size_t& outLength);
157 static str GetLine(
str content,
int line);
160 template<
typename Value>
161 void EmitOpcodeValue(
const Value& value,
size_t size);
163 template<
typename Value>
164 void EmitOpcodeValue(
const Value& value);
166 template<
typename Value>
167 void EmitAt(
unsigned char *location,
const Value& value,
size_t size);
169 template<
typename Value>
170 void SetOpcodeValue(
const Value& value);
172 template<
typename Value>
173 Value GetOpcodeValue(
size_t size)
const;
175 template<
typename Value>
176 Value GetOpcodeValue(
size_t offset,
size_t size)
const;