diff --git a/lib/_internal/libraries.dart b/lib/_internal/libraries.dart index d1d60b876fb..e0d75b1de1c 100644 --- a/lib/_internal/libraries.dart +++ b/lib/_internal/libraries.dart @@ -69,6 +69,12 @@ const Map LIBRARIES = const { documented: false, platforms: VM_PLATFORM), + "scalarlist": const LibraryInfo( + "scalarlist/scalarlist.dart", + category: "Server", + dart2jsPath: "compiler/implementation/lib/scalarlist.dart", + dart2jsPatchPath: "compiler/implementation/lib/scalarlist_patch.dart"), + "uri": const LibraryInfo( "uri/uri.dart"), diff --git a/lib/compiler/implementation/lib/scalarlist.dart b/lib/compiler/implementation/lib/scalarlist.dart new file mode 100644 index 00000000000..056cc5ce041 --- /dev/null +++ b/lib/compiler/implementation/lib/scalarlist.dart @@ -0,0 +1,19 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// This is a copy of the VM's dart:scalarlist library. This API is not +// usable when running inside a web browser. Nevertheless, we +// provide a mock version of the dart:scalarlist so that we can +// statically analyze programs that use dart:scalarlist. + +/** + * The scalarlist library is used for Dart server applications, + * which run on a stand-alone Dart VM from the command line. + * *This library does not work in browser based applications.* + * + * This library allows you to work with arrays of scalar values + * of various sizes. + */ +#library("dart:scalarlist"); +#source("../../../scalarlist/scalarlist.dart"); diff --git a/lib/compiler/implementation/lib/scalarlist_patch.dart b/lib/compiler/implementation/lib/scalarlist_patch.dart new file mode 100644 index 00000000000..b8df2d4fab9 --- /dev/null +++ b/lib/compiler/implementation/lib/scalarlist_patch.dart @@ -0,0 +1,118 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// This is an empty dummy patch file for the VM dart:scalarlist library. +// This is needed in order to be able to generate documentation for the +// scalarlist library. + +patch class Int8List { + patch factory Int8List(int length) { + throw new UnsupportedOperationException('Int8List'); + } + + patch factory Int8List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Int8List.view'); + } +} + + +patch class Uint8List { + patch factory Uint8List(int length) { + throw new UnsupportedOperationException('Uint8List'); + } + + patch factory Uint8List.view(ByteArray array, + [int start = 0, int length]) { + throw new UnsupportedOperationException('Uint8List.view'); + } +} + + +patch class Int16List { + patch factory Int16List(int length) { + throw new UnsupportedOperationException('Int16List'); + + } + + patch factory Int16List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Int16List.view'); + } +} + + +patch class Uint16List { + patch factory Uint16List(int length) { + throw new UnsupportedOperationException('Uint16List'); + } + + patch factory Uint16List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Uint16List.view'); + } +} + + +patch class Int32List { + patch factory Int32List(int length) { + throw new UnsupportedOperationException('Int32List'); + } + + patch factory Int32List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Int32List.view'); + } +} + + +patch class Uint32List { + patch factory Uint32List(int length) { + throw new UnsupportedOperationException('Uint32List'); + } + + patch factory Uint32List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Uint32List.view'); + } +} + + +patch class Int64List { + patch factory Int64List(int length) { + throw new UnsupportedOperationException('Int64List'); + } + + patch factory Int64List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Int64List.view'); + } +} + + +patch class Uint64List { + patch factory Uint64List(int length) { + throw new UnsupportedOperationException('Uint64List'); + } + + patch factory Uint64List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Uint64List.view'); + } +} + + +patch class Float32List { + patch factory Float32List(int length) { + throw new UnsupportedOperationException('Float32List'); + } + + patch factory Float32List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Float32List.view'); + } +} + + +patch class Float64List { + patch factory Float64List(int length) { + throw new UnsupportedOperationException('Float64List'); + } + + patch factory Float64List.view(ByteArray array, [int start = 0, int length]) { + throw new UnsupportedOperationException('Float64List.view'); + } +} diff --git a/lib/scalarlist/scalarlist.dart b/lib/scalarlist/scalarlist.dart new file mode 100644 index 00000000000..7f1f97f3754 --- /dev/null +++ b/lib/scalarlist/scalarlist.dart @@ -0,0 +1,675 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +// TODO(ager): This should have a #library directive when the VM +// can use normal library structuring. +// +// #library('dart:scalarlist'); + +/** + * A random-access sequence of bytes that also provides random access to + * the fixed-width integers and floating point numbers represented by + * those bytes. Byte arrays may be used to pack and unpack data from + * external sources (such as networks or files systems), and to process + * large quantities of numerical data more efficiently than would be possible + * with ordinary [List] implementations. Byte arrays can save space, by + * eliminating the need for object headers, and time, by eliminating the + * need for data copies. Finally, Byte arrays may be used to intentionally + * reinterpret the bytes representing one arithmetic type as another. + * For example this code fragment determine what 64-bit signed integer + * is represented by the bytes of a 64-bit floating point number: + * + * var ba = new ByteArray(8); + * ba.setFloat64(0, 3.14159265358979323846); + * int huh = ba.getInt64(0); + */ +abstract class ByteArray { + /** + * Returns the length of this byte array, in bytes. + */ + int lengthInBytes(); + + /** + * Returns a [ByteArray] _view_ of a portion of this byte array. + * The returned byte array consists of [length] bytes starting + * at position [start] in this byte array. The returned byte array + * is backed by the same data as this byte array. In other words, + * changes to the returned byte array are visible in this byte array + * and vice-versa. + * + * Throws [IndexOutOfRangeException] if [start] is negative, or if + * `start + length` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [length] is negative. + */ + ByteArray subByteArray([int start, int length]); + + /** + * Returns the (possibly negative) integer represented by the byte at the + * specified [byteOffset] in this byte array, in two's complement binary + * representation. The return value will be between -128 and 127, inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * greater than or equal to the length of this byte array. + */ + int getInt8(int byteOffset); + + /** + * Sets the byte at the specified [byteOffset] in this byte array to the + * two's complement binary representation of the specified [value], which + * must fit in a single byte. In other words, [value] must be between + * -128 and 127, inclusive. + * + * Returns `byteOffset + 1`, which is the offset of the first byte in the + * array after the byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * greater than or equal to the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is less than -128 or + * greater than 127. + */ + int setInt8(int byteOffset, int value); + + /** + * Returns the positive integer represented by the byte at the specified + * [byteOffset] in this byte array, in unsigned binary form. The + * return value will be between 0 and 255, inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * greater than or equal to the length of this byte array. + */ + int getUint8(int byteOffset); + + /** + * Sets the byte at the specified [byteOffset] in this byte array to the + * unsigned binary representation of the specified [value], which must fit + * in a single byte. in other words, [value] must be between 0 and 255, + * inclusive. + * + * Returns `byteOffset + 1`, which is the offset of the first byte in the + * array after the byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, + * or greater than or equal to the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is negative or + * greater than 255. + */ + int setUint8(int byteOffset, int value); + + /** + * Returns the (possibly negative) integer represented by the two bytes at + * the specified [byteOffset] in this byte array, in two's complement binary + * form. The return value will be between 215 and 215 - 1, + * inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 2` is greater than the length of this byte array. + */ + int getInt16(int byteOffset); + + /** + * Sets the two bytes starting at the specified [byteOffset] in this + * byte array to the two's complement binary representation of the specified + * [value], which must fit in two bytes. In other words, [value] must lie + * between 215 and 215 - 1, inclusive. + * + * Returns `byteOffset + 2`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 2` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is less than 215 + * or greater than 215 - 1. + */ + int setInt16(int byteOffset, int value); + + /** + * Returns the positive integer represented by the two bytes starting + * at the specified [byteOffset] in this byte array, in unsigned binary + * form. The return value will be between 0 and 216 - 1, inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 2` is greater than the length of this byte array. + */ + int getUint16(int byteOffset); + + /** + * Sets the two bytes starting at the specified [byteOffset] in this byte + * array to the unsigned binary representation of the specified [value], + * which must fit in two bytes. in other words, [value] must be between + * 0 and 216 - 1, inclusive. + * + * Returns `byteOffset + 2`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 2` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is negative or + * greater than 216 - 1. + */ + int setUint16(int byteOffset, int value); + + /** + * Returns the (possibly negative) integer represented by the four bytes at + * the specified [byteOffset] in this byte array, in two's complement binary + * form. The return value will be between 231 and 231 - 1, + * inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 4` is greater than the length of this byte array. + */ + int getInt32(int byteOffset); + + /** + * Sets the four bytes starting at the specified [byteOffset] in this + * byte array to the two's complement binary representation of the specified + * [value], which must fit in four bytes. In other words, [value] must lie + * between 231 and 231 - 1, inclusive. + * + * Returns `byteOffset + 4`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 4` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is less than 231 + * or greater than 231 - 1. + */ + int setInt32(int byteOffset, int value); + + /** + * Returns the positive integer represented by the four bytes starting + * at the specified [byteOffset] in this byte array, in unsigned binary + * form. The return value will be between 0 and 232 - 1, inclusive. + * + */ + int getUint32(int byteOffset); + + /** + * Sets the four bytes starting at the specified [byteOffset] in this byte + * array to the unsigned binary representation of the specified [value], + * which must fit in four bytes. in other words, [value] must be between + * 0 and 232 - 1, inclusive. + * + * Returns `byteOffset + 4`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 4` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is negative or + * greater than 232 - 1. + */ + int setUint32(int byteOffset, int value); + + /** + * Returns the (possibly negative) integer represented by the eight bytes at + * the specified [byteOffset] in this byte array, in two's complement binary + * form. The return value will be between 263 and 263 - 1, + * inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 8` is greater than the length of this byte array. + */ + int getInt64(int byteOffset); + + /** + * Sets the eight bytes starting at the specified [byteOffset] in this + * byte array to the two's complement binary representation of the specified + * [value], which must fit in eight bytes. In other words, [value] must lie + * between 263 and 263 - 1, inclusive. + * + * Returns `byteOffset + 8`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 8` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is less than 263 + * or greater than 263 - 1. + */ + int setInt64(int byteOffset, int value); + + /** + * Returns the positive integer represented by the eight bytes starting + * at the specified [byteOffset] in this byte array, in unsigned binary + * form. The return value will be between 0 and 264 - 1, inclusive. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 8` is greater than the length of this byte array. + */ + int getUint64(int byteOffset); + + /** + * Sets the eight bytes starting at the specified [byteOffset] in this byte + * array to the unsigned binary representation of the specified [value], + * which must fit in eight bytes. in other words, [value] must be between + * 0 and 264 - 1, inclusive. + * + * Returns `byteOffset + 8`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 8` is greater than the length of this byte array. + * + * Throws [IllegalArgumentException] if [value] is negative or + * greater than 264 - 1. + */ + int setUint64(int byteOffset, int value); + + /** + * Returns the floating point number represented by the four bytes at + * the specified [byteOffset] in this byte array, in IEEE 754 + * single-precision binary floating-point format (binary32). + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 4` is greater than the length of this byte array. + */ + double getFloat32(int byteOffset); + + /** + * Sets the four bytes starting at the specified [byteOffset] in this + * byte array to the IEEE 754 single-precision binary floating-point + * (binary32) representation of the specified [value]. + * + * **Note that this method can lose precision.** The input [value] is + * a 64-bit floating point value, which will be converted to 32-bit + * floating point value by IEEE 754 rounding rules before it is stored. + * If [value] cannot be represented exactly as a binary32, it will be + * converted to the nearest binary32 value. If two binary32 values are + * equally close, the one whose least significant bit is zero will be used. + * Note that finite (but large) values can be converted to infinity, and + * small non-zero values can be converted to zero. + * + * Returns `byteOffset + 4`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 4` is greater than the length of this byte array. + */ + int setFloat32(int byteOffset, double value); + + /** + * Returns the floating point number represented by the eight bytes at + * the specified [byteOffset] in this byte array, in IEEE 754 + * double-precision binary floating-point format (binary64). + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 8` is greater than the length of this byte array. + */ + double getFloat64(int byteOffset); + + /** + * Sets the eight bytes starting at the specified [byteOffset] in this + * byte array to the IEEE 754 double-precision binary floating-point + * (binary64) representation of the specified [value]. + * + * Returns `byteOffset + 8`, which is the offset of the first byte in the + * array after the last byte that was set by this call. This return value can + * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. + * + * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or + * `byteOffset + 8` is greater than the length of this byte array. + */ + int setFloat64(int byteOffset, double value); +} + +/** + * A "mixin interface" that allows a type, typically but not necessarily + * a [List], to be viewed as a [ByteArray]. + */ +abstract class ByteArrayViewable { + /** + * Returns the number of bytes in the representation of each element in + * this list, or the number bytes in the representation of the entire + * object if it is not a list. + */ + int bytesPerElement(); + + /** + * Returns the length of this view, in bytes. + */ + int lengthInBytes(); + + /** + * Returns the byte array view of this object. This view allows the + * byte representation of the object to be read and written directly. + */ + ByteArray asByteArray([int start, int length]); +} + + +/** + * A fixed-length list of 8-bit signed integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Int8List implements List, ByteArrayViewable { + /** + * Creates an [Int8List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Int8List(int length); + + /** + * Creates an [Int8List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Int8List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + */ + external Int8List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 8-bit unsigned integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Uint8List implements List, ByteArrayViewable { + /** + * Creates a [Uint8List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Uint8List(int length); + + /** + * Creates a [Uint8List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Uint8List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + */ + external Uint8List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 16-bit signed integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Int16List implements List, ByteArrayViewable { + /** + * Creates an [Int16List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Int16List(int length); + + /** + * Creates an [Int16List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Int16List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 2 (the size of an "int16" in bytes), or if the + * [start] of the region is not divisible by 2. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 2. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "int16s," or if it + * is not "int16-aligned." + */ + external Int16List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 16-bit unsigned integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Uint16List implements List, ByteArrayViewable { + /** + * Creates a [Uint16List] of the specified length (in elements), all + * of whose elements are initially zero. + */ + external Uint16List(int length); + + /** + * Creates a [Uint16List] _view_ of the specified region in + * the specified byte [array]. Changes in the [Uint16List] will be + * visible in the byte array and vice versa. If the [start] index of the + * region is not specified, it defaults to zero (the first byte in the byte + * array). If the length is not specified, it defaults to null, which + * indicates that the view extends to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 2 (the size of a "uint16" in bytes), or if the + * [start] of the region is not divisible by 2. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 2. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "uint16s," or if it + * is not "uint16-aligned." + */ + external Uint16List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 32-bit signed integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Int32List implements List, ByteArrayViewable { + /** + * Creates an [Int32List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Int32List(int length); + + /** + * Creates an [Int32List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Int32List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 4 (the size of an "int32" in bytes), or if the + * [start] of the region is not divisible by 4. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 4. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "int32s," or if it + * is not "int32-aligned." + */ + external Int32List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 32-bit unsigned integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Uint32List implements List, ByteArrayViewable { + /** + * Creates a [Uint32List] of the specified length (in elements), all + * of whose elements are initially zero. + */ + external Uint32List(int length); + + /** + * Creates a [Uint32List] _view_ of the specified region in + * the specified byte [array]. Changes in the [Uint32] will be + * visible in the byte array and vice versa. If the [start] index of the + * region is not specified, it defaults to zero (the first byte in the byte + * array). If the length is not specified, it defaults to null, which + * indicates that the view extends to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 4 (the size of a "uint32" in bytes), or if the + * [start] of the region is not divisible by 4. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 4. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "uint32s," or if it + * is not "uint32-aligned." + */ + external Uint32List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 64-bit signed integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Int64List implements List, ByteArrayViewable { + /** + * Creates an [Int64List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Int64List(int length); + + /** + * Creates an [Int64List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Int64List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 8 (the size of an "int64" in bytes), or if the + * [start] of the region is not divisible by 8. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 8. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "int64s," or if it + * is not "int64-aligned." + */ + external Int64List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of 64-bit unsigned integers that is viewable as a + * [ByteArray]. For long lists, this implementation will be considerably + * more space- and time-efficient than the default [List] implementation. + */ +class Uint64List implements List, ByteArrayViewable { + /** + * Creates a [Uint64List] of the specified length (in elements), all + * of whose elements are initially zero. + */ + external Uint64List(int length); + + /** + * Creates an [Uint64List] _view_ of the specified region in + * the specified byte [array]. Changes in the [Uint64List] will be + * visible in the byte array and vice versa. If the [start] index of the + * region is not specified, it defaults to zero (the first byte in the byte + * array). If the length is not specified, it defaults to null, which + * indicates that the view extends to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 8 (the size of a "uint64" in bytes), or if the + * [start] of the region is not divisible by 8. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 8. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "uint64s," or if it + * is not "uint64-aligned." + */ + external Uint64List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of IEEE 754 single-precision binary floating-point + * numbers that is viewable as a [ByteArray]. For long lists, this + * implementation will be considerably more space- and time-efficient than + * the default [List] implementation. + */ +class Float32List implements List, ByteArrayViewable { + /** + * Creates a [Float32List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Float32List(int length); + + /** + * Creates a [Float32List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Float32List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 4 (the size of a "float32" in bytes), or if the + * [start] of the region is not divisible by 4. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 4. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "float32s," or if it + * is not "float32-aligned." + */ + external Float32List.view(ByteArray array, [int start, int length]); +} + + +/** + * A fixed-length list of IEEE 754 double-precision binary floating-point + * numbers that is viewable as a [ByteArray]. For long lists, this + * implementation will be considerably more space- and time-efficient than + * the default [List] implementation. + */ +class Float64List implements List, ByteArrayViewable { + /** + * Creates a [Float64List] of the specified length (in elements), all of + * whose elements are initially zero. + */ + external Float64List(int length); + + /** + * Creates a [Float64List] _view_ of the specified region in the specified + * byte [array]. Changes in the [Float64List] will be visible in the byte + * array and vice versa. If the [start] index of the region is not specified, + * it defaults to zero (the first byte in the byte array). If the length is + * not specified, it defaults to null, which indicates that the view extends + * to the end of the byte array. + * + * Throws [IllegalArgumentException] if the length of the specified region + * is not divisible by 8 (the size of a "float64" in bytes), or if the + * [start] of the region is not divisible by 8. If, however, [array] + * is a view of another byte array, this constructor will throw + * [IllegalArgumentException] if the implicit starting position in the + * "ultimately backing" byte array is not divisible by 8. In plain terms, + * this constructor throws [IllegalArgumentException] if the specified + * region does not contain an integral number of "float64s," or if it + * is not "float64-aligned." + */ + external Float64List.view(ByteArray array, [int start, int length]); +} diff --git a/lib/scalarlist/scalarlist_sources.gypi b/lib/scalarlist/scalarlist_sources.gypi new file mode 100644 index 00000000000..86ae9e76b61 --- /dev/null +++ b/lib/scalarlist/scalarlist_sources.gypi @@ -0,0 +1,9 @@ +# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +{ + 'sources': [ + 'scalarlist.dart', + ], +} diff --git a/runtime/bin/dartutils.h b/runtime/bin/dartutils.h index 723c191ada1..27e4e2659e1 100644 --- a/runtime/bin/dartutils.h +++ b/runtime/bin/dartutils.h @@ -127,6 +127,7 @@ class DartUtils { static const char* kUriLibURL; static const char* kUtfLibURL; static const char* kIsolateLibURL; + static const char* kScalarlistLibURL; static const char* kWebLibURL; static const char* kIdFieldName; diff --git a/runtime/bin/io.dart b/runtime/bin/io.dart index 10b51dc749c..36d02bb268e 100644 --- a/runtime/bin/io.dart +++ b/runtime/bin/io.dart @@ -8,9 +8,10 @@ #library("io"); #import("dart:coreimpl"); +#import("dart:crypto"); #import("dart:isolate"); #import("dart:math"); #import("dart:nativewrappers"); +#import("dart:scalarlist"); #import("dart:uri"); -#import("dart:crypto"); #import("dart:utf"); diff --git a/runtime/lib/byte_array.dart b/runtime/lib/byte_array.dart index f4737c1974c..59b878cfc9c 100644 --- a/runtime/lib/byte_array.dart +++ b/runtime/lib/byte_array.dart @@ -2,789 +2,113 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -/** - * A random-access sequence of bytes that also provides random access to - * the fixed-width integers and floating point numbers represented by - * those bytes. Byte arrays may be used to pack and unpack data from - * external sources (such as networks or files systems), and to process - * large quantities of numerical data more efficiently than would be possible - * with ordinary [List] implementations. Byte arrays can save space, by - * eliminating the need for object headers, and time, by eliminating the - * need for data copies. Finally, Byte arrays may be used to intentionally - * reinterpret the bytes representing one arithmetic type as another. - * For example this code fragment determine what 64-bit signed integer - * is represented by the bytes of a 64-bit floating point number: - * - * var ba = new ByteArray(8); - * ba.setFloat64(0, 3.14159265358979323846); - * int huh = ba.getInt64(0); - */ -interface ByteArray { - /** - * Returns the length of this byte array, in bytes. - */ - int lengthInBytes(); - - /** - * Returns a [ByteArray] _view_ of a portion of this byte array. - * The returned byte array consists of [length] bytes starting - * at position [start] in this byte array. The returned byte array - * is backed by the same data as this byte array. In other words, - * changes to the returned byte array are visible in this byte array - * and vice-versa. - * - * Throws [IndexOutOfRangeException] if [start] is negative, or if - * `start + length` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [length] is negative. - */ - ByteArray subByteArray([int start, int length]); - - /** - * Returns the (possibly negative) integer represented by the byte at the - * specified [byteOffset] in this byte array, in two's complement binary - * representation. The return value will be between -128 and 127, inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * greater than or equal to the length of this byte array. - */ - int getInt8(int byteOffset); - - /** - * Sets the byte at the specified [byteOffset] in this byte array to the - * two's complement binary representation of the specified [value], which - * must fit in a single byte. In other words, [value] must be between - * -128 and 127, inclusive. - * - * Returns `byteOffset + 1`, which is the offset of the first byte in the - * array after the byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * greater than or equal to the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is less than -128 or - * greater than 127. - */ - int setInt8(int byteOffset, int value); - - /** - * Returns the positive integer represented by the byte at the specified - * [byteOffset] in this byte array, in unsigned binary form. The - * return value will be between 0 and 255, inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * greater than or equal to the length of this byte array. - */ - int getUint8(int byteOffset); - - /** - * Sets the byte at the specified [byteOffset] in this byte array to the - * unsigned binary representation of the specified [value], which must fit - * in a single byte. in other words, [value] must be between 0 and 255, - * inclusive. - * - * Returns `byteOffset + 1`, which is the offset of the first byte in the - * array after the byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, - * or greater than or equal to the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is negative or - * greater than 255. - */ - int setUint8(int byteOffset, int value); - - /** - * Returns the (possibly negative) integer represented by the two bytes at - * the specified [byteOffset] in this byte array, in two's complement binary - * form. The return value will be between 215 and 215 - 1, - * inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 2` is greater than the length of this byte array. - */ - int getInt16(int byteOffset); - - /** - * Sets the two bytes starting at the specified [byteOffset] in this - * byte array to the two's complement binary representation of the specified - * [value], which must fit in two bytes. In other words, [value] must lie - * between 215 and 215 - 1, inclusive. - * - * Returns `byteOffset + 2`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 2` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is less than 215 - * or greater than 215 - 1. - */ - int setInt16(int byteOffset, int value); - - /** - * Returns the positive integer represented by the two bytes starting - * at the specified [byteOffset] in this byte array, in unsigned binary - * form. The return value will be between 0 and 216 - 1, inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 2` is greater than the length of this byte array. - */ - int getUint16(int byteOffset); - - /** - * Sets the two bytes starting at the specified [byteOffset] in this byte - * array to the unsigned binary representation of the specified [value], - * which must fit in two bytes. in other words, [value] must be between - * 0 and 216 - 1, inclusive. - * - * Returns `byteOffset + 2`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 2` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is negative or - * greater than 216 - 1. - */ - int setUint16(int byteOffset, int value); - - /** - * Returns the (possibly negative) integer represented by the four bytes at - * the specified [byteOffset] in this byte array, in two's complement binary - * form. The return value will be between 231 and 231 - 1, - * inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 4` is greater than the length of this byte array. - */ - int getInt32(int byteOffset); - - /** - * Sets the four bytes starting at the specified [byteOffset] in this - * byte array to the two's complement binary representation of the specified - * [value], which must fit in four bytes. In other words, [value] must lie - * between 231 and 231 - 1, inclusive. - * - * Returns `byteOffset + 4`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 4` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is less than 231 - * or greater than 231 - 1. - */ - int setInt32(int byteOffset, int value); - - /** - * Returns the positive integer represented by the four bytes starting - * at the specified [byteOffset] in this byte array, in unsigned binary - * form. The return value will be between 0 and 232 - 1, inclusive. - * - */ - int getUint32(int byteOffset); - - /** - * Sets the four bytes starting at the specified [byteOffset] in this byte - * array to the unsigned binary representation of the specified [value], - * which must fit in four bytes. in other words, [value] must be between - * 0 and 232 - 1, inclusive. - * - * Returns `byteOffset + 4`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 4` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is negative or - * greater than 232 - 1. - */ - int setUint32(int byteOffset, int value); - - /** - * Returns the (possibly negative) integer represented by the eight bytes at - * the specified [byteOffset] in this byte array, in two's complement binary - * form. The return value will be between 263 and 263 - 1, - * inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 8` is greater than the length of this byte array. - */ - int getInt64(int byteOffset); - - /** - * Sets the eight bytes starting at the specified [byteOffset] in this - * byte array to the two's complement binary representation of the specified - * [value], which must fit in eight bytes. In other words, [value] must lie - * between 263 and 263 - 1, inclusive. - * - * Returns `byteOffset + 8`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 8` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is less than 263 - * or greater than 263 - 1. - */ - int setInt64(int byteOffset, int value); - - /** - * Returns the positive integer represented by the eight bytes starting - * at the specified [byteOffset] in this byte array, in unsigned binary - * form. The return value will be between 0 and 264 - 1, inclusive. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 8` is greater than the length of this byte array. - */ - int getUint64(int byteOffset); - - /** - * Sets the eight bytes starting at the specified [byteOffset] in this byte - * array to the unsigned binary representation of the specified [value], - * which must fit in eight bytes. in other words, [value] must be between - * 0 and 264 - 1, inclusive. - * - * Returns `byteOffset + 8`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 8` is greater than the length of this byte array. - * - * Throws [IllegalArgumentException] if [value] is negative or - * greater than 264 - 1. - */ - int setUint64(int byteOffset, int value); - - /** - * Returns the floating point number represented by the four bytes at - * the specified [byteOffset] in this byte array, in IEEE 754 - * single-precision binary floating-point format (binary32). - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 4` is greater than the length of this byte array. - */ - double getFloat32(int byteOffset); - - /** - * Sets the four bytes starting at the specified [byteOffset] in this - * byte array to the IEEE 754 single-precision binary floating-point - * (binary32) representation of the specified [value]. - * - * **Note that this method can lose precision.** The input [value] is - * a 64-bit floating point value, which will be converted to 32-bit - * floating point value by IEEE 754 rounding rules before it is stored. - * If [value] cannot be represented exactly as a binary32, it will be - * converted to the nearest binary32 value. If two binary32 values are - * equally close, the one whose least significant bit is zero will be used. - * Note that finite (but large) values can be converted to infinity, and - * small non-zero values can be converted to zero. - * - * Returns `byteOffset + 4`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 4` is greater than the length of this byte array. - */ - int setFloat32(int byteOffset, double value); - - /** - * Returns the floating point number represented by the eight bytes at - * the specified [byteOffset] in this byte array, in IEEE 754 - * double-precision binary floating-point format (binary64). - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 8` is greater than the length of this byte array. - */ - double getFloat64(int byteOffset); - - /** - * Sets the eight bytes starting at the specified [byteOffset] in this - * byte array to the IEEE 754 double-precision binary floating-point - * (binary64) representation of the specified [value]. - * - * Returns `byteOffset + 8`, which is the offset of the first byte in the - * array after the last byte that was set by this call. This return value can - * be passed as the [byteOffset] parameter to a subsequent `setXxx` call. - * - * Throws [IndexOutOfRangeException] if [byteOffset] is negative, or - * `byteOffset + 8` is greater than the length of this byte array. - */ - int setFloat64(int byteOffset, double value); -} - -/** - * A "mixin" interface that allows a type, typically but not necessarily - * a [List], to be viewed as a [ByteArray]. - */ -interface ByteArrayViewable { - /** - * Returns the number of bytes in the representation of each element in - * this list, or the number bytes in the representation of the entire - * object if it is not a list. - */ - int bytesPerElement(); - - /** - * Returns the length of this view, in bytes. - */ - int lengthInBytes(); - - /** - * Returns the byte array view of this object. This view allows the - * byte representation of the object to be read and written directly. - */ - ByteArray asByteArray([int start, int length]); -} - - -/** - * A fixed-length list of 8-bit signed integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Int8List extends List, ByteArrayViewable - default _Int8ArrayFactory { - /** - * Creates an [Int8List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Int8List(int length); - - /** - * Creates an [Int8List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Int8List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - */ - Int8List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 8-bit unsigned integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Uint8List extends List, ByteArrayViewable - default _Uint8ArrayFactory { - /** - * Creates a [Uint8List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Uint8List(int length); - - /** - * Creates a [Uint8List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Uint8List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - */ - Uint8List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 16-bit signed integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Int16List extends List, ByteArrayViewable - default _Int16ArrayFactory { - /** - * Creates an [Int16List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Int16List(int length); - - /** - * Creates an [Int16List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Int16List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 2 (the size of an "int16" in bytes), or if the - * [start] of the region is not divisible by 2. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 2. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "int16s," or if it - * is not "int16-aligned." - */ - Int16List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 16-bit unsigned integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Uint16List extends List, ByteArrayViewable - default _Uint16ArrayFactory { - /** - * Creates a [Uint16List] of the specified length (in elements), all - * of whose elements are initially zero. - */ - Uint16List(int length); - - /** - * Creates a [Uint16List] _view_ of the specified region in - * the specified byte [array]. Changes in the [Uint16List] will be - * visible in the byte array and vice versa. If the [start] index of the - * region is not specified, it defaults to zero (the first byte in the byte - * array). If the length is not specified, it defaults to null, which - * indicates that the view extends to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 2 (the size of a "uint16" in bytes), or if the - * [start] of the region is not divisible by 2. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 2. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "uint16s," or if it - * is not "uint16-aligned." - */ - Uint16List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 32-bit signed integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Int32List extends List, ByteArrayViewable - default _Int32ArrayFactory { - /** - * Creates an [Int32List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Int32List(int length); - - /** - * Creates an [Int32List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Int32List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 4 (the size of an "int32" in bytes), or if the - * [start] of the region is not divisible by 4. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 4. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "int32s," or if it - * is not "int32-aligned." - */ - Int32List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 32-bit unsigned integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Uint32List extends List, ByteArrayViewable - default _Uint32ArrayFactory { - /** - * Creates a [Uint32List] of the specified length (in elements), all - * of whose elements are initially zero. - */ - Uint32List(int length); - - /** - * Creates a [Uint32List] _view_ of the specified region in - * the specified byte [array]. Changes in the [Uint32] will be - * visible in the byte array and vice versa. If the [start] index of the - * region is not specified, it defaults to zero (the first byte in the byte - * array). If the length is not specified, it defaults to null, which - * indicates that the view extends to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 4 (the size of a "uint32" in bytes), or if the - * [start] of the region is not divisible by 4. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 4. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "uint32s," or if it - * is not "uint32-aligned." - */ - Uint32List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 64-bit signed integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Int64List extends List, ByteArrayViewable - default _Int64ArrayFactory { - /** - * Creates an [Int64List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Int64List(int length); - - /** - * Creates an [Int64List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Int64List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 8 (the size of an "int64" in bytes), or if the - * [start] of the region is not divisible by 8. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 8. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "int64s," or if it - * is not "int64-aligned." - */ - Int64List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of 64-bit unsigned integers that is viewable as a - * [ByteArray]. For long lists, this implementation will be considerably - * more space- and time-efficient than the default [List] implementation. - */ -interface Uint64List extends List, ByteArrayViewable - default _Uint64ArrayFactory { - /** - * Creates a [Uint64List] of the specified length (in elements), all - * of whose elements are initially zero. - */ - Uint64List(int length); - - /** - * Creates an [Uint64List] _view_ of the specified region in - * the specified byte [array]. Changes in the [Uint64List] will be - * visible in the byte array and vice versa. If the [start] index of the - * region is not specified, it defaults to zero (the first byte in the byte - * array). If the length is not specified, it defaults to null, which - * indicates that the view extends to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 8 (the size of a "uint64" in bytes), or if the - * [start] of the region is not divisible by 8. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 8. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "uint64s," or if it - * is not "uint64-aligned." - */ - Uint64List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of IEEE 754 single-precision binary floating-point - * numbers that is viewable as a [ByteArray]. For long lists, this - * implementation will be considerably more space- and time-efficient than - * the default [List] implementation. - */ -interface Float32List extends List, ByteArrayViewable - default _Float32ArrayFactory { - /** - * Creates a [Float32List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Float32List(int length); - - /** - * Creates a [Float32List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Float32List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 4 (the size of a "float32" in bytes), or if the - * [start] of the region is not divisible by 4. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 4. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "float32s," or if it - * is not "float32-aligned." - */ - Float32List.view(ByteArray array, [int start, int length]); -} - - -/** - * A fixed-length list of IEEE 754 double-precision binary floating-point - * numbers that is viewable as a [ByteArray]. For long lists, this - * implementation will be considerably more space- and time-efficient than - * the default [List] implementation. - */ -interface Float64List extends List, ByteArrayViewable - default _Float64ArrayFactory { - /** - * Creates a [Float64List] of the specified length (in elements), all of - * whose elements are initially zero. - */ - Float64List(int length); - - /** - * Creates a [Float64List] _view_ of the specified region in the specified - * byte [array]. Changes in the [Float64List] will be visible in the byte - * array and vice versa. If the [start] index of the region is not specified, - * it defaults to zero (the first byte in the byte array). If the length is - * not specified, it defaults to null, which indicates that the view extends - * to the end of the byte array. - * - * Throws [IllegalArgumentException] if the length of the specified region - * is not divisible by 8 (the size of a "float64" in bytes), or if the - * [start] of the region is not divisible by 8. If, however, [array] - * is a view of another byte array, this constructor will throw - * [IllegalArgumentException] if the implicit starting position in the - * "ultimately backing" byte array is not divisible by 8. In plain terms, - * this constructor throws [IllegalArgumentException] if the specified - * region does not contain an integral number of "float64s," or if it - * is not "float64-aligned." - */ - Float64List.view(ByteArray array, [int start, int length]); -} - - -class _Int8ArrayFactory { - factory Int8List(int length) { +patch class Int8List { + /* patch */ factory Int8List(int length) { return new _Int8Array(length); } - factory Int8List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Int8List.view(ByteArray array, + [int start = 0, int length]) { return new _Int8ArrayView(array, start, length); } } -class _Uint8ArrayFactory { - factory Uint8List(int length) { +patch class Uint8List { + /* patch */ factory Uint8List(int length) { return new _Uint8Array(length); } - factory Uint8List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Uint8List.view(ByteArray array, + [int start = 0, int length]) { return new _Uint8ArrayView(array, start, length); } } -class _Int16ArrayFactory { - factory Int16List(int length) { +patch class Int16List { + /* patch */ factory Int16List(int length) { return new _Int16Array(length); } - factory Int16List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Int16List.view(ByteArray array, [int start = 0, int length]) { return new _Int16ArrayView(array, start, length); } } -class _Uint16ArrayFactory { - factory Uint16List(int length) { +patch class Uint16List { + /* patch */ factory Uint16List(int length) { return new _Uint16Array(length); } - factory Uint16List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Uint16List.view(ByteArray array, [int start = 0, int length]) { return new _Uint16ArrayView(array, start, length); } } -class _Int32ArrayFactory { - factory Int32List(int length) { +patch class Int32List { + /* patch */ factory Int32List(int length) { return new _Int32Array(length); } - factory Int32List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Int32List.view(ByteArray array, [int start = 0, int length]) { return new _Int32ArrayView(array, start, length); } } -class _Uint32ArrayFactory { - factory Uint32List(int length) { +patch class Uint32List { + /* patch */ factory Uint32List(int length) { return new _Uint32Array(length); } - factory Uint32List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Uint32List.view(ByteArray array, [int start = 0, int length]) { return new _Uint32ArrayView(array, start, length); } } -class _Int64ArrayFactory { - factory Int64List(int length) { +patch class Int64List { + /* patch */ factory Int64List(int length) { return new _Int64Array(length); } - factory Int64List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Int64List.view(ByteArray array, [int start = 0, int length]) { return new _Int64ArrayView(array, start, length); } } -class _Uint64ArrayFactory { - factory Uint64List(int length) { +patch class Uint64List { + /* patch */ factory Uint64List(int length) { return new _Uint64Array(length); } - factory Uint64List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Uint64List.view(ByteArray array, [int start = 0, int length]) { return new _Uint64ArrayView(array, start, length); } } -class _Float32ArrayFactory { - factory Float32List(int length) { +patch class Float32List { + /* patch */ factory Float32List(int length) { return new _Float32Array(length); } - factory Float32List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Float32List.view(ByteArray array, [int start = 0, int length]) { return new _Float32ArrayView(array, start, length); } } -class _Float64ArrayFactory { - factory Float64List(int length) { +patch class Float64List { + /* patch */ factory Float64List(int length) { return new _Float64Array(length); } - factory Float64List.view(ByteArray array, [int start = 0, int length]) { + /* patch */ factory Float64List.view(ByteArray array, [int start = 0, int length]) { return new _Float64ArrayView(array, start, length); } } diff --git a/runtime/lib/lib_sources.gypi b/runtime/lib/lib_sources.gypi index 33fd3736efc..b0d29a84c19 100644 --- a/runtime/lib/lib_sources.gypi +++ b/runtime/lib/lib_sources.gypi @@ -6,8 +6,6 @@ { 'sources': [ - 'byte_array.cc', - 'byte_array.dart', 'double.cc', 'double.dart', 'double_patch.dart', diff --git a/runtime/lib/scalarlist_sources.gypi b/runtime/lib/scalarlist_sources.gypi new file mode 100644 index 00000000000..cb7c3ddd8f9 --- /dev/null +++ b/runtime/lib/scalarlist_sources.gypi @@ -0,0 +1,13 @@ +# Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +# for details. All rights reserved. Use of this source code is governed by a +# BSD-style license that can be found in the LICENSE file. + +# Sources visible via dart:scalarlist library. + +{ + 'sources': [ + 'byte_array.cc', + 'byte_array.dart', + ], +} + diff --git a/runtime/tests/vm/dart/byte_array_test.dart b/runtime/tests/vm/dart/byte_array_test.dart index 1839370b0c0..6bae6c34643 100644 --- a/runtime/tests/vm/dart/byte_array_test.dart +++ b/runtime/tests/vm/dart/byte_array_test.dart @@ -1,3 +1,9 @@ +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +#import('dart:scalarlist'); + class ByteArrayTest { static testInt8List() { Expect.throws(() { new Int8List(-1); }, diff --git a/runtime/vm/bootstrap.cc b/runtime/vm/bootstrap.cc index 31674a90e02..1e1ddd72c88 100644 --- a/runtime/vm/bootstrap.cc +++ b/runtime/vm/bootstrap.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -63,6 +63,13 @@ RawScript* Bootstrap::LoadMirrorsScript(bool patch) { } +RawScript* Bootstrap::LoadScalarlistScript(bool patch) { + const char* url = patch ? "dart:scalarlist_patch" : "dart:scalarlist"; + const char* source = patch ? scalarlist_patch_ : scalarlist_source_; + return LoadScript(url, source, patch); +} + + RawError* Bootstrap::Compile(const Library& library, const Script& script) { if (FLAG_print_bootstrap) { OS::Print("Bootstrap source '%s':\n%s\n", diff --git a/runtime/vm/bootstrap.h b/runtime/vm/bootstrap.h index 2d4ce50f111..0b7412a9008 100644 --- a/runtime/vm/bootstrap.h +++ b/runtime/vm/bootstrap.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -22,6 +22,7 @@ class Bootstrap : public AllStatic { static RawScript* LoadMathScript(bool patch); static RawScript* LoadIsolateScript(bool patch); static RawScript* LoadMirrorsScript(bool patch); + static RawScript* LoadScalarlistScript(bool patch); static RawError* Compile(const Library& library, const Script& script); static void SetupNativeResolver(); @@ -38,6 +39,8 @@ class Bootstrap : public AllStatic { static const char isolate_patch_[]; static const char mirrors_source_[]; static const char mirrors_patch_[]; + static const char scalarlist_source_[]; + static const char scalarlist_patch_[]; }; } // namespace dart diff --git a/runtime/vm/bootstrap_natives.cc b/runtime/vm/bootstrap_natives.cc index 4fbf62fc151..fa368b697a0 100644 --- a/runtime/vm/bootstrap_natives.cc +++ b/runtime/vm/bootstrap_natives.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -71,6 +71,10 @@ void Bootstrap::SetupNativeResolver() { library = Library::IsolateLibrary(); ASSERT(!library.IsNull()); library.set_native_entry_resolver(resolver); + + library = Library::ScalarlistLibrary(); + ASSERT(!library.IsNull()); + library.set_native_entry_resolver(resolver); } } // namespace dart diff --git a/runtime/vm/bootstrap_nocorelib.cc b/runtime/vm/bootstrap_nocorelib.cc index 582db6197c1..dca7e2e8e9e 100644 --- a/runtime/vm/bootstrap_nocorelib.cc +++ b/runtime/vm/bootstrap_nocorelib.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -45,6 +45,12 @@ RawScript* Bootstrap::LoadMirrorsScript(bool is_patch) { } +RawScript* Bootstrap::LoadScalarlistScript(bool is_patch) { + UNREACHABLE(); + return Script::null(); +} + + RawError* Bootstrap::Compile(const Library& library, const Script& script) { UNREACHABLE(); return Error::null(); diff --git a/runtime/vm/intrinsifier.cc b/runtime/vm/intrinsifier.cc index abeef01f0e2..27e83f7415b 100644 --- a/runtime/vm/intrinsifier.cc +++ b/runtime/vm/intrinsifier.cc @@ -17,10 +17,12 @@ static bool CompareNames(const char* test_name, const char* name) { return true; } if ((name[0] == '_') && (test_name[0] == '_')) { - // Check if the private class is member of corelib and matches the - // test_class_name. + // Check if the private class is member of core, coreimpl or + // scalarlist and matches the test_class_name. const Library& core_lib = Library::Handle(Library::CoreLibrary()); const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); + const Library& scalarlist_lib = + Library::Handle(Library::ScalarlistLibrary()); String& test_str = String::Handle(String::New(test_name)); String& test_str_with_key = String::Handle(); test_str_with_key = @@ -33,6 +35,11 @@ static bool CompareNames(const char* test_name, const char* name) { if (strcmp(test_str_with_key.ToCString(), name) == 0) { return true; } + test_str_with_key = + String::Concat(test_str, String::Handle(scalarlist_lib.private_key())); + if (strcmp(test_str_with_key.ToCString(), name) == 0) { + return true; + } } return false; } @@ -57,13 +64,15 @@ bool Intrinsifier::CanIntrinsify(const Function& function) { const char* function_name = String::Handle(function.name()).ToCString(); const Class& function_class = Class::Handle(function.Owner()); const char* class_name = String::Handle(function_class.Name()).ToCString(); - // Only core and math library methods can be intrinsified. + // Only core, math and scalarlist library methods can be intrinsified. const Library& core_lib = Library::Handle(Library::CoreLibrary()); const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); const Library& math_lib = Library::Handle(Library::MathLibrary()); + const Library& scalarlist_lib = Library::Handle(Library::ScalarlistLibrary()); if ((function_class.library() != core_lib.raw()) && (function_class.library() != core_impl_lib.raw()) && - (function_class.library() != math_lib.raw())) { + (function_class.library() != math_lib.raw()) && + (function_class.library() != scalarlist_lib.raw())) { return false; } #define FIND_INTRINSICS(test_class_name, test_function_name, destination) \ diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index ae36909cd43..faa7773abf8 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -687,111 +687,114 @@ RawError* Object::Init(Isolate* isolate) { RegisterPrivateClass(cls, name, core_lib); pending_classes.Add(cls, Heap::kOld); - cls = Class::New(); - object_store->set_int8_array_class(cls); - name = Symbols::_Int8Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_uint8_array_class(cls); - name = Symbols::_Uint8Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_int16_array_class(cls); - name = Symbols::_Int16Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_uint16_array_class(cls); - name = Symbols::_Uint16Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_int32_array_class(cls); - name = Symbols::_Int32Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_uint32_array_class(cls); - name = Symbols::_Uint32Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_int64_array_class(cls); - name = Symbols::_Int64Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_uint64_array_class(cls); - name = Symbols::_Uint64Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_float32_array_class(cls); - name = Symbols::_Float32Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_float64_array_class(cls); - name = Symbols::_Float64Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_int8_array_class(cls); - name = Symbols::_ExternalInt8Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_uint8_array_class(cls); - name = Symbols::_ExternalUint8Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_int16_array_class(cls); - name = Symbols::_ExternalInt16Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_uint16_array_class(cls); - name = Symbols::_ExternalUint16Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_int32_array_class(cls); - name = Symbols::_ExternalInt32Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_uint32_array_class(cls); - name = Symbols::_ExternalUint32Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_int64_array_class(cls); - name = Symbols::_ExternalInt64Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_uint64_array_class(cls); - name = Symbols::_ExternalUint64Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_float32_array_class(cls); - name = Symbols::_ExternalFloat32Array(); - RegisterPrivateClass(cls, name, core_lib); - - cls = Class::New(); - object_store->set_external_float64_array_class(cls); - name = Symbols::_ExternalFloat64Array(); - RegisterPrivateClass(cls, name, core_lib); - cls = Class::New(); object_store->set_weak_property_class(cls); name = Symbols::_WeakProperty(); RegisterPrivateClass(cls, name, core_lib); + Library::InitScalarlistLibrary(isolate); + Library& scalarlist_lib = Library::Handle(Library::ScalarlistLibrary()); + + cls = Class::New(); + object_store->set_int8_array_class(cls); + name = Symbols::_Int8Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_uint8_array_class(cls); + name = Symbols::_Uint8Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_int16_array_class(cls); + name = Symbols::_Int16Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_uint16_array_class(cls); + name = Symbols::_Uint16Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_int32_array_class(cls); + name = Symbols::_Int32Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_uint32_array_class(cls); + name = Symbols::_Uint32Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_int64_array_class(cls); + name = Symbols::_Int64Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_uint64_array_class(cls); + name = Symbols::_Uint64Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_float32_array_class(cls); + name = Symbols::_Float32Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_float64_array_class(cls); + name = Symbols::_Float64Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_int8_array_class(cls); + name = Symbols::_ExternalInt8Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_uint8_array_class(cls); + name = Symbols::_ExternalUint8Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_int16_array_class(cls); + name = Symbols::_ExternalInt16Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_uint16_array_class(cls); + name = Symbols::_ExternalUint16Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_int32_array_class(cls); + name = Symbols::_ExternalInt32Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_uint32_array_class(cls); + name = Symbols::_ExternalUint32Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_int64_array_class(cls); + name = Symbols::_ExternalInt64Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_uint64_array_class(cls); + name = Symbols::_ExternalUint64Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_float32_array_class(cls); + name = Symbols::_ExternalFloat32Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + + cls = Class::New(); + object_store->set_external_float64_array_class(cls); + name = Symbols::_ExternalFloat64Array(); + RegisterPrivateClass(cls, name, scalarlist_lib); + // Set the super type of class Stacktrace to Object type so that the // 'toString' method is implemented. cls = object_store->stacktrace_class(); @@ -947,6 +950,18 @@ RawError* Object::Init(Isolate* isolate) { if (!error.IsNull()) { return error.raw(); } + const Script& scalarlist_script = Script::Handle( + Bootstrap::LoadScalarlistScript(false)); + ASSERT(!scalarlist_lib.IsNull()); + error = Bootstrap::Compile(scalarlist_lib, scalarlist_script); + if (!error.IsNull()) { + return error.raw(); + } + patch_script = Bootstrap::LoadScalarlistScript(true); + error = scalarlist_lib.Patch(patch_script); + if (!error.IsNull()) { + return error.raw(); + } Bootstrap::SetupNativeResolver(); // Remove the Object superclass cycle by setting the super type to null (not @@ -6606,6 +6621,16 @@ void Library::InitMirrorsLibrary(Isolate* isolate) { } +void Library::InitScalarlistLibrary(Isolate* isolate) { + const String& url = String::Handle(Symbols::New("dart:scalarlist")); + const Library& lib = Library::Handle(Library::New(url)); + lib.Register(); + const Library& core_impl_lib = Library::Handle(Library::CoreImplLibrary()); + lib.AddImport(core_impl_lib); + isolate->object_store()->set_scalarlist_library(lib); +} + + void Library::InitNativeWrappersLibrary(Isolate* isolate) { static const int kNumNativeWrappersClasses = 4; ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); @@ -6734,6 +6759,11 @@ RawLibrary* Library::MirrorsLibrary() { } +RawLibrary* Library::ScalarlistLibrary() { + return Isolate::Current()->object_store()->scalarlist_library(); +} + + RawLibrary* Library::NativeWrappersLibrary() { return Isolate::Current()->object_store()->native_wrappers_library(); } diff --git a/runtime/vm/object.h b/runtime/vm/object.h index 074b99a61e6..358404a992d 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -2146,12 +2146,15 @@ class Library : public Object { static void InitMathLibrary(Isolate* isolate); static void InitIsolateLibrary(Isolate* isolate); static void InitMirrorsLibrary(Isolate* isolate); + static void InitScalarlistLibrary(Isolate* isolate); + static void InitNativeWrappersLibrary(Isolate* isolate); + static RawLibrary* CoreLibrary(); static RawLibrary* CoreImplLibrary(); static RawLibrary* MathLibrary(); static RawLibrary* IsolateLibrary(); static RawLibrary* MirrorsLibrary(); - static void InitNativeWrappersLibrary(Isolate* isolate); + static RawLibrary* ScalarlistLibrary(); static RawLibrary* NativeWrappersLibrary(); // Eagerly compile all classes and functions in the library. diff --git a/runtime/vm/object_store.cc b/runtime/vm/object_store.cc index 086d93440e7..15b22d037ac 100644 --- a/runtime/vm/object_store.cc +++ b/runtime/vm/object_store.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -68,6 +68,7 @@ ObjectStore::ObjectStore() math_library_(Library::null()), isolate_library_(Library::null()), mirrors_library_(Library::null()), + scalarlist_library_(Library::null()), native_wrappers_library_(Library::null()), builtin_library_(Library::null()), root_library_(Library::null()), diff --git a/runtime/vm/object_store.h b/runtime/vm/object_store.h index 1442ff16085..97666b2f27e 100644 --- a/runtime/vm/object_store.h +++ b/runtime/vm/object_store.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -385,6 +385,13 @@ class ObjectStore { mirrors_library_ = value.raw(); } + RawLibrary* scalarlist_library() const { + return scalarlist_library_; + } + void set_scalarlist_library(const Library& value) { + scalarlist_library_ = value.raw(); + } + RawLibrary* builtin_library() const { return builtin_library_; } @@ -518,6 +525,7 @@ class ObjectStore { RawLibrary* math_library_; RawLibrary* isolate_library_; RawLibrary* mirrors_library_; + RawLibrary* scalarlist_library_; RawLibrary* native_wrappers_library_; RawLibrary* builtin_library_; RawLibrary* root_library_; diff --git a/runtime/vm/snapshot_test.cc b/runtime/vm/snapshot_test.cc index 548912bab05..e7e8fc1903f 100644 --- a/runtime/vm/snapshot_test.cc +++ b/runtime/vm/snapshot_test.cc @@ -1430,6 +1430,7 @@ UNIT_TEST_CASE(DartGeneratedArrayLiteralMessages) { UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { const int kArrayLength = 10; static const char* kScriptChars = + "#import('dart:scalarlist');\n" "final int kArrayLength = 10;\n" "getStringList() {\n" " var s = 'Hello, world!';\n" @@ -1600,6 +1601,7 @@ UNIT_TEST_CASE(DartGeneratedListMessagesWithBackref) { UNIT_TEST_CASE(DartGeneratedArrayLiteralMessagesWithBackref) { const int kArrayLength = 10; static const char* kScriptChars = + "#import('dart:scalarlist');\n" "final int kArrayLength = 10;\n" "getStringList() {\n" " var s = 'Hello, world!';\n" diff --git a/runtime/vm/vm.gypi b/runtime/vm/vm.gypi index 7ae96f157be..8b8776e0862 100644 --- a/runtime/vm/vm.gypi +++ b/runtime/vm/vm.gypi @@ -15,6 +15,8 @@ 'mirrors_patch_cc_file': '<(SHARED_INTERMEDIATE_DIR)/mirrors_patch_gen.cc', 'isolate_cc_file': '<(SHARED_INTERMEDIATE_DIR)/isolate_gen.cc', 'isolate_patch_cc_file': '<(SHARED_INTERMEDIATE_DIR)/isolate_patch_gen.cc', + 'scalarlist_cc_file': '<(SHARED_INTERMEDIATE_DIR)/scalarlist_gen.cc', + 'scalarlist_patch_cc_file': '<(SHARED_INTERMEDIATE_DIR)/scalarlist_patch_gen.cc', 'snapshot_test_dat_file': '<(SHARED_INTERMEDIATE_DIR)/snapshot_test.dat', 'snapshot_test_in_dat_file': 'snapshot_test_in.dat', 'snapshot_test_dart_file': 'snapshot_test.dart', @@ -72,12 +74,15 @@ 'generate_isolate_patch_cc_file', 'generate_mirrors_cc_file', 'generate_mirrors_patch_cc_file', + 'generate_scalarlist_cc_file', + 'generate_scalarlist_patch_cc_file', ], 'includes': [ '../lib/lib_sources.gypi', '../lib/lib_impl_sources.gypi', '../lib/isolate_sources.gypi', '../lib/mirrors_sources.gypi', + '../lib/scalarlist_sources.gypi', ], 'sources': [ 'bootstrap.cc', @@ -92,6 +97,8 @@ '<(isolate_patch_cc_file)', '<(mirrors_cc_file)', '<(mirrors_patch_cc_file)', + '<(scalarlist_cc_file)', + '<(scalarlist_patch_cc_file)', ], 'include_dirs': [ '..', @@ -105,6 +112,7 @@ '../lib/lib_impl_sources.gypi', '../lib/isolate_sources.gypi', '../lib/mirrors_sources.gypi', + '../lib/scalarlist_sources.gypi', ], 'sources': [ 'bootstrap_nocorelib.cc', @@ -493,6 +501,82 @@ }, ] }, + { + 'target_name': 'generate_scalarlist_cc_file', + 'type': 'none', + 'includes': [ + # Load the shared library sources. + '../../lib/scalarlist/scalarlist_sources.gypi', + ], + 'sources/': [ + # Exclude all .[cc|h] files. + # This is only here for reference. Excludes happen after + # variable expansion, so the script has to do its own + # exclude processing of the sources being passed. + ['exclude', '\\.cc|h$'], + ], + 'actions': [ + { + 'action_name': 'generate_scalarlist_cc', + 'inputs': [ + '../tools/create_string_literal.py', + '<(builtin_in_cc_file)', + '<@(_sources)', + ], + 'outputs': [ + '<(scalarlist_cc_file)', + ], + 'action': [ + 'python', + 'tools/create_string_literal.py', + '--output', '<(scalarlist_cc_file)', + '--input_cc', '<(builtin_in_cc_file)', + '--include', 'vm/bootstrap.h', + '--var_name', 'dart::Bootstrap::scalarlist_source_', + '<@(_sources)', + ], + 'message': 'Generating ''<(scalarlist_cc_file)'' file.' + }, + ] + }, + { + 'target_name': 'generate_scalarlist_patch_cc_file', + 'type': 'none', + 'includes': [ + # Load the runtime implementation sources. + '../lib/scalarlist_sources.gypi', + ], + 'sources/': [ + # Exclude all .[cc|h] files. + # This is only here for reference. Excludes happen after + # variable expansion, so the script has to do its own + # exclude processing of the sources being passed. + ['exclude', '\\.cc|h$'], + ], + 'actions': [ + { + 'action_name': 'generate_scalarlist_patch_cc', + 'inputs': [ + '../tools/create_string_literal.py', + '<(builtin_in_cc_file)', + '<@(_sources)', + ], + 'outputs': [ + '<(scalarlist_patch_cc_file)', + ], + 'action': [ + 'python', + 'tools/create_string_literal.py', + '--output', '<(scalarlist_patch_cc_file)', + '--input_cc', '<(builtin_in_cc_file)', + '--include', 'vm/bootstrap.h', + '--var_name', 'dart::Bootstrap::scalarlist_patch_', + '<@(_sources)', + ], + 'message': 'Generating ''<(scalarlist_patch_cc_file)'' file.' + }, + ] + }, { 'target_name': 'generate_snapshot_test_dat_file', 'type': 'none', diff --git a/tests/standalone/byte_array_test.dart b/tests/standalone/byte_array_test.dart index 2ca9c7eef6e..0a98a958f63 100644 --- a/tests/standalone/byte_array_test.dart +++ b/tests/standalone/byte_array_test.dart @@ -1,9 +1,11 @@ -// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. // // Dart test program for testing native byte arrays. +#import('dart:scalarlist'); + void testCreateByteArray() { Uint8List byteArray; diff --git a/tests/standalone/io/http_parser_test.dart b/tests/standalone/io/http_parser_test.dart index 19dce9901cf..a73bf40d0b9 100644 --- a/tests/standalone/io/http_parser_test.dart +++ b/tests/standalone/io/http_parser_test.dart @@ -3,6 +3,7 @@ // BSD-style license that can be found in the LICENSE file. #import('dart:math'); +#import('dart:scalarlist'); #source("../../../runtime/bin/http_parser.dart"); diff --git a/tests/standalone/io/web_socket_test.dart b/tests/standalone/io/web_socket_test.dart index 7cde41e390f..31d61641c62 100644 --- a/tests/standalone/io/web_socket_test.dart +++ b/tests/standalone/io/web_socket_test.dart @@ -4,6 +4,7 @@ // #import("dart:io"); +#import("dart:scalarlist"); void testRequestResponseClientCloses( int totalConnections, int closeStatus, String closeReason) { diff --git a/tools/create_sdk.py b/tools/create_sdk.py index 3b14658f819..0b89851afdf 100755 --- a/tools/create_sdk.py +++ b/tools/create_sdk.py @@ -34,6 +34,7 @@ # ......mirrors/ # ......uri/ # ......utf/ +# ......scalarlist/ # ....pkg/ # ......args/ # ......compiler/ @@ -226,7 +227,8 @@ def Main(argv): # for library in ['_internal', 'html', 'core', 'coreimpl', - 'crypto', 'isolate', 'json', 'math', 'mirrors', 'uri', 'utf']: + 'crypto', 'isolate', 'json', 'math', 'mirrors', + 'scalarlist', 'uri', 'utf']: copytree(join(HOME, 'lib', library), join(LIB, library), ignore=ignore_patterns('*.svn', 'doc', '*.py', '*.gypi', '*.sh'))