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 STATIC_ASSERT(HeapObject::kMapOffset == 0); | |
2031 STATIC_ASSERT(JSObject::kPropertiesOffset == kPointerSize); | |
2032 STATIC_ASSERT(JSObject::kElementsOffset == 2 * kPointerSize); | |
2033 STATIC_ASSERT(JSObject::kHeaderSize == 3 * kPointerSize); | |
2034 STATIC_ASSERT(JSGeneratorObject::kResultValuePropertyIndex == 0); | |
2035 STATIC_ASSERT(JSGeneratorObject::kResultDonePropertyIndex == 1); | |
2036 | |
2037 const int size = 5 * kPointerSize; | |
Michael Starzinger
2013/05/06 11:22:32
The size should be determined by isolate()->native
| |
2038 __ Allocate(size, eax, ecx, edx, &gc_required, TAG_OBJECT); | |
2039 | |
2040 __ bind(&allocated); | |
2041 // The object is now in eax. Initialize its map, value, and done fields. | |
2042 Handle<Map> map(isolate()->native_context()->iterator_result_map()); | |
2043 __ mov(ebx, map); | |
2044 __ pop(ecx); | |
2045 __ mov(edx, | |
2046 done | |
Michael Starzinger
2013/05/06 11:22:32
Use factory->ToBoolean(done) here.
| |
2047 ? isolate()->factory()->true_value() | |
2048 : isolate()->factory()->false_value()); | |
2049 __ mov(FieldOperand(eax, 0 * kPointerSize), ebx); // map | |
Michael Starzinger
2013/05/06 11:22:32
Same comment as in bootstrapper.cc applies. Can we
| |
2050 __ mov(FieldOperand(eax, 1 * kPointerSize), // properties | |
2051 isolate()->factory()->empty_fixed_array()); | |
2052 __ mov(FieldOperand(eax, 2 * kPointerSize), // elements | |
2053 isolate()->factory()->empty_fixed_array()); | |
2054 __ mov(FieldOperand(eax, 3 * kPointerSize), ecx); // value | |
2055 __ mov(FieldOperand(eax, 4 * kPointerSize), edx); // done? | |
2056 | |
2057 // Only the value field needs a write barrier, as the other values are in the | |
2058 // root set. | |
2059 __ RecordWriteField(eax, 3 * kPointerSize, ecx, edx, kDontSaveFPRegs); | |
2060 | |
2061 if (done) { | |
2062 // Exit all nested statements. | |
2063 NestedStatement* current = nesting_stack_; | |
2064 int stack_depth = 0; | |
2065 int context_length = 0; | |
2066 while (current != NULL) { | |
2067 current = current->Exit(&stack_depth, &context_length); | |
2068 } | |
2069 __ Drop(stack_depth); | |
2070 } | |
2071 | |
2072 EmitReturnSequence(); | |
2073 | |
2074 __ bind(&gc_required); | |
2075 __ Push(Smi::FromInt(size)); | |
2076 __ CallRuntime(Runtime::kAllocateInNewSpace, 1); | |
2077 __ mov(context_register(), | |
2078 Operand(ebp, StandardFrameConstants::kContextOffset)); | |
2079 __ jmp(&allocated); | |
2080 } | |
2081 | |
2082 | |
2036 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { | 2083 void FullCodeGenerator::EmitNamedPropertyLoad(Property* prop) { |
2037 SetSourcePosition(prop->position()); | 2084 SetSourcePosition(prop->position()); |
2038 Literal* key = prop->key()->AsLiteral(); | 2085 Literal* key = prop->key()->AsLiteral(); |
2039 ASSERT(!key->handle()->IsSmi()); | 2086 ASSERT(!key->handle()->IsSmi()); |
2040 __ mov(ecx, Immediate(key->handle())); | 2087 __ mov(ecx, Immediate(key->handle())); |
2041 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); | 2088 Handle<Code> ic = isolate()->builtins()->LoadIC_Initialize(); |
2042 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); | 2089 CallIC(ic, RelocInfo::CODE_TARGET, prop->PropertyFeedbackId()); |
2043 } | 2090 } |
2044 | 2091 |
2045 | 2092 |
(...skipping 2647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4693 *stack_depth = 0; | 4740 *stack_depth = 0; |
4694 *context_length = 0; | 4741 *context_length = 0; |
4695 return previous_; | 4742 return previous_; |
4696 } | 4743 } |
4697 | 4744 |
4698 #undef __ | 4745 #undef __ |
4699 | 4746 |
4700 } } // namespace v8::internal | 4747 } } // namespace v8::internal |
4701 | 4748 |
4702 #endif // V8_TARGET_ARCH_IA32 | 4749 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |