diff options
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs | 588 |
1 files changed, 294 insertions, 294 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs index 46f6845..e85c1d0 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs | |||
@@ -27,325 +27,325 @@ | |||
27 | */ | 27 | */ |
28 | /* Original code: Tedd Hansen */ | 28 | /* Original code: Tedd Hansen */ |
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | using System.Reflection; | 32 | using System.Reflection; |
33 | using System.Reflection.Emit; | 33 | using System.Reflection.Emit; |
34 | 34 | ||
35 | namespace OpenSim.Region.Scripting.LSL | 35 | namespace OpenSim.Region.Scripting.LSL |
36 | { | ||
37 | partial class LSO_Parser | ||
38 | { | ||
39 | //LSO_Enums MyLSO_Enums = new LSO_Enums(); | ||
40 | |||
41 | internal bool LSL_PROCESS_OPCODE(ILGenerator il) | ||
36 | { | 42 | { |
37 | partial class LSO_Parser | 43 | |
44 | byte bp1; | ||
45 | UInt32 u32p1; | ||
46 | UInt16 opcode = br_read(1)[0]; | ||
47 | Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString()); | ||
48 | string idesc = ((LSO_Enums.Operation_Table)opcode).ToString(); | ||
49 | switch ((LSO_Enums.Operation_Table)opcode) | ||
38 | { | 50 | { |
39 | //LSO_Enums MyLSO_Enums = new LSO_Enums(); | ||
40 | 51 | ||
41 | internal bool LSL_PROCESS_OPCODE(ILGenerator il) | 52 | case LSO_Enums.Operation_Table.POP: |
42 | { | 53 | case LSO_Enums.Operation_Table.POPL: |
43 | 54 | case LSO_Enums.Operation_Table.POPV: | |
44 | byte bp1; | 55 | case LSO_Enums.Operation_Table.POPQ: |
45 | UInt32 u32p1; | 56 | case LSO_Enums.Operation_Table.POPIP: |
46 | UInt16 opcode = br_read(1)[0]; | 57 | case LSO_Enums.Operation_Table.POPBP: |
47 | Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString()); | 58 | case LSO_Enums.Operation_Table.POPSP: |
48 | string idesc = ((LSO_Enums.Operation_Table)opcode).ToString(); | 59 | case LSO_Enums.Operation_Table.POPSLR: |
49 | switch ((LSO_Enums.Operation_Table)opcode) | 60 | // ignore -- builds callframe |
50 | { | 61 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Pop);"); |
62 | il.Emit(OpCodes.Pop); | ||
63 | break; | ||
64 | case LSO_Enums.Operation_Table.POPARG: | ||
65 | Common.SendToDebug("Instruction " + idesc + ": Ignored"); | ||
66 | Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack "); | ||
67 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
68 | break; | ||
51 | 69 | ||
52 | case LSO_Enums.Operation_Table.POP: | 70 | // LONG |
53 | case LSO_Enums.Operation_Table.POPL: | 71 | case LSO_Enums.Operation_Table.STORE: |
54 | case LSO_Enums.Operation_Table.POPV: | 72 | case LSO_Enums.Operation_Table.STORES: |
55 | case LSO_Enums.Operation_Table.POPQ: | 73 | case LSO_Enums.Operation_Table.STOREL: |
56 | case LSO_Enums.Operation_Table.POPIP: | 74 | case LSO_Enums.Operation_Table.STOREV: |
57 | case LSO_Enums.Operation_Table.POPBP: | 75 | case LSO_Enums.Operation_Table.STOREQ: |
58 | case LSO_Enums.Operation_Table.POPSP: | 76 | case LSO_Enums.Operation_Table.STOREG: |
59 | case LSO_Enums.Operation_Table.POPSLR: | 77 | case LSO_Enums.Operation_Table.STOREGS: |
60 | // ignore -- builds callframe | 78 | case LSO_Enums.Operation_Table.STOREGL: |
61 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Pop);"); | 79 | case LSO_Enums.Operation_Table.STOREGV: |
62 | il.Emit(OpCodes.Pop); | 80 | case LSO_Enums.Operation_Table.STOREGQ: |
63 | break; | 81 | case LSO_Enums.Operation_Table.LOADP: |
64 | case LSO_Enums.Operation_Table.POPARG: | 82 | case LSO_Enums.Operation_Table.LOADSP: |
65 | Common.SendToDebug("Instruction " + idesc + ": Ignored"); | 83 | case LSO_Enums.Operation_Table.LOADLP: |
66 | Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack "); | 84 | case LSO_Enums.Operation_Table.LOADVP: |
67 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | 85 | case LSO_Enums.Operation_Table.LOADQP: |
68 | break; | 86 | case LSO_Enums.Operation_Table.PUSH: |
87 | case LSO_Enums.Operation_Table.PUSHS: | ||
88 | case LSO_Enums.Operation_Table.PUSHL: | ||
89 | case LSO_Enums.Operation_Table.PUSHV: | ||
90 | case LSO_Enums.Operation_Table.PUSHQ: | ||
91 | case LSO_Enums.Operation_Table.PUSHG: | ||
92 | case LSO_Enums.Operation_Table.PUSHGS: | ||
93 | case LSO_Enums.Operation_Table.PUSHGL: | ||
94 | case LSO_Enums.Operation_Table.PUSHGV: | ||
95 | case LSO_Enums.Operation_Table.PUSHGQ: | ||
96 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
97 | break; | ||
98 | // None | ||
99 | case LSO_Enums.Operation_Table.PUSHIP: | ||
100 | case LSO_Enums.Operation_Table.PUSHBP: | ||
101 | case LSO_Enums.Operation_Table.PUSHSP: | ||
102 | // Push Stack Top (Memory Address) to stack | ||
103 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, " + myHeader.SP + ");"); | ||
104 | Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack"); | ||
105 | il.Emit(OpCodes.Ldc_I4, myHeader.SP); | ||
106 | break; | ||
107 | // BYTE | ||
108 | case LSO_Enums.Operation_Table.PUSHARGB: | ||
109 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
110 | break; | ||
111 | // INTEGER | ||
112 | case LSO_Enums.Operation_Table.PUSHARGI: | ||
113 | // TODO: What is size of integer? | ||
114 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
115 | Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes.Ldc_I4, " + u32p1 + ");"); | ||
116 | Common.SendToDebug("Param1: " + u32p1); | ||
117 | il.Emit(OpCodes.Ldc_I4, u32p1); | ||
118 | break; | ||
119 | // FLOAT | ||
120 | case LSO_Enums.Operation_Table.PUSHARGF: | ||
121 | // TODO: What is size of float? | ||
122 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
123 | break; | ||
124 | // STRING | ||
125 | case LSO_Enums.Operation_Table.PUSHARGS: | ||
126 | string s = Read_String(); | ||
127 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldstr, \"" + s + "\");"); | ||
128 | Common.SendToDebug("Param1: " + s); | ||
129 | il.Emit(OpCodes.Ldstr, s); | ||
130 | break; | ||
131 | // VECTOR z,y,x | ||
132 | case LSO_Enums.Operation_Table.PUSHARGV: | ||
133 | Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
134 | Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
135 | Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
136 | break; | ||
137 | // ROTATION s,z,y,x | ||
138 | case LSO_Enums.Operation_Table.PUSHARGQ: | ||
139 | Common.SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
140 | Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
141 | Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
142 | Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
143 | break; | ||
144 | // LONG | ||
145 | case LSO_Enums.Operation_Table.PUSHARGE: | ||
146 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
147 | //Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes., " + u32p1 + ");"); | ||
148 | Common.SendToDebug("Instruction " + idesc + ": Ignoring (not in use according to doc)"); | ||
149 | //Common.SendToDebug("Instruction " + idesc + ": Description: Pushes X bytes of $00 onto the stack (used to put space for local variable memory for a call)"); | ||
150 | Common.SendToDebug("Param1: " + u32p1); | ||
151 | //il.Emit(OpCodes.ldc_i4, u32p1); | ||
152 | //if (u32p1 > 0) { | ||
153 | //for (int _ic=0; _ic < u32p1; _ic++) | ||
154 | //{ | ||
155 | // Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldnull);"); | ||
156 | // il.Emit(OpCodes.Ldnull); | ||
157 | //} | ||
158 | break; | ||
159 | // BYTE | ||
160 | case LSO_Enums.Operation_Table.ADD: | ||
161 | bp1 = br_read(1)[0]; | ||
162 | Common.SendToDebug("Instruction " + idesc + ": Add type: " + ((LSO_Enums.OpCode_Add_TypeDefs)bp1).ToString()); | ||
163 | Common.SendToDebug("Param1: " + bp1); | ||
164 | switch ((LSO_Enums.OpCode_Add_TypeDefs)bp1) | ||
165 | { | ||
166 | case LSO_Enums.OpCode_Add_TypeDefs.String: | ||
167 | Common.SendToDebug("Instruction " + idesc | ||
168 | + ": il.Emit(OpCodes.Call, typeof(System.String).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) }));"); | ||
169 | il.Emit(OpCodes.Call, typeof(System.String).GetMethod | ||
170 | ("Concat", new Type[] { typeof(object), typeof(object) })); | ||
69 | 171 | ||
70 | // LONG | ||
71 | case LSO_Enums.Operation_Table.STORE: | ||
72 | case LSO_Enums.Operation_Table.STORES: | ||
73 | case LSO_Enums.Operation_Table.STOREL: | ||
74 | case LSO_Enums.Operation_Table.STOREV: | ||
75 | case LSO_Enums.Operation_Table.STOREQ: | ||
76 | case LSO_Enums.Operation_Table.STOREG: | ||
77 | case LSO_Enums.Operation_Table.STOREGS: | ||
78 | case LSO_Enums.Operation_Table.STOREGL: | ||
79 | case LSO_Enums.Operation_Table.STOREGV: | ||
80 | case LSO_Enums.Operation_Table.STOREGQ: | ||
81 | case LSO_Enums.Operation_Table.LOADP: | ||
82 | case LSO_Enums.Operation_Table.LOADSP: | ||
83 | case LSO_Enums.Operation_Table.LOADLP: | ||
84 | case LSO_Enums.Operation_Table.LOADVP: | ||
85 | case LSO_Enums.Operation_Table.LOADQP: | ||
86 | case LSO_Enums.Operation_Table.PUSH: | ||
87 | case LSO_Enums.Operation_Table.PUSHS: | ||
88 | case LSO_Enums.Operation_Table.PUSHL: | ||
89 | case LSO_Enums.Operation_Table.PUSHV: | ||
90 | case LSO_Enums.Operation_Table.PUSHQ: | ||
91 | case LSO_Enums.Operation_Table.PUSHG: | ||
92 | case LSO_Enums.Operation_Table.PUSHGS: | ||
93 | case LSO_Enums.Operation_Table.PUSHGL: | ||
94 | case LSO_Enums.Operation_Table.PUSHGV: | ||
95 | case LSO_Enums.Operation_Table.PUSHGQ: | ||
96 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
97 | break; | ||
98 | // None | ||
99 | case LSO_Enums.Operation_Table.PUSHIP: | ||
100 | case LSO_Enums.Operation_Table.PUSHBP: | ||
101 | case LSO_Enums.Operation_Table.PUSHSP: | ||
102 | // Push Stack Top (Memory Address) to stack | ||
103 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, " + myHeader.SP + ");"); | ||
104 | Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack"); | ||
105 | il.Emit(OpCodes.Ldc_I4, myHeader.SP); | ||
106 | break; | ||
107 | // BYTE | ||
108 | case LSO_Enums.Operation_Table.PUSHARGB: | ||
109 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
110 | break; | ||
111 | // INTEGER | ||
112 | case LSO_Enums.Operation_Table.PUSHARGI: | ||
113 | // TODO: What is size of integer? | ||
114 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
115 | Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes.Ldc_I4, " + u32p1 + ");"); | ||
116 | Common.SendToDebug("Param1: " + u32p1); | ||
117 | il.Emit(OpCodes.Ldc_I4, u32p1); | ||
118 | break; | ||
119 | // FLOAT | ||
120 | case LSO_Enums.Operation_Table.PUSHARGF: | ||
121 | // TODO: What is size of float? | ||
122 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
123 | break; | ||
124 | // STRING | ||
125 | case LSO_Enums.Operation_Table.PUSHARGS: | ||
126 | string s = Read_String(); | ||
127 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldstr, \"" + s + "\");"); | ||
128 | Common.SendToDebug("Param1: " + s); | ||
129 | il.Emit(OpCodes.Ldstr, s); | ||
130 | break; | 172 | break; |
131 | // VECTOR z,y,x | 173 | case LSO_Enums.OpCode_Add_TypeDefs.UInt32: |
132 | case LSO_Enums.Operation_Table.PUSHARGV: | 174 | default: |
133 | Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); | 175 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Add);"); |
134 | Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); | 176 | il.Emit(OpCodes.Add); |
135 | Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
136 | break; | 177 | break; |
137 | // ROTATION s,z,y,x | 178 | } |
138 | case LSO_Enums.Operation_Table.PUSHARGQ: | ||
139 | Common.SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
140 | Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
141 | Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
142 | Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
143 | break; | ||
144 | // LONG | ||
145 | case LSO_Enums.Operation_Table.PUSHARGE: | ||
146 | u32p1 = BitConverter.ToUInt32(br_read(4), 0); | ||
147 | //Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes., " + u32p1 + ");"); | ||
148 | Common.SendToDebug("Instruction " + idesc + ": Ignoring (not in use according to doc)"); | ||
149 | //Common.SendToDebug("Instruction " + idesc + ": Description: Pushes X bytes of $00 onto the stack (used to put space for local variable memory for a call)"); | ||
150 | Common.SendToDebug("Param1: " + u32p1); | ||
151 | //il.Emit(OpCodes.ldc_i4, u32p1); | ||
152 | //if (u32p1 > 0) { | ||
153 | //for (int _ic=0; _ic < u32p1; _ic++) | ||
154 | //{ | ||
155 | // Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldnull);"); | ||
156 | // il.Emit(OpCodes.Ldnull); | ||
157 | //} | ||
158 | break; | ||
159 | // BYTE | ||
160 | case LSO_Enums.Operation_Table.ADD: | ||
161 | bp1 = br_read(1)[0]; | ||
162 | Common.SendToDebug("Instruction " + idesc + ": Add type: " + ((LSO_Enums.OpCode_Add_TypeDefs)bp1).ToString()); | ||
163 | Common.SendToDebug("Param1: " + bp1); | ||
164 | switch ((LSO_Enums.OpCode_Add_TypeDefs)bp1) | ||
165 | { | ||
166 | case LSO_Enums.OpCode_Add_TypeDefs.String: | ||
167 | Common.SendToDebug("Instruction " + idesc | ||
168 | + ": il.Emit(OpCodes.Call, typeof(System.String).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) }));"); | ||
169 | il.Emit(OpCodes.Call, typeof(System.String).GetMethod | ||
170 | ("Concat", new Type[] { typeof(object), typeof(object) })); | ||
171 | 179 | ||
172 | break; | ||
173 | case LSO_Enums.OpCode_Add_TypeDefs.UInt32: | ||
174 | default: | ||
175 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Add);"); | ||
176 | il.Emit(OpCodes.Add); | ||
177 | break; | ||
178 | } | ||
179 | 180 | ||
180 | 181 | //il.Emit(OpCodes.Add, p1); | |
181 | //il.Emit(OpCodes.Add, p1); | 182 | break; |
182 | break; | 183 | case LSO_Enums.Operation_Table.SUB: |
183 | case LSO_Enums.Operation_Table.SUB: | 184 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Sub);"); |
184 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Sub);"); | ||
185 | bp1 = br_read(1)[0]; | ||
186 | Common.SendToDebug("Param1: " + bp1); | ||
187 | il.Emit(OpCodes.Sub); | ||
188 | //il.Emit(OpCodes.Sub, p1); | ||
189 | break; | ||
190 | case LSO_Enums.Operation_Table.MUL: | ||
191 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Mul);"); | ||
192 | bp1 = br_read(1)[0]; | 185 | bp1 = br_read(1)[0]; |
193 | Common.SendToDebug("Param1: " + bp1); | 186 | Common.SendToDebug("Param1: " + bp1); |
194 | il.Emit(OpCodes.Mul); | 187 | il.Emit(OpCodes.Sub); |
195 | //il.Emit(OpCodes.Mul, p1); | 188 | //il.Emit(OpCodes.Sub, p1); |
196 | break; | 189 | break; |
197 | case LSO_Enums.Operation_Table.DIV: | 190 | case LSO_Enums.Operation_Table.MUL: |
198 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Div);"); | 191 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Mul);"); |
199 | bp1 = br_read(1)[0]; | 192 | bp1 = br_read(1)[0]; |
200 | Common.SendToDebug("Param1: " + bp1); | 193 | Common.SendToDebug("Param1: " + bp1); |
201 | il.Emit(OpCodes.Div); | 194 | il.Emit(OpCodes.Mul); |
202 | //il.Emit(OpCodes.Div, p1); | 195 | //il.Emit(OpCodes.Mul, p1); |
203 | break; | 196 | break; |
204 | case LSO_Enums.Operation_Table.EQ: | 197 | case LSO_Enums.Operation_Table.DIV: |
205 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ceq);"); | 198 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Div);"); |
206 | bp1 = br_read(1)[0]; | 199 | bp1 = br_read(1)[0]; |
207 | Common.SendToDebug("Param1: " + bp1); | 200 | Common.SendToDebug("Param1: " + bp1); |
208 | il.Emit(OpCodes.Ceq); | 201 | il.Emit(OpCodes.Div); |
209 | //il.Emit(OpCodes.Ceq, p1); | 202 | //il.Emit(OpCodes.Div, p1); |
210 | break; | 203 | break; |
211 | case LSO_Enums.Operation_Table.NEQ: | 204 | case LSO_Enums.Operation_Table.EQ: |
212 | case LSO_Enums.Operation_Table.LEQ: | 205 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ceq);"); |
213 | case LSO_Enums.Operation_Table.GEQ: | 206 | bp1 = br_read(1)[0]; |
214 | case LSO_Enums.Operation_Table.LESS: | 207 | Common.SendToDebug("Param1: " + bp1); |
215 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Clt_Un);"); | 208 | il.Emit(OpCodes.Ceq); |
216 | bp1 = br_read(1)[0]; | 209 | //il.Emit(OpCodes.Ceq, p1); |
217 | Common.SendToDebug("Param1: " + bp1); | 210 | break; |
218 | il.Emit(OpCodes.Clt_Un); | 211 | case LSO_Enums.Operation_Table.NEQ: |
219 | //il.Emit(OpCodes.Clt, p1); | 212 | case LSO_Enums.Operation_Table.LEQ: |
220 | break; | 213 | case LSO_Enums.Operation_Table.GEQ: |
221 | case LSO_Enums.Operation_Table.GREATER: | 214 | case LSO_Enums.Operation_Table.LESS: |
222 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Cgt_Un);"); | 215 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Clt_Un);"); |
223 | bp1 = br_read(1)[0]; | 216 | bp1 = br_read(1)[0]; |
224 | Common.SendToDebug("Param1: " + bp1); | 217 | Common.SendToDebug("Param1: " + bp1); |
225 | il.Emit(OpCodes.Cgt_Un); | 218 | il.Emit(OpCodes.Clt_Un); |
226 | //il.Emit(OpCodes.Cgt, p1); | 219 | //il.Emit(OpCodes.Clt, p1); |
227 | break; | 220 | break; |
228 | case LSO_Enums.Operation_Table.MOD: | 221 | case LSO_Enums.Operation_Table.GREATER: |
229 | case LSO_Enums.Operation_Table.BOOLOR: | 222 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Cgt_Un);"); |
230 | bp1 = br_read(1)[0]; | 223 | bp1 = br_read(1)[0]; |
231 | Common.SendToDebug("Param1: " + bp1); | 224 | Common.SendToDebug("Param1: " + bp1); |
232 | break; | 225 | il.Emit(OpCodes.Cgt_Un); |
233 | // LONG | 226 | //il.Emit(OpCodes.Cgt, p1); |
234 | case LSO_Enums.Operation_Table.JUMP: | 227 | break; |
235 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | 228 | case LSO_Enums.Operation_Table.MOD: |
236 | break; | 229 | case LSO_Enums.Operation_Table.BOOLOR: |
237 | // BYTE, LONG | 230 | bp1 = br_read(1)[0]; |
238 | case LSO_Enums.Operation_Table.JUMPIF: | 231 | Common.SendToDebug("Param1: " + bp1); |
239 | case LSO_Enums.Operation_Table.JUMPNIF: | 232 | break; |
240 | Common.SendToDebug("Param1: " + br_read(1)[0]); | 233 | // LONG |
241 | Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); | 234 | case LSO_Enums.Operation_Table.JUMP: |
242 | break; | 235 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); |
243 | // LONG | 236 | break; |
244 | case LSO_Enums.Operation_Table.STATE: | 237 | // BYTE, LONG |
245 | bp1 = br_read(1)[0]; | 238 | case LSO_Enums.Operation_Table.JUMPIF: |
246 | //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack | 239 | case LSO_Enums.Operation_Table.JUMPNIF: |
247 | //il.Emit(OpCodes.Ldc_I4, 0); // Push index position | 240 | Common.SendToDebug("Param1: " + br_read(1)[0]); |
248 | //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value | 241 | Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); |
249 | //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value | 242 | break; |
250 | break; | 243 | // LONG |
251 | case LSO_Enums.Operation_Table.CALL: | 244 | case LSO_Enums.Operation_Table.STATE: |
252 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | 245 | bp1 = br_read(1)[0]; |
253 | break; | 246 | //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack |
254 | // BYTE | 247 | //il.Emit(OpCodes.Ldc_I4, 0); // Push index position |
255 | case LSO_Enums.Operation_Table.CAST: | 248 | //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value |
256 | bp1 = br_read(1)[0]; | 249 | //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value |
257 | Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)); | 250 | break; |
258 | Common.SendToDebug("Param1: " + bp1); | 251 | case LSO_Enums.Operation_Table.CALL: |
259 | switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1) | 252 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); |
260 | { | 253 | break; |
261 | case LSO_Enums.OpCode_Cast_TypeDefs.String: | 254 | // BYTE |
262 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Calli, typeof(System.Convert).GetMethod(\"ToString\", new Type[] { typeof(object) }));"); | 255 | case LSO_Enums.Operation_Table.CAST: |
263 | //il.Emit(OpCodes.Box, typeof (UInt32)); | 256 | bp1 = br_read(1)[0]; |
264 | il.Emit(OpCodes.Calli, typeof(Common).GetMethod | 257 | Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)); |
265 | ("Cast_ToString", new Type[] { typeof(object) })); | 258 | Common.SendToDebug("Param1: " + bp1); |
266 | 259 | switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1) | |
267 | //il.Emit(OpCodes.Box, typeof(System.UInt32) ); | 260 | { |
268 | //il.Emit(OpCodes.Box, typeof(string)); | 261 | case LSO_Enums.OpCode_Cast_TypeDefs.String: |
262 | Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Calli, typeof(System.Convert).GetMethod(\"ToString\", new Type[] { typeof(object) }));"); | ||
263 | //il.Emit(OpCodes.Box, typeof (UInt32)); | ||
264 | il.Emit(OpCodes.Calli, typeof(Common).GetMethod | ||
265 | ("Cast_ToString", new Type[] { typeof(object) })); | ||
266 | |||
267 | //il.Emit(OpCodes.Box, typeof(System.UInt32) ); | ||
268 | //il.Emit(OpCodes.Box, typeof(string)); | ||
269 | |||
270 | //il.Emit(OpCodes.Conv_R8); | ||
271 | //il.Emit(OpCodes.Call, typeof(System.Convert).GetMethod | ||
272 | // ("ToString", new Type[] { typeof(float) })); | ||
269 | 273 | ||
270 | //il.Emit(OpCodes.Conv_R8); | ||
271 | //il.Emit(OpCodes.Call, typeof(System.Convert).GetMethod | ||
272 | // ("ToString", new Type[] { typeof(float) })); | ||
273 | |||
274 | break; | ||
275 | default: | ||
276 | Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); | ||
277 | break; | ||
278 | } | ||
279 | break; | ||
280 | // LONG | ||
281 | case LSO_Enums.Operation_Table.STACKTOS: | ||
282 | case LSO_Enums.Operation_Table.STACKTOL: | ||
283 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); | ||
284 | break; | 274 | break; |
285 | // BYTE | 275 | default: |
286 | case LSO_Enums.Operation_Table.PRINT: | 276 | Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); |
287 | case LSO_Enums.Operation_Table.CALLLIB: | ||
288 | Common.SendToDebug("Param1: " + br_read(1)[0]); | ||
289 | break; | 277 | break; |
290 | // SHORT | 278 | } |
291 | case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: | 279 | break; |
292 | // TODO: What is size of short? | 280 | // LONG |
293 | UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); | 281 | case LSO_Enums.Operation_Table.STACKTOS: |
294 | Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()); | 282 | case LSO_Enums.Operation_Table.STACKTOL: |
295 | Common.SendToDebug("Param1: " + U16p1); | 283 | Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); |
296 | switch ((LSO_Enums.BuiltIn_Functions)U16p1) | 284 | break; |
297 | { | 285 | // BYTE |
298 | case LSO_Enums.BuiltIn_Functions.llSay: | 286 | case LSO_Enums.Operation_Table.PRINT: |
299 | Common.SendToDebug("Instruction " + idesc + " " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() | 287 | case LSO_Enums.Operation_Table.CALLLIB: |
300 | + ": Mapped to internal function"); | 288 | Common.SendToDebug("Param1: " + br_read(1)[0]); |
301 | 289 | break; | |
302 | //il.Emit(OpCodes.Ldstr, "INTERNAL COMMAND: llSay({0}, \"{1}\""); | 290 | // SHORT |
303 | //il.Emit(OpCodes.Call, typeof(IL_Helper).GetMethod("ReverseFormatString", | 291 | case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: |
304 | // new Type[] { typeof(string), typeof(UInt32), typeof(string) } | 292 | // TODO: What is size of short? |
305 | //)); | 293 | UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); |
294 | Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()); | ||
295 | Common.SendToDebug("Param1: " + U16p1); | ||
296 | switch ((LSO_Enums.BuiltIn_Functions)U16p1) | ||
297 | { | ||
298 | case LSO_Enums.BuiltIn_Functions.llSay: | ||
299 | Common.SendToDebug("Instruction " + idesc + " " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() | ||
300 | + ": Mapped to internal function"); | ||
306 | 301 | ||
302 | //il.Emit(OpCodes.Ldstr, "INTERNAL COMMAND: llSay({0}, \"{1}\""); | ||
303 | //il.Emit(OpCodes.Call, typeof(IL_Helper).GetMethod("ReverseFormatString", | ||
304 | // new Type[] { typeof(string), typeof(UInt32), typeof(string) } | ||
305 | //)); | ||
307 | 306 | ||
308 | //il.Emit(OpCodes.Pop); | ||
309 | //il.Emit(OpCodes.Call, | ||
310 | // typeof(Console).GetMethod("WriteLine", | ||
311 | // new Type[] { typeof(string) } | ||
312 | //)); | ||
313 | 307 | ||
308 | //il.Emit(OpCodes.Pop); | ||
309 | //il.Emit(OpCodes.Call, | ||
310 | // typeof(Console).GetMethod("WriteLine", | ||
311 | // new Type[] { typeof(string) } | ||
312 | //)); | ||
314 | 313 | ||
315 | il.Emit(OpCodes.Call, | ||
316 | typeof(Common).GetMethod("SendToLog", | ||
317 | new Type[] { typeof(string) } | ||
318 | )); | ||
319 | 314 | ||
315 | il.Emit(OpCodes.Call, | ||
316 | typeof(Common).GetMethod("SendToLog", | ||
317 | new Type[] { typeof(string) } | ||
318 | )); | ||
320 | 319 | ||
321 | |||
322 | //il.Emit(OpCodes.Pop); | ||
323 | 320 | ||
324 | //il.Emit(OpCodes.Ldind_I2, 0); | ||
325 | 321 | ||
326 | //il.Emit(OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) })); | 322 | //il.Emit(OpCodes.Pop); |
327 | //il.EmitCalli(OpCodes.Calli, | ||
328 | //il.Emit(OpCodes.Call, typeof().GetMethod | ||
329 | // ("llSay", new Type[] { typeof(UInt32), typeof(string) })); | ||
330 | break; | ||
331 | default: | ||
332 | Common.SendToDebug("Instruction " + idesc + ": " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + ": INTERNAL COMMAND NOT IMPLEMENTED"); | ||
333 | break; | ||
334 | } | ||
335 | |||
336 | //Common.SendToDebug("Instruction " + idesc + ": DEBUG: Faking return code:"); | ||
337 | //Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, 0);"); | ||
338 | //il.Emit(OpCodes.Ldc_I4, 0); | ||
339 | break; | ||
340 | 323 | ||
341 | // RETURN | 324 | //il.Emit(OpCodes.Ldind_I2, 0); |
342 | case LSO_Enums.Operation_Table.RETURN: | ||
343 | 325 | ||
344 | Common.SendToDebug("Last OPCODE was return command. Code chunk execution complete."); | 326 | //il.Emit(OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) })); |
345 | return true; | 327 | //il.EmitCalli(OpCodes.Calli, |
328 | //il.Emit(OpCodes.Call, typeof().GetMethod | ||
329 | // ("llSay", new Type[] { typeof(UInt32), typeof(string) })); | ||
330 | break; | ||
331 | default: | ||
332 | Common.SendToDebug("Instruction " + idesc + ": " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + ": INTERNAL COMMAND NOT IMPLEMENTED"); | ||
333 | break; | ||
346 | } | 334 | } |
347 | return false; | ||
348 | } | ||
349 | 335 | ||
336 | //Common.SendToDebug("Instruction " + idesc + ": DEBUG: Faking return code:"); | ||
337 | //Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, 0);"); | ||
338 | //il.Emit(OpCodes.Ldc_I4, 0); | ||
339 | break; | ||
340 | |||
341 | // RETURN | ||
342 | case LSO_Enums.Operation_Table.RETURN: | ||
343 | |||
344 | Common.SendToDebug("Last OPCODE was return command. Code chunk execution complete."); | ||
345 | return true; | ||
350 | } | 346 | } |
347 | return false; | ||
351 | } | 348 | } |
349 | |||
350 | } | ||
351 | } | ||