mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Don't delete the OS declaration of `exit` because the concurrency shims aren't always imported, and so the shim declaration might not always be available. Don't override the OS declaration of `exit` in the concurrency shims since we can't just delete the OS one. Instead, set up internal shims just for building Concurrency that forward declares `exit`.
40 lines
774 B
Swift
40 lines
774 B
Swift
#if canImport(Darwin)
|
|
import Darwin
|
|
#elseif canImport(SwiftWASILibc)
|
|
import SwiftWASILibc
|
|
#elseif canImport(ucrt)
|
|
import ucrt
|
|
#elseif canImport(SwiftGlibc)
|
|
import SwiftGlibc
|
|
#endif
|
|
|
|
func square(_ x: Int) -> Int {
|
|
return x * x
|
|
}
|
|
|
|
func euclid2(_ a: Int, _ b: Int) -> Int {
|
|
return square(a) + square(b)
|
|
}
|
|
|
|
@main
|
|
struct Inlining {
|
|
static func main() {
|
|
if CommandLine.argc != 3 {
|
|
print("usage: Inlining <a> <b>")
|
|
exit(1)
|
|
}
|
|
|
|
guard let a = Int(CommandLine.arguments[1]) else {
|
|
print("Argument <a> must be a number")
|
|
exit(1)
|
|
}
|
|
guard let b = Int(CommandLine.arguments[2]) else {
|
|
print("Argument <b> must be a number")
|
|
exit(1)
|
|
}
|
|
let result = euclid2(a, b)
|
|
|
|
print("\(a) * \(a) + \(b) * \(b) = \(result)")
|
|
}
|
|
}
|