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