Files
swift-mirror/stdlib/core/Misc.swift
Dmitri Hrybenko 2cc8fe40d4 stdlib/printing: replace four printing systems with one new one
The old ones were:

- print/println
- printAny
- printf
- Console

The new printing story is just print/println.  Every object can be printed.
You can customize the way it is printed by adopting Printable protocol.  Full
details in comments inside stdlib/core/OutputStream.swift.

Printing is not completely finished yet.  We still have ReplPrintable, which
should be removed, string interpolation still uses String constructors, and
printing objects that don't conform to Printable will result in printing
mangled names.


Swift SVN r18001
2014-05-13 13:07:59 +00:00

90 lines
3.1 KiB
Swift

//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2015 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
// Extern C functions
//===----------------------------------------------------------------------===//
// FIXME: Once we have an FFI interface, make these have proper function bodies
// The C "abort" function
@asmname("abort") func _abort()
@asmname("putchar")
func c_putchar(value: Int32)
@asmname("print_int")
func c_print_int(p: Builtin.RawPointer, buf_len: Int, x: Int64, Radix: Int,
uppercase: Bool) -> UInt64
@asmname("print_uint")
func c_print_uint(p: Builtin.RawPointer, buf_len: Int, x: UInt64, Radix: Int,
uppercase: Bool) -> UInt64
@asmname("swift_replOutputIsUTF8") func _isUTF8() -> Bool
// Some file stuff
@asmname("write")
func posix_write(fd: Int32, buf: Builtin.RawPointer, sz: Int) -> Int
@asmname("read")
func posix_read(fd: Int32, buf: Builtin.RawPointer, sz: Int) -> Int
@asmname("llvm.ctlz.i64")
func __llvm_ctlz(value: Builtin.Int64, isZeroUndef: Builtin.Int1) -> Builtin.Int64
@transparent func countLeadingZeros(value: Int64) -> Int64 {
return Int64(__llvm_ctlz(value.value, false.value))
}
@transparent func _autorelease(x: AnyObject) {
Builtin.retain(x)
Builtin.autorelease(x)
}
/// Check if a given object (of value or reference type) conforms to the given
/// protocol.
///
/// Limitation: `DestType` should be a protocol defined in the `Swift` module.
@asmname("swift_stdlib_conformsToProtocol")
func _stdlib_conformsToProtocol<SourceType, DestType>(
value: SourceType, _: DestType.Type
) -> Bool
/// Cast the given object (of value or reference type) to the given protocol
/// type. Traps if the object does not conform to the protocol.
///
/// Limitation: `DestType` should be a protocol defined in the `Swift` module.
@asmname("swift_stdlib_dynamicCastToExistential1Unconditional")
func _stdlib_dynamicCastToExistential1Unconditional<SourceType, DestType>(
value: SourceType, _: DestType.Type
) -> DestType
/// Cast the given object (of value or reference type) to the given protocol
/// type. Returns `.None` if the object does not conform to the protocol.
///
/// Limitation: `DestType` should be a protocol defined in the `Swift` module.
@asmname("swift_stdlib_dynamicCastToExistential1")
func _stdlib_dynamicCastToExistential1<SourceType, DestType>(
value: SourceType, _: DestType.Type
) -> DestType?
@asmname("swift_stdlib_getTypeName")
func _stdlib_getTypeNameImpl<T>(value: T, result: UnsafePointer<String>)
/// Returns the mangled type name for the given value.
func _stdlib_getTypeName<T>(value: T) -> String {
var resultPtr = UnsafePointer<String>.alloc(1)
_stdlib_getTypeNameImpl(value, resultPtr)
let result = resultPtr.get()
resultPtr.dealloc(1)
return result
}