OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1882 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 case Yield::INITIAL: | 1893 case Yield::INITIAL: |
1894 case Yield::SUSPEND: { | 1894 case Yield::SUSPEND: { |
1895 VisitForStackValue(expr->generator_object()); | 1895 VisitForStackValue(expr->generator_object()); |
1896 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); | 1896 __ CallRuntime(Runtime::kSuspendJSGeneratorObject, 1); |
1897 __ mov(context_register(), | 1897 __ mov(context_register(), |
1898 Operand(ebp, StandardFrameConstants::kContextOffset)); | 1898 Operand(ebp, StandardFrameConstants::kContextOffset)); |
1899 | 1899 |
1900 Label resume; | 1900 Label resume; |
1901 __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex); | 1901 __ CompareRoot(result_register(), Heap::kTheHoleValueRootIndex); |
1902 __ j(not_equal, &resume); | 1902 __ j(not_equal, &resume); |
1903 __ pop(result_register()); | |
1904 if (expr->yield_kind() == Yield::SUSPEND) { | 1903 if (expr->yield_kind() == Yield::SUSPEND) { |
1905 // TODO(wingo): Box into { value: VALUE, done: false }. | 1904 EmitReturnIteratorResult(false); |
| 1905 } else { |
| 1906 __ pop(result_register()); |
| 1907 EmitReturnSequence(); |
1906 } | 1908 } |
1907 EmitReturnSequence(); | |
1908 | 1909 |
1909 __ bind(&resume); | 1910 __ bind(&resume); |
1910 context()->Plug(result_register()); | 1911 context()->Plug(result_register()); |
1911 break; | 1912 break; |
1912 } | 1913 } |
1913 | 1914 |
1914 case Yield::FINAL: { | 1915 case Yield::FINAL: { |
1915 VisitForAccumulatorValue(expr->generator_object()); | 1916 VisitForAccumulatorValue(expr->generator_object()); |
1916 __ mov(FieldOperand(result_register(), | 1917 __ mov(FieldOperand(result_register(), |
1917 JSGeneratorObject::kContinuationOffset), | 1918 JSGeneratorObject::kContinuationOffset), |
1918 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); | 1919 Immediate(Smi::FromInt(JSGeneratorObject::kGeneratorClosed))); |
1919 __ pop(result_register()); | 1920 EmitReturnIteratorResult(true); |
1920 // TODO(wingo): Box into { value: VALUE, done: true }. | |
1921 | |
1922 // Exit all nested statements. | |
1923 NestedStatement* current = nesting_stack_; | |
1924 int stack_depth = 0; | |
1925 int context_length = 0; | |
1926 while (current != NULL) { | |
1927 current = current->Exit(&stack_depth, &context_length); | |
1928 } | |
1929 __ Drop(stack_depth); | |
1930 EmitReturnSequence(); | |
1931 break; | 1921 break; |
1932 } | 1922 } |
1933 | 1923 |
1934 case Yield::DELEGATING: | 1924 case Yield::DELEGATING: |
1935 UNIMPLEMENTED(); | 1925 UNIMPLEMENTED(); |
1936 } | 1926 } |
1937 } | 1927 } |
1938 | 1928 |
1939 | 1929 |
1940 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, | 1930 void FullCodeGenerator::EmitGeneratorResume(Expression *generator, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2026 // Throw error if we attempt to operate on a running generator. | 2016 // Throw error if we attempt to operate on a running generator. |
2027 __ bind(&wrong_state); | 2017 __ bind(&wrong_state); |
2028 __ push(ebx); | 2018 __ push(ebx); |
2029 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); | 2019 __ CallRuntime(Runtime::kThrowGeneratorStateError, 1); |
2030 | 2020 |
2031 __ bind(&done); | 2021 __ bind(&done); |
2032 context()->Plug(result_register()); | 2022 context()->Plug(result_register()); |
2033 } | 2023 } |
2034 | 2024 |
2035 | 2025 |
| 2026 void FullCodeGenerator::EmitReturnIteratorResult(bool done) { |
| 2027 Label gc_required; |
| 2028 Label allocated; |
| 2029 |
| 2030 Handle<Map> map(isolate()->native_context()->generator_result_map()); |
| 2031 |
| 2032 __ Allocate(map->instance_size(), eax, ecx, edx, &gc_required, TAG_OBJECT); |
| 2033 |
| 2034 __ bind(&allocated); |
| 2035 __ mov(ebx, map); |
| 2036 __ pop(ecx); |
| 2037 __ mov(edx, isolate()->factory()->ToBoolean(done)); |
| 2038 ASSERT_EQ(map->instance_size(), 5 * kPointerSize); |
| 2039 __ mov(FieldOperand(eax, HeapObject::kMapOffset), ebx); |
| 2040 __ mov(FieldOperand(eax, JSObject::kPropertiesOffset), |
| 2041 isolate()->factory()->empty_fixed_array()); |
| 2042 __ mov(FieldOperand(eax, JSObject::kElementsOffset), |
| 2043 isolate()->factory()->empty_fixed_array()); |
| 2044 __ mov(FieldOperand(eax, JSGeneratorObject::kResultValuePropertyOffset), ecx); |
| 2045 __ mov(FieldOperand(eax, JSGeneratorObject::kResultDonePropertyOffset), edx); |
| 2046 |
| 2047 // Only the value field needs a write barrier, as the other values are in the |
| 2048 // root set. |
| 2049 __ RecordWriteField(eax, JSGeneratorObject::kResultValuePropertyOffset, |
| 2050 ecx, edx, kDontSaveFPRegs); |
| 2051 |
| 2052 if (done) { |
| 2053 // Exit all nested statements. |
| 2054 NestedStatement* current = nesting_stack_; |
| 2055 int stack_depth = 0; |
| 2056 int context_length = 0; |
| 2057 while (current != NULL) { |
| 2058 current = current->Exit(&stack_depth, &context_length); |
| 2059 } |
| 2060 __ Drop(stack_depth); |
| 2061 } |
| 2062 |
| 2063 EmitReturnSequence(); |
| 2064 |
| 2065 __ bind(&gc_required); |
| 2066 __ Push(Smi::FromInt(map->instance_size())); |
| 2067 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); |
| 2068 __ mov(context_register(), |
| 2069 Operand(ebp, StandardFrameConstants::kContextOffset)); |
| 2070 __ jmp(&allocated); |
| 2071 } |
| 2072 |
| 2073 |
2036 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { | 2074 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
2037 SetSourcePosition(prop->position()); | 2075 SetSourcePosition(prop->position()); |
2038 Literal* key = prop->key()->AsLiteral(); | 2076 Literal* key = prop->key()->AsLiteral(); |
2039 ASSERT(!key->handle()->IsSmi()); | 2077 ASSERT(!key->handle()->IsSmi()); |
2040 __ mov(ecx, Immediate(key->handle())); | 2078 __ mov(ecx, Immediate(key->handle())); |
2041 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 2079 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
2042 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); | 2080 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
2043 } | 2081 } |
2044 | 2082 |
2045 | 2083 |
(...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4693 *stack_depth = 0; | 4731 *stack_depth = 0; |
4694 *context_length = 0; | 4732 *context_length = 0; |
4695 return previous_; | 4733 return previous_; |
4696 } | 4734 } |
4697 | 4735 |
4698 #undef __ | 4736 #undef __ |
4699 | 4737 |
4700 } } // namespace v8::internal | 4738 } } // namespace v8::internal |
4701 | 4739 |
4702 #endif // V8_TARGET_ARCH_IA32 | 4740 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |