Skip to content

Commit

Permalink
Merge pull request #813 from swiftwasm/master
Browse files Browse the repository at this point in the history
[pull] swiftwasm from master
  • Loading branch information
pull[bot] authored Apr 26, 2020
2 parents 1c63a78 + d7b5de9 commit 3790bd3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
25 changes: 21 additions & 4 deletions docs/Literals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,30 @@ The ExpressibleByStringLiteral Protocol
Here is the ExpressibleByStringLiteral protocol as defined in the standard
library's CompilerProtocols.swift::

// NOTE: the compiler has builtin knowledge of this protocol
// Conforming types can be initialized with arbitrary string literals.
/// A type that can be initialized with a string literal.
///
/// The `String` and `StaticString` types conform to the
/// `ExpressibleByStringLiteral` protocol. You can initialize a variable or
/// constant of either of these types using a string literal of any length.
///
/// let picnicGuest = "Deserving porcupine"
///
/// Conforming to ExpressibleByStringLiteral
/// ========================================
///
/// To add `ExpressibleByStringLiteral` conformance to your custom type,
/// implement the required initializer.
public protocol ExpressibleByStringLiteral
: ExpressibleByExtendedGraphemeClusterLiteral {

typealias StringLiteralType : _ExpressibleByBuiltinStringLiteral
// Create an instance initialized to `value`.
/// A type that represents a string literal.
///
/// Valid types for `StringLiteralType` are `String` and `StaticString`.
associatedtype StringLiteralType: _ExpressibleByBuiltinStringLiteral

/// Creates an instance initialized to the given string value.
///
/// - Parameter value: The value of the new instance.
init(stringLiteral value: StringLiteralType)
}

Expand Down
12 changes: 6 additions & 6 deletions stdlib/public/core/UnsafePointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@
/// `load(fromByteOffset:as:)` method to read values.
///
/// let rawPointer = UnsafeRawPointer(uint64Pointer)
/// fullInteger = rawPointer.load(as: UInt64.self) // OK
/// firstByte = rawPointer.load(as: UInt8.self) // OK
/// let fullInteger = rawPointer.load(as: UInt64.self) // OK
/// let firstByte = rawPointer.load(as: UInt8.self) // OK
///
/// Performing Typed Pointer Arithmetic
/// ===================================
Expand Down Expand Up @@ -260,7 +260,7 @@ public struct UnsafePointer<Pointee>: _Pointer {
/// pointer to `Int64`, then accesses a property on the signed integer.
///
/// let uint64Pointer: UnsafePointer<UInt64> = fetchValue()
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self) { ptr in
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self, capacity: 1) { ptr in
/// return ptr.pointee < 0
/// }
///
Expand Down Expand Up @@ -430,8 +430,8 @@ public struct UnsafePointer<Pointee>: _Pointer {
/// to read and write values.
///
/// let rawPointer = UnsafeMutableRawPointer(uint64Pointer)
/// fullInteger = rawPointer.load(as: UInt64.self) // OK
/// firstByte = rawPointer.load(as: UInt8.self) // OK
/// let fullInteger = rawPointer.load(as: UInt64.self) // OK
/// let firstByte = rawPointer.load(as: UInt8.self) // OK
///
/// Performing Typed Pointer Arithmetic
/// ===================================
Expand Down Expand Up @@ -911,7 +911,7 @@ public struct UnsafeMutablePointer<Pointee>: _Pointer {
/// pointer to `Int64`, then accesses a property on the signed integer.
///
/// let uint64Pointer: UnsafeMutablePointer<UInt64> = fetchValue()
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self) { ptr in
/// let isNegative = uint64Pointer.withMemoryRebound(to: Int64.self, capacity: 1) { ptr in
/// return ptr.pointee < 0
/// }
///
Expand Down
18 changes: 9 additions & 9 deletions stdlib/public/core/UnsafeRawPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ public struct UnsafeRawPointer: _Pointer {
///
/// let count = 4
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
/// bytes: 100,
/// alignedTo: MemoryLayout<Int8>.alignment)
/// byteCount: 100,
/// alignment: MemoryLayout<Int8>.alignment)
/// let int8Pointer = bytesPointer.bindMemory(to: Int8.self, capacity: count)
///
/// After calling `bindMemory(to:capacity:)`, the first four bytes of the
Expand Down Expand Up @@ -653,8 +653,8 @@ public struct UnsafeMutableRawPointer: _Pointer {
///
/// let count = 4
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
/// bytes: 100,
/// alignedTo: MemoryLayout<Int8>.alignment)
/// byteCount: 100,
/// alignment: MemoryLayout<Int8>.alignment)
/// let int8Pointer = bytesPointer.bindMemory(to: Int8.self, capacity: count)
///
/// After calling `bindMemory(to:capacity:)`, the first four bytes of the
Expand Down Expand Up @@ -716,7 +716,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
/// byteCount: count * MemoryLayout<Int8>.stride,
/// alignment: MemoryLayout<Int8>.alignment)
/// let int8Pointer = myBytes.initializeMemory(
/// let int8Pointer = bytesPointer.initializeMemory(
/// as: Int8.self, repeating: 0, count: count)
///
/// // After using 'int8Pointer':
Expand Down Expand Up @@ -764,8 +764,8 @@ public struct UnsafeMutableRawPointer: _Pointer {
///
/// let count = 4
/// let bytesPointer = UnsafeMutableRawPointer.allocate(
/// bytes: count * MemoryLayout<Int8>.stride,
/// alignedTo: MemoryLayout<Int8>.alignment)
/// byteCount: count * MemoryLayout<Int8>.stride,
/// alignment: MemoryLayout<Int8>.alignment)
/// let values: [Int8] = [1, 2, 3, 4]
/// let int8Pointer = values.withUnsafeBufferPointer { buffer in
/// return bytesPointer.initializeMemory(as: Int8.self,
Expand All @@ -776,7 +776,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
/// // (int8Pointer + 3).pointee == 4
///
/// // After using 'int8Pointer':
/// int8Pointer.deallocate(count)
/// int8Pointer.deallocate()
///
/// After calling this method on a raw pointer `p`, the region starting at
/// `p` and continuing up to `p + count * MemoryLayout<T>.stride` is bound
Expand Down Expand Up @@ -933,7 +933,7 @@ public struct UnsafeMutableRawPointer: _Pointer {
///
/// let typedPointer = p.bindMemory(to: U.self, capacity: 1)
/// typedPointer.deinitialize(count: 1)
/// p.initializeMemory(as: T.self, to: newValue)
/// p.initializeMemory(as: T.self, repeating: newValue, count: 1)
///
/// - Parameters:
/// - value: The value to store as raw bytes.
Expand Down

0 comments on commit 3790bd3

Please sign in to comment.