|
| 1 | +//===----------------------------------------------------------------------===// |
| 2 | +// |
| 3 | +// This source file is part of the Swift.org open source project |
| 4 | +// |
| 5 | +// Copyright (c) 2020 Apple Inc. and the Swift project authors |
| 6 | +// Licensed under Apache License v2.0 with Runtime Library Exception |
| 7 | +// |
| 8 | +// See https://swift.org/LICENSE.txt for license information |
| 9 | +// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors |
| 10 | +// |
| 11 | +//===----------------------------------------------------------------------===// |
| 12 | + |
| 13 | +@_exported import SwiftWASILibc // Clang module |
| 14 | + |
| 15 | +// Constants defined by <math.h> |
| 16 | +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi' or '.pi' to get the value of correct type and avoid casting.") |
| 17 | +public let M_PI = Double.pi |
| 18 | + |
| 19 | +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 2' or '.pi / 2' to get the value of correct type and avoid casting.") |
| 20 | +public let M_PI_2 = Double.pi / 2 |
| 21 | + |
| 22 | +@available(swift, deprecated: 3.0, message: "Please use 'Double.pi / 4' or '.pi / 4' to get the value of correct type and avoid casting.") |
| 23 | +public let M_PI_4 = Double.pi / 4 |
| 24 | + |
| 25 | +@available(swift, deprecated: 3.0, message: "Please use '2.squareRoot()'.") |
| 26 | +public let M_SQRT2 = 2.squareRoot() |
| 27 | + |
| 28 | +@available(swift, deprecated: 3.0, message: "Please use '0.5.squareRoot()'.") |
| 29 | +public let M_SQRT1_2 = 0.5.squareRoot() |
| 30 | + |
| 31 | +// Constants defined by <float.h> |
| 32 | +@available(swift, deprecated: 3.0, message: "Please use 'T.radix' to get the radix of a FloatingPoint type 'T'.") |
| 33 | +public let FLT_RADIX = Double.radix |
| 34 | + |
| 35 | +%for type, prefix in [('Float', 'FLT'), ('Double', 'DBL')]: |
| 36 | +// Where does the 1 come from? C counts the usually-implicit leading |
| 37 | +// significand bit, but Swift does not. Neither is really right or wrong. |
| 38 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.significandBitCount + 1'.") |
| 39 | +public let ${prefix}_MANT_DIG = ${type}.significandBitCount + 1 |
| 40 | + |
| 41 | +// Where does the 1 come from? C models floating-point numbers as having a |
| 42 | +// significand in [0.5, 1), but Swift (following IEEE 754) considers the |
| 43 | +// significand to be in [1, 2). This rationale applies to ${prefix}_MIN_EXP |
| 44 | +// as well. |
| 45 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude.exponent + 1'.") |
| 46 | +public let ${prefix}_MAX_EXP = ${type}.greatestFiniteMagnitude.exponent + 1 |
| 47 | + |
| 48 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude.exponent + 1'.") |
| 49 | +public let ${prefix}_MIN_EXP = ${type}.leastNormalMagnitude.exponent + 1 |
| 50 | + |
| 51 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.greatestFiniteMagnitude' or '.greatestFiniteMagnitude'.") |
| 52 | +public let ${prefix}_MAX = ${type}.greatestFiniteMagnitude |
| 53 | + |
| 54 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.ulpOfOne' or '.ulpOfOne'.") |
| 55 | +public let ${prefix}_EPSILON = ${type}.ulpOfOne |
| 56 | + |
| 57 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNormalMagnitude' or '.leastNormalMagnitude'.") |
| 58 | +public let ${prefix}_MIN = ${type}.leastNormalMagnitude |
| 59 | + |
| 60 | +@available(swift, deprecated: 3.0, message: "Please use '${type}.leastNonzeroMagnitude' or '.leastNonzeroMagnitude'.") |
| 61 | +public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude |
| 62 | + |
| 63 | +%end |
| 64 | + |
| 65 | +public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1) |
| 66 | + |
| 67 | +// NOTE: wasi-libc's error.h defines these macros as function-like macros, which ClangImporter can't import for now. |
| 68 | +%{ |
| 69 | +posix_error_codes = [ |
| 70 | + "E2BIG", |
| 71 | + "EACCES", |
| 72 | + "EADDRINUSE", |
| 73 | + "EADDRNOTAVAIL", |
| 74 | + "EAFNOSUPPORT", |
| 75 | + "EAGAIN", |
| 76 | + "EALREADY", |
| 77 | + "EBADF", |
| 78 | + "EBADMSG", |
| 79 | + "EBUSY", |
| 80 | + "ECANCELED", |
| 81 | + "ECHILD", |
| 82 | + "ECONNABORTED", |
| 83 | + "ECONNREFUSED", |
| 84 | + "ECONNRESET", |
| 85 | + "EDEADLK", |
| 86 | + "EDESTADDRREQ", |
| 87 | + "EDOM", |
| 88 | + "EDQUOT", |
| 89 | + "EEXIST", |
| 90 | + "EFAULT", |
| 91 | + "EFBIG", |
| 92 | + "EHOSTUNREACH", |
| 93 | + "EIDRM", |
| 94 | + "EILSEQ", |
| 95 | + "EINPROGRESS", |
| 96 | + "EINTR", |
| 97 | + "EINVAL", |
| 98 | + "EIO", |
| 99 | + "EISCONN", |
| 100 | + "EISDIR", |
| 101 | + "ELOOP", |
| 102 | + "EMFILE", |
| 103 | + "EMLINK", |
| 104 | + "EMSGSIZE", |
| 105 | + "EMULTIHOP", |
| 106 | + "ENAMETOOLONG", |
| 107 | + "ENETDOWN", |
| 108 | + "ENETRESET", |
| 109 | + "ENETUNREACH", |
| 110 | + "ENFILE", |
| 111 | + "ENOBUFS", |
| 112 | + "ENODEV", |
| 113 | + "ENOENT", |
| 114 | + "ENOEXEC", |
| 115 | + "ENOLCK", |
| 116 | + "ENOLINK", |
| 117 | + "ENOMEM", |
| 118 | + "ENOMSG", |
| 119 | + "ENOPROTOOPT", |
| 120 | + "ENOSPC", |
| 121 | + "ENOSYS", |
| 122 | + "ENOTCONN", |
| 123 | + "ENOTDIR", |
| 124 | + "ENOTEMPTY", |
| 125 | + "ENOTRECOVERABLE", |
| 126 | + "ENOTSOCK", |
| 127 | + "ENOTSUP", |
| 128 | + "ENOTTY", |
| 129 | + "ENXIO", |
| 130 | + "EOVERFLOW", |
| 131 | + "EOWNERDEAD", |
| 132 | + "EPERM", |
| 133 | + "EPIPE", |
| 134 | + "EPROTO", |
| 135 | + "EPROTONOSUPPORT", |
| 136 | + "EPROTOTYPE", |
| 137 | + "ERANGE", |
| 138 | + "EROFS", |
| 139 | + "ESPIPE", |
| 140 | + "ESRCH", |
| 141 | + "ESTALE", |
| 142 | + "ETIMEDOUT", |
| 143 | + "ETXTBSY", |
| 144 | + "EXDEV", |
| 145 | + "ENOTCAPABLE", |
| 146 | +] |
| 147 | +}% |
| 148 | + |
| 149 | +%for ecode in posix_error_codes: |
| 150 | + |
| 151 | +public let ${ecode} = POSIXErrorCode.${ecode}.rawValue |
| 152 | + |
| 153 | +%end |
| 154 | + |
| 155 | +// NOTE: wasi-libc's _seek.h defines these macros as function-like macros, which ClangImporter can't import for now. |
| 156 | + |
| 157 | +public let SEEK_SET: Int32 = 0 |
| 158 | +public let SEEK_CUR: Int32 = 1 |
| 159 | +public let SEEK_END: Int32 = 2 |
0 commit comments