| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/execution.h" | 7 #include "src/execution.h" |
| 8 #include "src/handles.h" | 8 #include "src/handles.h" |
| 9 #include "src/interpreter/bytecode-array-builder.h" | 9 #include "src/interpreter/bytecode-array-builder.h" |
| 10 #include "src/interpreter/interpreter.h" | 10 #include "src/interpreter/interpreter.h" |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } // namespace v8 | 94 } // namespace v8 |
| 95 | 95 |
| 96 using v8::internal::BytecodeArray; | 96 using v8::internal::BytecodeArray; |
| 97 using v8::internal::Handle; | 97 using v8::internal::Handle; |
| 98 using v8::internal::Object; | 98 using v8::internal::Object; |
| 99 using v8::internal::Smi; | 99 using v8::internal::Smi; |
| 100 using v8::internal::Token; | 100 using v8::internal::Token; |
| 101 using namespace v8::internal::interpreter; | 101 using namespace v8::internal::interpreter; |
| 102 | 102 |
| 103 TEST(InterpreterReturn) { | 103 TEST(InterpreterReturn) { |
| 104 InitializedHandleScope handles; | 104 HandleAndZoneScope handles; |
| 105 Handle<Object> undefined_value = | 105 Handle<Object> undefined_value = |
| 106 handles.main_isolate()->factory()->undefined_value(); | 106 handles.main_isolate()->factory()->undefined_value(); |
| 107 | 107 |
| 108 BytecodeArrayBuilder builder(handles.main_isolate()); | 108 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 109 builder.set_locals_count(0); | 109 builder.set_locals_count(0); |
| 110 builder.set_parameter_count(1); | 110 builder.set_parameter_count(1); |
| 111 builder.Return(); | 111 builder.Return(); |
| 112 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 112 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 113 | 113 |
| 114 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 114 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 115 auto callable = tester.GetCallable<>(); | 115 auto callable = tester.GetCallable<>(); |
| 116 Handle<Object> return_val = callable().ToHandleChecked(); | 116 Handle<Object> return_val = callable().ToHandleChecked(); |
| 117 CHECK(return_val.is_identical_to(undefined_value)); | 117 CHECK(return_val.is_identical_to(undefined_value)); |
| 118 } | 118 } |
| 119 | 119 |
| 120 | 120 |
| 121 TEST(InterpreterLoadUndefined) { | 121 TEST(InterpreterLoadUndefined) { |
| 122 InitializedHandleScope handles; | 122 HandleAndZoneScope handles; |
| 123 Handle<Object> undefined_value = | 123 Handle<Object> undefined_value = |
| 124 handles.main_isolate()->factory()->undefined_value(); | 124 handles.main_isolate()->factory()->undefined_value(); |
| 125 | 125 |
| 126 BytecodeArrayBuilder builder(handles.main_isolate()); | 126 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 127 builder.set_locals_count(0); | 127 builder.set_locals_count(0); |
| 128 builder.set_parameter_count(1); | 128 builder.set_parameter_count(1); |
| 129 builder.LoadUndefined().Return(); | 129 builder.LoadUndefined().Return(); |
| 130 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 130 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 131 | 131 |
| 132 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 132 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 133 auto callable = tester.GetCallable<>(); | 133 auto callable = tester.GetCallable<>(); |
| 134 Handle<Object> return_val = callable().ToHandleChecked(); | 134 Handle<Object> return_val = callable().ToHandleChecked(); |
| 135 CHECK(return_val.is_identical_to(undefined_value)); | 135 CHECK(return_val.is_identical_to(undefined_value)); |
| 136 } | 136 } |
| 137 | 137 |
| 138 | 138 |
| 139 TEST(InterpreterLoadNull) { | 139 TEST(InterpreterLoadNull) { |
| 140 InitializedHandleScope handles; | 140 HandleAndZoneScope handles; |
| 141 Handle<Object> null_value = handles.main_isolate()->factory()->null_value(); | 141 Handle<Object> null_value = handles.main_isolate()->factory()->null_value(); |
| 142 | 142 |
| 143 BytecodeArrayBuilder builder(handles.main_isolate()); | 143 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 144 builder.set_locals_count(0); | 144 builder.set_locals_count(0); |
| 145 builder.set_parameter_count(1); | 145 builder.set_parameter_count(1); |
| 146 builder.LoadNull().Return(); | 146 builder.LoadNull().Return(); |
| 147 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 147 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 148 | 148 |
| 149 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 149 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 150 auto callable = tester.GetCallable<>(); | 150 auto callable = tester.GetCallable<>(); |
| 151 Handle<Object> return_val = callable().ToHandleChecked(); | 151 Handle<Object> return_val = callable().ToHandleChecked(); |
| 152 CHECK(return_val.is_identical_to(null_value)); | 152 CHECK(return_val.is_identical_to(null_value)); |
| 153 } | 153 } |
| 154 | 154 |
| 155 | 155 |
| 156 TEST(InterpreterLoadTheHole) { | 156 TEST(InterpreterLoadTheHole) { |
| 157 InitializedHandleScope handles; | 157 HandleAndZoneScope handles; |
| 158 Handle<Object> the_hole_value = | 158 Handle<Object> the_hole_value = |
| 159 handles.main_isolate()->factory()->the_hole_value(); | 159 handles.main_isolate()->factory()->the_hole_value(); |
| 160 | 160 |
| 161 BytecodeArrayBuilder builder(handles.main_isolate()); | 161 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 162 builder.set_locals_count(0); | 162 builder.set_locals_count(0); |
| 163 builder.set_parameter_count(1); | 163 builder.set_parameter_count(1); |
| 164 builder.LoadTheHole().Return(); | 164 builder.LoadTheHole().Return(); |
| 165 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 165 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 166 | 166 |
| 167 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 167 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 168 auto callable = tester.GetCallable<>(); | 168 auto callable = tester.GetCallable<>(); |
| 169 Handle<Object> return_val = callable().ToHandleChecked(); | 169 Handle<Object> return_val = callable().ToHandleChecked(); |
| 170 CHECK(return_val.is_identical_to(the_hole_value)); | 170 CHECK(return_val.is_identical_to(the_hole_value)); |
| 171 } | 171 } |
| 172 | 172 |
| 173 | 173 |
| 174 TEST(InterpreterLoadTrue) { | 174 TEST(InterpreterLoadTrue) { |
| 175 InitializedHandleScope handles; | 175 HandleAndZoneScope handles; |
| 176 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 176 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); |
| 177 | 177 |
| 178 BytecodeArrayBuilder builder(handles.main_isolate()); | 178 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 179 builder.set_locals_count(0); | 179 builder.set_locals_count(0); |
| 180 builder.set_parameter_count(1); | 180 builder.set_parameter_count(1); |
| 181 builder.LoadTrue().Return(); | 181 builder.LoadTrue().Return(); |
| 182 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 182 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 183 | 183 |
| 184 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 184 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 185 auto callable = tester.GetCallable<>(); | 185 auto callable = tester.GetCallable<>(); |
| 186 Handle<Object> return_val = callable().ToHandleChecked(); | 186 Handle<Object> return_val = callable().ToHandleChecked(); |
| 187 CHECK(return_val.is_identical_to(true_value)); | 187 CHECK(return_val.is_identical_to(true_value)); |
| 188 } | 188 } |
| 189 | 189 |
| 190 | 190 |
| 191 TEST(InterpreterLoadFalse) { | 191 TEST(InterpreterLoadFalse) { |
| 192 InitializedHandleScope handles; | 192 HandleAndZoneScope handles; |
| 193 Handle<Object> false_value = handles.main_isolate()->factory()->false_value(); | 193 Handle<Object> false_value = handles.main_isolate()->factory()->false_value(); |
| 194 | 194 |
| 195 BytecodeArrayBuilder builder(handles.main_isolate()); | 195 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 196 builder.set_locals_count(0); | 196 builder.set_locals_count(0); |
| 197 builder.set_parameter_count(1); | 197 builder.set_parameter_count(1); |
| 198 builder.LoadFalse().Return(); | 198 builder.LoadFalse().Return(); |
| 199 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 199 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 200 | 200 |
| 201 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 201 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 202 auto callable = tester.GetCallable<>(); | 202 auto callable = tester.GetCallable<>(); |
| 203 Handle<Object> return_val = callable().ToHandleChecked(); | 203 Handle<Object> return_val = callable().ToHandleChecked(); |
| 204 CHECK(return_val.is_identical_to(false_value)); | 204 CHECK(return_val.is_identical_to(false_value)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 | 207 |
| 208 TEST(InterpreterLoadLiteral) { | 208 TEST(InterpreterLoadLiteral) { |
| 209 InitializedHandleScope handles; | 209 HandleAndZoneScope handles; |
| 210 i::Factory* factory = handles.main_isolate()->factory(); |
| 211 |
| 212 // Small Smis. |
| 210 for (int i = -128; i < 128; i++) { | 213 for (int i = -128; i < 128; i++) { |
| 211 BytecodeArrayBuilder builder(handles.main_isolate()); | 214 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 212 builder.set_locals_count(0); | 215 builder.set_locals_count(0); |
| 213 builder.set_parameter_count(1); | 216 builder.set_parameter_count(1); |
| 214 builder.LoadLiteral(Smi::FromInt(i)).Return(); | 217 builder.LoadLiteral(Smi::FromInt(i)).Return(); |
| 215 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 218 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 216 | 219 |
| 217 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 220 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 218 auto callable = tester.GetCallable<>(); | 221 auto callable = tester.GetCallable<>(); |
| 219 Handle<Object> return_val = callable().ToHandleChecked(); | 222 Handle<Object> return_val = callable().ToHandleChecked(); |
| 220 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(i)); | 223 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(i)); |
| 221 } | 224 } |
| 225 |
| 226 // Large Smis. |
| 227 { |
| 228 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 229 builder.set_locals_count(0); |
| 230 builder.set_parameter_count(1); |
| 231 builder.LoadLiteral(Smi::FromInt(0x12345678)).Return(); |
| 232 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 233 |
| 234 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 235 auto callable = tester.GetCallable<>(); |
| 236 Handle<Object> return_val = callable().ToHandleChecked(); |
| 237 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(0x12345678)); |
| 238 } |
| 239 |
| 240 // Heap numbers. |
| 241 { |
| 242 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 243 builder.set_locals_count(0); |
| 244 builder.set_parameter_count(1); |
| 245 builder.LoadLiteral(factory->NewHeapNumber(-2.1e19)).Return(); |
| 246 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 247 |
| 248 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 249 auto callable = tester.GetCallable<>(); |
| 250 Handle<Object> return_val = callable().ToHandleChecked(); |
| 251 CHECK_EQ(i::HeapNumber::cast(*return_val)->value(), -2.1e19); |
| 252 } |
| 253 |
| 254 // Strings. |
| 255 { |
| 256 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 257 builder.set_locals_count(0); |
| 258 builder.set_parameter_count(1); |
| 259 Handle<i::String> string = factory->NewStringFromAsciiChecked("String"); |
| 260 builder.LoadLiteral(string).Return(); |
| 261 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 262 |
| 263 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 264 auto callable = tester.GetCallable<>(); |
| 265 Handle<Object> return_val = callable().ToHandleChecked(); |
| 266 CHECK(i::String::cast(*return_val)->Equals(*string)); |
| 267 } |
| 222 } | 268 } |
| 223 | 269 |
| 224 | 270 |
| 225 TEST(InterpreterLoadStoreRegisters) { | 271 TEST(InterpreterLoadStoreRegisters) { |
| 226 InitializedHandleScope handles; | 272 HandleAndZoneScope handles; |
| 227 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 273 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); |
| 228 for (int i = 0; i <= Register::kMaxRegisterIndex; i++) { | 274 for (int i = 0; i <= Register::kMaxRegisterIndex; i++) { |
| 229 BytecodeArrayBuilder builder(handles.main_isolate()); | 275 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 230 builder.set_locals_count(i + 1); | 276 builder.set_locals_count(i + 1); |
| 231 builder.set_parameter_count(1); | 277 builder.set_parameter_count(1); |
| 232 Register reg(i); | 278 Register reg(i); |
| 233 builder.LoadTrue() | 279 builder.LoadTrue() |
| 234 .StoreAccumulatorInRegister(reg) | 280 .StoreAccumulatorInRegister(reg) |
| 235 .LoadFalse() | 281 .LoadFalse() |
| 236 .LoadAccumulatorWithRegister(reg) | 282 .LoadAccumulatorWithRegister(reg) |
| 237 .Return(); | 283 .Return(); |
| 238 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 284 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 239 | 285 |
| 240 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 286 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 241 auto callable = tester.GetCallable<>(); | 287 auto callable = tester.GetCallable<>(); |
| 242 Handle<Object> return_val = callable().ToHandleChecked(); | 288 Handle<Object> return_val = callable().ToHandleChecked(); |
| 243 CHECK(return_val.is_identical_to(true_value)); | 289 CHECK(return_val.is_identical_to(true_value)); |
| 244 } | 290 } |
| 245 } | 291 } |
| 246 | 292 |
| 247 | 293 |
| 248 TEST(InterpreterAdd) { | 294 TEST(InterpreterAdd) { |
| 249 InitializedHandleScope handles; | 295 HandleAndZoneScope handles; |
| 250 // TODO(rmcilroy): Do add tests for heap numbers and strings once we support | 296 // TODO(rmcilroy): Do add tests for heap numbers and strings once we support |
| 251 // them. | 297 // them. |
| 252 BytecodeArrayBuilder builder(handles.main_isolate()); | 298 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 253 builder.set_locals_count(1); | 299 builder.set_locals_count(1); |
| 254 builder.set_parameter_count(1); | 300 builder.set_parameter_count(1); |
| 255 Register reg(0); | 301 Register reg(0); |
| 256 builder.LoadLiteral(Smi::FromInt(1)) | 302 builder.LoadLiteral(Smi::FromInt(1)) |
| 257 .StoreAccumulatorInRegister(reg) | 303 .StoreAccumulatorInRegister(reg) |
| 258 .LoadLiteral(Smi::FromInt(2)) | 304 .LoadLiteral(Smi::FromInt(2)) |
| 259 .BinaryOperation(Token::Value::ADD, reg) | 305 .BinaryOperation(Token::Value::ADD, reg) |
| 260 .Return(); | 306 .Return(); |
| 261 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 307 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 262 | 308 |
| 263 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 309 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 264 auto callable = tester.GetCallable<>(); | 310 auto callable = tester.GetCallable<>(); |
| 265 Handle<Object> return_val = callable().ToHandleChecked(); | 311 Handle<Object> return_val = callable().ToHandleChecked(); |
| 266 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 312 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
| 267 } | 313 } |
| 268 | 314 |
| 269 | 315 |
| 270 TEST(InterpreterSub) { | 316 TEST(InterpreterSub) { |
| 271 InitializedHandleScope handles; | 317 HandleAndZoneScope handles; |
| 272 // TODO(rmcilroy): Do add tests for heap numbers once we support them. | 318 // TODO(rmcilroy): Do add tests for heap numbers once we support them. |
| 273 BytecodeArrayBuilder builder(handles.main_isolate()); | 319 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 274 builder.set_locals_count(1); | 320 builder.set_locals_count(1); |
| 275 builder.set_parameter_count(1); | 321 builder.set_parameter_count(1); |
| 276 Register reg(0); | 322 Register reg(0); |
| 277 builder.LoadLiteral(Smi::FromInt(5)) | 323 builder.LoadLiteral(Smi::FromInt(5)) |
| 278 .StoreAccumulatorInRegister(reg) | 324 .StoreAccumulatorInRegister(reg) |
| 279 .LoadLiteral(Smi::FromInt(31)) | 325 .LoadLiteral(Smi::FromInt(31)) |
| 280 .BinaryOperation(Token::Value::SUB, reg) | 326 .BinaryOperation(Token::Value::SUB, reg) |
| 281 .Return(); | 327 .Return(); |
| 282 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 328 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 283 | 329 |
| 284 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 330 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 285 auto callable = tester.GetCallable<>(); | 331 auto callable = tester.GetCallable<>(); |
| 286 Handle<Object> return_val = callable().ToHandleChecked(); | 332 Handle<Object> return_val = callable().ToHandleChecked(); |
| 287 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-26)); | 333 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-26)); |
| 288 } | 334 } |
| 289 | 335 |
| 290 | 336 |
| 291 TEST(InterpreterMul) { | 337 TEST(InterpreterMul) { |
| 292 InitializedHandleScope handles; | 338 HandleAndZoneScope handles; |
| 293 // TODO(rmcilroy): Do add tests for heap numbers once we support them. | 339 // TODO(rmcilroy): Do add tests for heap numbers once we support them. |
| 294 BytecodeArrayBuilder builder(handles.main_isolate()); | 340 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 295 builder.set_locals_count(1); | 341 builder.set_locals_count(1); |
| 296 builder.set_parameter_count(1); | 342 builder.set_parameter_count(1); |
| 297 Register reg(0); | 343 Register reg(0); |
| 298 builder.LoadLiteral(Smi::FromInt(111)) | 344 builder.LoadLiteral(Smi::FromInt(111)) |
| 299 .StoreAccumulatorInRegister(reg) | 345 .StoreAccumulatorInRegister(reg) |
| 300 .LoadLiteral(Smi::FromInt(6)) | 346 .LoadLiteral(Smi::FromInt(6)) |
| 301 .BinaryOperation(Token::Value::MUL, reg) | 347 .BinaryOperation(Token::Value::MUL, reg) |
| 302 .Return(); | 348 .Return(); |
| 303 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 349 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 304 | 350 |
| 305 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 351 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 306 auto callable = tester.GetCallable<>(); | 352 auto callable = tester.GetCallable<>(); |
| 307 Handle<Object> return_val = callable().ToHandleChecked(); | 353 Handle<Object> return_val = callable().ToHandleChecked(); |
| 308 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(666)); | 354 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(666)); |
| 309 } | 355 } |
| 310 | 356 |
| 311 | 357 |
| 312 TEST(InterpreterDiv) { | 358 TEST(InterpreterDiv) { |
| 313 InitializedHandleScope handles; | 359 HandleAndZoneScope handles; |
| 314 // TODO(rmcilroy): Do add tests for heap numbers once we support them. | 360 // TODO(rmcilroy): Do add tests for heap numbers once we support them. |
| 315 BytecodeArrayBuilder builder(handles.main_isolate()); | 361 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 316 builder.set_locals_count(1); | 362 builder.set_locals_count(1); |
| 317 builder.set_parameter_count(1); | 363 builder.set_parameter_count(1); |
| 318 Register reg(0); | 364 Register reg(0); |
| 319 builder.LoadLiteral(Smi::FromInt(-20)) | 365 builder.LoadLiteral(Smi::FromInt(-20)) |
| 320 .StoreAccumulatorInRegister(reg) | 366 .StoreAccumulatorInRegister(reg) |
| 321 .LoadLiteral(Smi::FromInt(5)) | 367 .LoadLiteral(Smi::FromInt(5)) |
| 322 .BinaryOperation(Token::Value::DIV, reg) | 368 .BinaryOperation(Token::Value::DIV, reg) |
| 323 .Return(); | 369 .Return(); |
| 324 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 370 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 325 | 371 |
| 326 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 372 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 327 auto callable = tester.GetCallable<>(); | 373 auto callable = tester.GetCallable<>(); |
| 328 Handle<Object> return_val = callable().ToHandleChecked(); | 374 Handle<Object> return_val = callable().ToHandleChecked(); |
| 329 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-4)); | 375 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(-4)); |
| 330 } | 376 } |
| 331 | 377 |
| 332 | 378 |
| 333 TEST(InterpreterMod) { | 379 TEST(InterpreterMod) { |
| 334 InitializedHandleScope handles; | 380 HandleAndZoneScope handles; |
| 335 // TODO(rmcilroy): Do add tests for heap numbers once we support them. | 381 // TODO(rmcilroy): Do add tests for heap numbers once we support them. |
| 336 BytecodeArrayBuilder builder(handles.main_isolate()); | 382 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 337 builder.set_locals_count(1); | 383 builder.set_locals_count(1); |
| 338 builder.set_parameter_count(1); | 384 builder.set_parameter_count(1); |
| 339 Register reg(0); | 385 Register reg(0); |
| 340 builder.LoadLiteral(Smi::FromInt(121)) | 386 builder.LoadLiteral(Smi::FromInt(121)) |
| 341 .StoreAccumulatorInRegister(reg) | 387 .StoreAccumulatorInRegister(reg) |
| 342 .LoadLiteral(Smi::FromInt(100)) | 388 .LoadLiteral(Smi::FromInt(100)) |
| 343 .BinaryOperation(Token::Value::MOD, reg) | 389 .BinaryOperation(Token::Value::MOD, reg) |
| 344 .Return(); | 390 .Return(); |
| 345 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 391 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 346 | 392 |
| 347 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 393 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 348 auto callable = tester.GetCallable<>(); | 394 auto callable = tester.GetCallable<>(); |
| 349 Handle<Object> return_val = callable().ToHandleChecked(); | 395 Handle<Object> return_val = callable().ToHandleChecked(); |
| 350 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(21)); | 396 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(21)); |
| 351 } | 397 } |
| 352 | 398 |
| 353 | 399 |
| 354 TEST(InterpreterParameter1) { | 400 TEST(InterpreterParameter1) { |
| 355 InitializedHandleScope handles; | 401 HandleAndZoneScope handles; |
| 356 BytecodeArrayBuilder builder(handles.main_isolate()); | 402 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 357 builder.set_locals_count(1); | 403 builder.set_locals_count(1); |
| 358 builder.set_parameter_count(1); | 404 builder.set_parameter_count(1); |
| 359 builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return(); | 405 builder.LoadAccumulatorWithRegister(builder.Parameter(0)).Return(); |
| 360 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); | 406 Handle<BytecodeArray> bytecode_array = builder.ToBytecodeArray(); |
| 361 | 407 |
| 362 InterpreterTester tester(handles.main_isolate(), bytecode_array); | 408 InterpreterTester tester(handles.main_isolate(), bytecode_array); |
| 363 auto callable = tester.GetCallable<Handle<Object>>(); | 409 auto callable = tester.GetCallable<Handle<Object>>(); |
| 364 | 410 |
| 365 // Check for heap objects. | 411 // Check for heap objects. |
| 366 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); | 412 Handle<Object> true_value = handles.main_isolate()->factory()->true_value(); |
| 367 Handle<Object> return_val = callable(true_value).ToHandleChecked(); | 413 Handle<Object> return_val = callable(true_value).ToHandleChecked(); |
| 368 CHECK(return_val.is_identical_to(true_value)); | 414 CHECK(return_val.is_identical_to(true_value)); |
| 369 | 415 |
| 370 // Check for Smis. | 416 // Check for Smis. |
| 371 return_val = callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) | 417 return_val = callable(Handle<Smi>(Smi::FromInt(3), handles.main_isolate())) |
| 372 .ToHandleChecked(); | 418 .ToHandleChecked(); |
| 373 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); | 419 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(3)); |
| 374 } | 420 } |
| 375 | 421 |
| 376 | 422 |
| 377 TEST(InterpreterParameter8) { | 423 TEST(InterpreterParameter8) { |
| 378 InitializedHandleScope handles; | 424 HandleAndZoneScope handles; |
| 379 BytecodeArrayBuilder builder(handles.main_isolate()); | 425 BytecodeArrayBuilder builder(handles.main_isolate(), handles.main_zone()); |
| 380 builder.set_locals_count(1); | 426 builder.set_locals_count(1); |
| 381 builder.set_parameter_count(8); | 427 builder.set_parameter_count(8); |
| 382 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) | 428 builder.LoadAccumulatorWithRegister(builder.Parameter(0)) |
| 383 .BinaryOperation(Token::Value::ADD, builder.Parameter(1)) | 429 .BinaryOperation(Token::Value::ADD, builder.Parameter(1)) |
| 384 .BinaryOperation(Token::Value::ADD, builder.Parameter(2)) | 430 .BinaryOperation(Token::Value::ADD, builder.Parameter(2)) |
| 385 .BinaryOperation(Token::Value::ADD, builder.Parameter(3)) | 431 .BinaryOperation(Token::Value::ADD, builder.Parameter(3)) |
| 386 .BinaryOperation(Token::Value::ADD, builder.Parameter(4)) | 432 .BinaryOperation(Token::Value::ADD, builder.Parameter(4)) |
| 387 .BinaryOperation(Token::Value::ADD, builder.Parameter(5)) | 433 .BinaryOperation(Token::Value::ADD, builder.Parameter(5)) |
| 388 .BinaryOperation(Token::Value::ADD, builder.Parameter(6)) | 434 .BinaryOperation(Token::Value::ADD, builder.Parameter(6)) |
| 389 .BinaryOperation(Token::Value::ADD, builder.Parameter(7)) | 435 .BinaryOperation(Token::Value::ADD, builder.Parameter(7)) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 401 Handle<Smi> arg5 = Handle<Smi>(Smi::FromInt(5), handles.main_isolate()); | 447 Handle<Smi> arg5 = Handle<Smi>(Smi::FromInt(5), handles.main_isolate()); |
| 402 Handle<Smi> arg6 = Handle<Smi>(Smi::FromInt(6), handles.main_isolate()); | 448 Handle<Smi> arg6 = Handle<Smi>(Smi::FromInt(6), handles.main_isolate()); |
| 403 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); | 449 Handle<Smi> arg7 = Handle<Smi>(Smi::FromInt(7), handles.main_isolate()); |
| 404 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); | 450 Handle<Smi> arg8 = Handle<Smi>(Smi::FromInt(8), handles.main_isolate()); |
| 405 // Check for Smis. | 451 // Check for Smis. |
| 406 Handle<Object> return_val = | 452 Handle<Object> return_val = |
| 407 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) | 453 callable(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) |
| 408 .ToHandleChecked(); | 454 .ToHandleChecked(); |
| 409 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); | 455 CHECK_EQ(Smi::cast(*return_val), Smi::FromInt(36)); |
| 410 } | 456 } |
| OLD | NEW |