| 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/interpreter/bytecode-generator.h" | 5 #include "src/interpreter/bytecode-generator.h" |
| 6 | 6 |
| 7 #include "src/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
| 10 #include "src/compilation-info.h" | 10 #include "src/compilation-info.h" |
| (...skipping 1847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1858 builder()->LoadLookupGlobalSlot(variable->name(), typeof_mode, | 1858 builder()->LoadLookupGlobalSlot(variable->name(), typeof_mode, |
| 1859 feedback_index(slot), depth); | 1859 feedback_index(slot), depth); |
| 1860 break; | 1860 break; |
| 1861 } | 1861 } |
| 1862 default: | 1862 default: |
| 1863 builder()->LoadLookupSlot(variable->name(), typeof_mode); | 1863 builder()->LoadLookupSlot(variable->name(), typeof_mode); |
| 1864 } | 1864 } |
| 1865 break; | 1865 break; |
| 1866 } | 1866 } |
| 1867 case VariableLocation::MODULE: { | 1867 case VariableLocation::MODULE: { |
| 1868 ModuleDescriptor* descriptor = scope()->GetModuleScope()->module(); | 1868 Register index = register_allocator()->NewRegister(); |
| 1869 if (variable->IsExport()) { | 1869 builder() |
| 1870 auto it = descriptor->regular_exports().find(variable->raw_name()); | 1870 ->LoadLiteral(Smi::FromInt(variable->index())) |
| 1871 DCHECK(it != descriptor->regular_exports().end()); | 1871 .StoreAccumulatorInRegister(index) |
| 1872 Register export_name = register_allocator()->NewRegister(); | 1872 .CallRuntime(Runtime::kLoadModuleVariable, index); |
| 1873 builder() | |
| 1874 ->LoadLiteral(it->second->export_name->string()) | |
| 1875 .StoreAccumulatorInRegister(export_name) | |
| 1876 .CallRuntime(Runtime::kLoadModuleExport, export_name); | |
| 1877 } else { | |
| 1878 auto it = descriptor->regular_imports().find(variable->raw_name()); | |
| 1879 DCHECK(it != descriptor->regular_imports().end()); | |
| 1880 RegisterList args = register_allocator()->NewRegisterList(2); | |
| 1881 builder() | |
| 1882 ->LoadLiteral(it->second->import_name->string()) | |
| 1883 .StoreAccumulatorInRegister(args[0]) | |
| 1884 .LoadLiteral(Smi::FromInt(it->second->module_request)) | |
| 1885 .StoreAccumulatorInRegister(args[1]) | |
| 1886 .CallRuntime(Runtime::kLoadModuleImport, args); | |
| 1887 } | |
| 1888 if (hole_check_mode == HoleCheckMode::kRequired) { | 1873 if (hole_check_mode == HoleCheckMode::kRequired) { |
| 1889 BuildThrowIfHole(variable->name()); | 1874 BuildThrowIfHole(variable->name()); |
| 1890 } | 1875 } |
| 1891 break; | 1876 break; |
| 1892 } | 1877 } |
| 1893 } | 1878 } |
| 1894 } | 1879 } |
| 1895 | 1880 |
| 1896 void BytecodeGenerator::BuildVariableLoadForAccumulatorValue( | 1881 void BytecodeGenerator::BuildVariableLoadForAccumulatorValue( |
| 1897 Variable* variable, FeedbackVectorSlot slot, HoleCheckMode hole_check_mode, | 1882 Variable* variable, FeedbackVectorSlot slot, HoleCheckMode hole_check_mode, |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2045 if (mode == CONST && op != Token::INIT) { | 2030 if (mode == CONST && op != Token::INIT) { |
| 2046 builder()->CallRuntime(Runtime::kThrowConstAssignError); | 2031 builder()->CallRuntime(Runtime::kThrowConstAssignError); |
| 2047 break; | 2032 break; |
| 2048 } | 2033 } |
| 2049 | 2034 |
| 2050 // If we don't throw above, we know that we're dealing with an | 2035 // If we don't throw above, we know that we're dealing with an |
| 2051 // export because imports are const and we do not generate initializing | 2036 // export because imports are const and we do not generate initializing |
| 2052 // assignments for them. | 2037 // assignments for them. |
| 2053 DCHECK(variable->IsExport()); | 2038 DCHECK(variable->IsExport()); |
| 2054 | 2039 |
| 2055 ModuleDescriptor* mod = scope()->GetModuleScope()->module(); | |
| 2056 // There may be several export names for this local name, but it doesn't | |
| 2057 // matter which one we pick, as they all map to the same cell. | |
| 2058 auto it = mod->regular_exports().find(variable->raw_name()); | |
| 2059 DCHECK(it != mod->regular_exports().end()); | |
| 2060 | |
| 2061 RegisterList args = register_allocator()->NewRegisterList(2); | 2040 RegisterList args = register_allocator()->NewRegisterList(2); |
| 2062 builder() | 2041 builder() |
| 2063 ->StoreAccumulatorInRegister(args[1]) | 2042 ->StoreAccumulatorInRegister(args[1]) |
| 2064 .LoadLiteral(it->second->export_name->string()) | 2043 .LoadLiteral(Smi::FromInt(variable->index())) |
| 2065 .StoreAccumulatorInRegister(args[0]); | 2044 .StoreAccumulatorInRegister(args[0]); |
| 2066 if (hole_check_mode == HoleCheckMode::kRequired) { | 2045 if (hole_check_mode == HoleCheckMode::kRequired) { |
| 2067 builder()->CallRuntime(Runtime::kLoadModuleExport, args[0]); | 2046 builder()->CallRuntime(Runtime::kLoadModuleVariable, args[0]); |
| 2068 BuildHoleCheckForVariableAssignment(variable, op); | 2047 BuildHoleCheckForVariableAssignment(variable, op); |
| 2069 } | 2048 } |
| 2070 builder() | 2049 builder() |
| 2071 ->CallRuntime(Runtime::kStoreModuleExport, args) | 2050 ->CallRuntime(Runtime::kStoreModuleVariable, args) |
| 2072 .LoadAccumulatorWithRegister(args[1]); | 2051 .LoadAccumulatorWithRegister(args[1]); |
| 2073 break; | 2052 break; |
| 2074 } | 2053 } |
| 2075 } | 2054 } |
| 2076 } | 2055 } |
| 2077 | 2056 |
| 2078 void BytecodeGenerator::VisitAssignment(Assignment* expr) { | 2057 void BytecodeGenerator::VisitAssignment(Assignment* expr) { |
| 2079 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); | 2058 DCHECK(expr->target()->IsValidReferenceExpressionOrThis()); |
| 2080 Register object, key; | 2059 Register object, key; |
| 2081 RegisterList super_property_args; | 2060 RegisterList super_property_args; |
| (...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3216 } | 3195 } |
| 3217 | 3196 |
| 3218 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { | 3197 Runtime::FunctionId BytecodeGenerator::StoreKeyedToSuperRuntimeId() { |
| 3219 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict | 3198 return is_strict(language_mode()) ? Runtime::kStoreKeyedToSuper_Strict |
| 3220 : Runtime::kStoreKeyedToSuper_Sloppy; | 3199 : Runtime::kStoreKeyedToSuper_Sloppy; |
| 3221 } | 3200 } |
| 3222 | 3201 |
| 3223 } // namespace interpreter | 3202 } // namespace interpreter |
| 3224 } // namespace internal | 3203 } // namespace internal |
| 3225 } // namespace v8 | 3204 } // namespace v8 |
| OLD | NEW |