Skip to content

Commit 923f0ef

Browse files
committed
stdlib: add WASI.swift.gyb for WASILibc
1 parent e5f4cb1 commit 923f0ef

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

stdlib/public/Platform/WASI.swift.gyb

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
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+
// wasi-libc's error.h uses a macro that Swift can't import.
68+
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINTR'.")
69+
public let EINTR: Int32 = 27
70+
@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINVAL'.")
71+
public let EINVAL: Int32 = 28

0 commit comments

Comments
 (0)