11cb0ef41Sopenharmony_ci// Copyright 2019 the V8 project authors. All rights reserved.
21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be
31cb0ef41Sopenharmony_ci// found in the LICENSE file.
41cb0ef41Sopenharmony_ci
51cb0ef41Sopenharmony_ci@abstract
61cb0ef41Sopenharmony_ciextern class FixedArrayBase extends HeapObject {
71cb0ef41Sopenharmony_ci  // length of the array.
81cb0ef41Sopenharmony_ci  const length: Smi;
91cb0ef41Sopenharmony_ci}
101cb0ef41Sopenharmony_ci
111cb0ef41Sopenharmony_ci@generateBodyDescriptor
121cb0ef41Sopenharmony_ciextern class FixedArray extends FixedArrayBase {
131cb0ef41Sopenharmony_ci  objects[length]: Object;
141cb0ef41Sopenharmony_ci}
151cb0ef41Sopenharmony_ci
161cb0ef41Sopenharmony_citype EmptyFixedArray extends FixedArray;
171cb0ef41Sopenharmony_ci
181cb0ef41Sopenharmony_ciextern class FixedDoubleArray extends FixedArrayBase {
191cb0ef41Sopenharmony_ci  floats[length]: float64_or_hole;
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci@generateBodyDescriptor
231cb0ef41Sopenharmony_ciextern class WeakFixedArray extends HeapObject {
241cb0ef41Sopenharmony_ci  const length: Smi;
251cb0ef41Sopenharmony_ci  @cppRelaxedLoad objects[length]: MaybeObject;
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ciextern class ByteArray extends FixedArrayBase { bytes[length]: uint8; }
291cb0ef41Sopenharmony_ci
301cb0ef41Sopenharmony_ci@hasSameInstanceTypeAsParent
311cb0ef41Sopenharmony_ci@doNotGenerateCast
321cb0ef41Sopenharmony_ciextern class ArrayList extends FixedArray {
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci@hasSameInstanceTypeAsParent
361cb0ef41Sopenharmony_ci@doNotGenerateCast
371cb0ef41Sopenharmony_ciextern class TemplateList extends FixedArray {
381cb0ef41Sopenharmony_ci}
391cb0ef41Sopenharmony_ci
401cb0ef41Sopenharmony_ci@generateBodyDescriptor
411cb0ef41Sopenharmony_ciextern class WeakArrayList extends HeapObject {
421cb0ef41Sopenharmony_ci  const capacity: Smi;
431cb0ef41Sopenharmony_ci  length: Smi;
441cb0ef41Sopenharmony_ci  @cppRelaxedLoad objects[capacity]: MaybeObject;
451cb0ef41Sopenharmony_ci}
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ciextern operator '.length_intptr' macro LoadAndUntagFixedArrayBaseLength(
481cb0ef41Sopenharmony_ci    FixedArrayBase): intptr;
491cb0ef41Sopenharmony_ci
501cb0ef41Sopenharmony_ciextern operator '.objects[]' macro LoadFixedArrayElement(
511cb0ef41Sopenharmony_ci    FixedArray, intptr): Object;
521cb0ef41Sopenharmony_ciextern operator '.objects[]' macro LoadFixedArrayElement(
531cb0ef41Sopenharmony_ci    FixedArray, Smi): Object;
541cb0ef41Sopenharmony_ciextern operator '.objects[]' macro LoadFixedArrayElement(
551cb0ef41Sopenharmony_ci    FixedArray, constexpr int31): Object;
561cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
571cb0ef41Sopenharmony_ci    FixedArray, intptr, Smi): void;
581cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
591cb0ef41Sopenharmony_ci    FixedArray, Smi, Smi): void;
601cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
611cb0ef41Sopenharmony_ci    FixedArray, intptr, HeapObject): void;
621cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
631cb0ef41Sopenharmony_ci    FixedArray, intptr, Object): void;
641cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
651cb0ef41Sopenharmony_ci    FixedArray, constexpr int31, Smi): void;
661cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
671cb0ef41Sopenharmony_ci    FixedArray, constexpr int31, HeapObject): void;
681cb0ef41Sopenharmony_ciextern operator '.objects[]=' macro StoreFixedArrayElement(
691cb0ef41Sopenharmony_ci    FixedArray, Smi, Object): void;
701cb0ef41Sopenharmony_ciextern macro StoreFixedArrayElement(
711cb0ef41Sopenharmony_ci    FixedArray, Smi, Object, constexpr WriteBarrierMode): void;
721cb0ef41Sopenharmony_ciextern macro StoreFixedArrayElement(
731cb0ef41Sopenharmony_ci    FixedArray, Smi, Smi, constexpr WriteBarrierMode): void;
741cb0ef41Sopenharmony_ciextern macro StoreFixedArrayElement(
751cb0ef41Sopenharmony_ci    FixedArray, constexpr int31, Object, constexpr WriteBarrierMode): void;
761cb0ef41Sopenharmony_ciextern macro StoreFixedArrayElement(
771cb0ef41Sopenharmony_ci    FixedArray, constexpr int31, Smi, constexpr WriteBarrierMode): void;
781cb0ef41Sopenharmony_ciextern macro StoreFixedArrayElement(
791cb0ef41Sopenharmony_ci    FixedArray, intptr, Object, constexpr WriteBarrierMode): void;
801cb0ef41Sopenharmony_ciextern macro StoreFixedArrayElement(
811cb0ef41Sopenharmony_ci    FixedArray, intptr, Smi, constexpr WriteBarrierMode): void;
821cb0ef41Sopenharmony_ciextern operator '.floats[]=' macro StoreFixedDoubleArrayElement(
831cb0ef41Sopenharmony_ci    FixedDoubleArray, intptr, float64): void;
841cb0ef41Sopenharmony_ciextern operator '.floats[]=' macro StoreFixedDoubleArrayElement(
851cb0ef41Sopenharmony_ci    FixedDoubleArray, Smi, float64): void;
861cb0ef41Sopenharmony_ciextern operator '.floats[]' macro LoadFixedDoubleArrayElement(
871cb0ef41Sopenharmony_ci    FixedDoubleArray, intptr): float64;
881cb0ef41Sopenharmony_cioperator '[]=' macro StoreFixedDoubleArrayDirect(
891cb0ef41Sopenharmony_ci    a: FixedDoubleArray, i: Smi, v: Number): void {
901cb0ef41Sopenharmony_ci  a.floats[i] = Convert<float64_or_hole>(Convert<float64>(v));
911cb0ef41Sopenharmony_ci}
921cb0ef41Sopenharmony_cioperator '[]=' macro StoreFixedArrayDirect(
931cb0ef41Sopenharmony_ci    a: FixedArray, i: Smi, v: Object): void {
941cb0ef41Sopenharmony_ci  a.objects[i] = v;
951cb0ef41Sopenharmony_ci}
961cb0ef41Sopenharmony_ci
971cb0ef41Sopenharmony_ciextern macro AllocateFixedArray(
981cb0ef41Sopenharmony_ci    constexpr ElementsKind, intptr, constexpr AllocationFlag): FixedArrayBase;
991cb0ef41Sopenharmony_ci
1001cb0ef41Sopenharmony_ciextern macro AllocateZeroedFixedArray(intptr): FixedArray;
1011cb0ef41Sopenharmony_ciextern macro AllocateZeroedFixedDoubleArray(intptr): FixedDoubleArray;
1021cb0ef41Sopenharmony_ciextern macro CalculateNewElementsCapacity(Smi): Smi;
1031cb0ef41Sopenharmony_ciextern macro CalculateNewElementsCapacity(intptr): intptr;
1041cb0ef41Sopenharmony_ci
1051cb0ef41Sopenharmony_ciextern macro AllocateFixedArrayWithHoles(
1061cb0ef41Sopenharmony_ci    intptr, constexpr AllocationFlag): FixedArray;
1071cb0ef41Sopenharmony_ciextern macro AllocateFixedDoubleArrayWithHoles(
1081cb0ef41Sopenharmony_ci    intptr, constexpr AllocationFlag): FixedDoubleArray;
1091cb0ef41Sopenharmony_ciextern macro CopyFixedArrayElements(
1101cb0ef41Sopenharmony_ci    constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray,
1111cb0ef41Sopenharmony_ci    intptr, intptr): void;
1121cb0ef41Sopenharmony_ciextern macro CopyFixedArrayElements(
1131cb0ef41Sopenharmony_ci    constexpr ElementsKind, FixedArray, constexpr ElementsKind, FixedArray,
1141cb0ef41Sopenharmony_ci    intptr, intptr, intptr): void;
1151cb0ef41Sopenharmony_ci
1161cb0ef41Sopenharmony_cimacro ExtractFixedArray(
1171cb0ef41Sopenharmony_ci    source: FixedArray, first: intptr, count: intptr,
1181cb0ef41Sopenharmony_ci    capacity: intptr): FixedArray {
1191cb0ef41Sopenharmony_ci  // TODO(turbofan): This should be optimized to use memcpy for initialization.
1201cb0ef41Sopenharmony_ci  return NewFixedArray(
1211cb0ef41Sopenharmony_ci      capacity,
1221cb0ef41Sopenharmony_ci      IteratorSequence<Object>(
1231cb0ef41Sopenharmony_ci          (&source.objects).Iterator(first, first + count),
1241cb0ef41Sopenharmony_ci          ConstantIterator(TheHole)));
1251cb0ef41Sopenharmony_ci}
1261cb0ef41Sopenharmony_cimacro ExtractFixedDoubleArray(
1271cb0ef41Sopenharmony_ci    source: FixedDoubleArray, first: intptr, count: intptr,
1281cb0ef41Sopenharmony_ci    capacity: intptr): FixedDoubleArray|EmptyFixedArray {
1291cb0ef41Sopenharmony_ci  // TODO(turbofan): This should be optimized to use memcpy for initialization.
1301cb0ef41Sopenharmony_ci  return NewFixedDoubleArray(
1311cb0ef41Sopenharmony_ci      capacity,
1321cb0ef41Sopenharmony_ci      IteratorSequence<float64_or_hole>(
1331cb0ef41Sopenharmony_ci          (&source.floats).Iterator(first, first + count),
1341cb0ef41Sopenharmony_ci          ConstantIterator(kDoubleHole)));
1351cb0ef41Sopenharmony_ci}
1361cb0ef41Sopenharmony_ci
1371cb0ef41Sopenharmony_cinamespace runtime {
1381cb0ef41Sopenharmony_ciextern runtime FatalProcessOutOfMemoryInvalidArrayLength(NoContext): never;
1391cb0ef41Sopenharmony_ci}
1401cb0ef41Sopenharmony_ci
1411cb0ef41Sopenharmony_cimacro NewFixedArray<Iterator: type>(length: intptr, it: Iterator): FixedArray {
1421cb0ef41Sopenharmony_ci  if (length == 0) return kEmptyFixedArray;
1431cb0ef41Sopenharmony_ci  if (length > kFixedArrayMaxLength) deferred {
1441cb0ef41Sopenharmony_ci      runtime::FatalProcessOutOfMemoryInvalidArrayLength(kNoContext);
1451cb0ef41Sopenharmony_ci    }
1461cb0ef41Sopenharmony_ci  return new
1471cb0ef41Sopenharmony_ci  FixedArray{map: kFixedArrayMap, length: Convert<Smi>(length), objects: ...it};
1481cb0ef41Sopenharmony_ci}
1491cb0ef41Sopenharmony_ci
1501cb0ef41Sopenharmony_cimacro NewFixedDoubleArray<Iterator: type>(
1511cb0ef41Sopenharmony_ci    length: intptr, it: Iterator): FixedDoubleArray|EmptyFixedArray {
1521cb0ef41Sopenharmony_ci  if (length == 0) return kEmptyFixedArray;
1531cb0ef41Sopenharmony_ci  if (length > kFixedDoubleArrayMaxLength) deferred {
1541cb0ef41Sopenharmony_ci      runtime::FatalProcessOutOfMemoryInvalidArrayLength(kNoContext);
1551cb0ef41Sopenharmony_ci    }
1561cb0ef41Sopenharmony_ci  return new FixedDoubleArray{
1571cb0ef41Sopenharmony_ci    map: kFixedDoubleArrayMap,
1581cb0ef41Sopenharmony_ci    length: Convert<Smi>(length),
1591cb0ef41Sopenharmony_ci    floats: ...it
1601cb0ef41Sopenharmony_ci  };
1611cb0ef41Sopenharmony_ci}
162