| OLD | NEW |
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 # define BYTECODE(name) case BC_##name: // NOLINT | 70 # define BYTECODE(name) case BC_##name: // NOLINT |
| 71 #endif | 71 #endif |
| 72 | 72 |
| 73 | 73 |
| 74 | 74 |
| 75 static bool RawMatch(const byte* code_base, | 75 static bool RawMatch(const byte* code_base, |
| 76 Vector<const uc16> subject, | 76 Vector<const uc16> subject, |
| 77 int* registers, | 77 int* registers, |
| 78 int current) { | 78 int current) { |
| 79 const byte* pc = code_base; | 79 const byte* pc = code_base; |
| 80 int backtrack_stack[10000]; | 80 static const int kBacktrackStackSize = 10000; |
| 81 int backtrack_stack_space = 10000; | 81 int backtrack_stack[kBacktrackStackSize]; |
| 82 int backtrack_stack_space = kBacktrackStackSize; |
| 82 int* backtrack_sp = backtrack_stack; | 83 int* backtrack_sp = backtrack_stack; |
| 83 int current_char = -1; | 84 int current_char = -1; |
| 84 #ifdef DEBUG | 85 #ifdef DEBUG |
| 85 if (FLAG_trace_regexp_bytecodes) { | 86 if (FLAG_trace_regexp_bytecodes) { |
| 86 PrintF("\n\nStart bytecode interpreter\n\n"); | 87 PrintF("\n\nStart bytecode interpreter\n\n"); |
| 87 } | 88 } |
| 88 #endif | 89 #endif |
| 89 while (true) { | 90 while (true) { |
| 90 switch (*pc) { | 91 switch (*pc) { |
| 91 BYTECODE(BREAK) | 92 BYTECODE(BREAK) |
| (...skipping 25 matching lines...) Expand all Loading... |
| 117 pc += BC_SET_REGISTER_LENGTH; | 118 pc += BC_SET_REGISTER_LENGTH; |
| 118 break; | 119 break; |
| 119 BYTECODE(ADVANCE_REGISTER) | 120 BYTECODE(ADVANCE_REGISTER) |
| 120 registers[pc[1]] += Load32(pc + 2); | 121 registers[pc[1]] += Load32(pc + 2); |
| 121 pc += BC_ADVANCE_REGISTER_LENGTH; | 122 pc += BC_ADVANCE_REGISTER_LENGTH; |
| 122 break; | 123 break; |
| 123 BYTECODE(SET_REGISTER_TO_CP) | 124 BYTECODE(SET_REGISTER_TO_CP) |
| 124 registers[pc[1]] = current + Load32(pc + 2); | 125 registers[pc[1]] = current + Load32(pc + 2); |
| 125 pc += BC_SET_REGISTER_TO_CP_LENGTH; | 126 pc += BC_SET_REGISTER_TO_CP_LENGTH; |
| 126 break; | 127 break; |
| 128 BYTECODE(SET_CP_TO_REGISTER) |
| 129 current = registers[pc[1]]; |
| 130 pc += BC_SET_CP_TO_REGISTER_LENGTH; |
| 131 break; |
| 132 BYTECODE(SET_REGISTER_TO_SP) |
| 133 registers[pc[1]] = backtrack_sp - backtrack_stack; |
| 134 pc += BC_SET_REGISTER_TO_SP_LENGTH; |
| 135 break; |
| 136 BYTECODE(SET_SP_TO_REGISTER) |
| 137 backtrack_sp = backtrack_stack + registers[pc[1]]; |
| 138 backtrack_stack_space = kBacktrackStackSize - |
| 139 (backtrack_sp - backtrack_stack); |
| 140 pc += BC_SET_SP_TO_REGISTER_LENGTH; |
| 141 break; |
| 127 BYTECODE(POP_CP) | 142 BYTECODE(POP_CP) |
| 128 backtrack_stack_space++; | 143 backtrack_stack_space++; |
| 129 --backtrack_sp; | 144 --backtrack_sp; |
| 130 current = *backtrack_sp; | 145 current = *backtrack_sp; |
| 131 pc += BC_POP_CP_LENGTH; | 146 pc += BC_POP_CP_LENGTH; |
| 132 break; | 147 break; |
| 133 BYTECODE(POP_BT) | 148 BYTECODE(POP_BT) |
| 134 backtrack_stack_space++; | 149 backtrack_stack_space++; |
| 135 --backtrack_sp; | 150 --backtrack_sp; |
| 136 pc = code_base + *backtrack_sp; | 151 pc = code_base + *backtrack_sp; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 157 if (pos >= subject.length()) { | 172 if (pos >= subject.length()) { |
| 158 pc = code_base + Load32(pc + 5); | 173 pc = code_base + Load32(pc + 5); |
| 159 } else { | 174 } else { |
| 160 current_char = subject[pos]; | 175 current_char = subject[pos]; |
| 161 pc += BC_LOAD_CURRENT_CHAR_LENGTH; | 176 pc += BC_LOAD_CURRENT_CHAR_LENGTH; |
| 162 } | 177 } |
| 163 break; | 178 break; |
| 164 } | 179 } |
| 165 BYTECODE(CHECK_CHAR) { | 180 BYTECODE(CHECK_CHAR) { |
| 166 int c = Load16(pc + 1); | 181 int c = Load16(pc + 1); |
| 167 if (c != current_char) { | 182 if (c == current_char) { |
| 168 pc = code_base + Load32(pc + 3); | 183 pc = code_base + Load32(pc + 3); |
| 169 } else { | 184 } else { |
| 170 pc += BC_CHECK_CHAR_LENGTH; | 185 pc += BC_CHECK_CHAR_LENGTH; |
| 171 } | 186 } |
| 172 break; | 187 break; |
| 173 } | 188 } |
| 174 BYTECODE(CHECK_NOT_CHAR) { | 189 BYTECODE(CHECK_NOT_CHAR) { |
| 175 int c = Load16(pc + 1); | 190 int c = Load16(pc + 1); |
| 176 if (c == current_char) { | 191 if (c != current_char) { |
| 177 pc = code_base + Load32(pc + 3); | 192 pc = code_base + Load32(pc + 3); |
| 178 } else { | 193 } else { |
| 179 pc += BC_CHECK_NOT_CHAR_LENGTH; | 194 pc += BC_CHECK_NOT_CHAR_LENGTH; |
| 180 } | 195 } |
| 181 break; | 196 break; |
| 182 } | 197 } |
| 183 BYTECODE(CHECK_LT) { | 198 BYTECODE(CHECK_LT) { |
| 184 int limit = Load16(pc + 1); | 199 int limit = Load16(pc + 1); |
| 185 if (current_char < limit) { | 200 if (current_char < limit) { |
| 186 pc = code_base + Load32(pc + 3); | 201 pc = code_base + Load32(pc + 3); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 AssertNoAllocation a; | 305 AssertNoAllocation a; |
| 291 const byte* code_base = code_array->GetDataStartAddress(); | 306 const byte* code_base = code_array->GetDataStartAddress(); |
| 292 return RawMatch(code_base, | 307 return RawMatch(code_base, |
| 293 Vector<const uc16>(subject16->GetTwoByteData(), | 308 Vector<const uc16>(subject16->GetTwoByteData(), |
| 294 subject16->length()), | 309 subject16->length()), |
| 295 registers, | 310 registers, |
| 296 start_position); | 311 start_position); |
| 297 } | 312 } |
| 298 | 313 |
| 299 } } // namespace v8::internal | 314 } } // namespace v8::internal |
| OLD | NEW |