Obscene rant about linters.

This commit is contained in:
Steve (Numerics) Canon
2019-04-03 15:15:28 -04:00
parent 45a76fe9f4
commit bcc7e2c901
2 changed files with 67 additions and 54 deletions

View File

@@ -12,6 +12,7 @@
import SwiftShims
%from SwiftMathFunctions import *
%from SwiftFloatingPointTypes import all_floating_point_types
/// A type that has elementary functions available.
///

View File

@@ -1,36 +1,45 @@
from SwiftFloatingPointTypes import all_floating_point_types
class SwiftMathFunction(object):
def __init__(self, name, kind=None, swiftName=None, args="x", comment=None, platforms=None):
def __init__(self, name, kind=None, swiftName=None, args="x", comment=None,
platforms=None):
self.name = name
self.swiftName = swiftName if swiftName is not None else name
self.kind = kind if kind is not None else "library"
self.args = args
self.comment = comment if comment is not None else "/// The " + str(self.swiftName) + " function."
if comment is not None:
self.comment = comment
else:
self.comment = "/// The " + str(self.swiftName) + " function."
self.platforms = platforms
def params(self, prefix="", suffix=""):
return ", ".join(
map(lambda a: prefix + a + suffix, self.args)
)
return ", ".join(map(lambda a: prefix + a + suffix, self.args))
def decl(self, type):
return self.swiftName + "(" + self.params("_ ", ": " + type) + ") -> " + type
return self.swiftName + "(" + self.params("_ ", ": " + type) + \
") -> " + type
def free_decl(self, constraint="T: ElementaryFunctions"):
return self.swiftName + "<T>(" + self.params("_ ", ": T") + ") -> T where " + constraint
return self.swiftName + "<T>(" + self.params("_ ", ": T") + \
") -> T where " + constraint
def impl(self, type):
if self.kind == "intrinsic":
builtin = "Builtin.int_" + self.name + "_FPIEEE" + str(type.bits)
return type.stdlib_name + "(" + builtin + "(" + self.params("","._value") + "))"
return "_swift_stdlib_" + self.name + type.cFuncSuffix + "(" + self.params() + ")"
return type.stdlib_name + "(" + builtin + "(" + \
self.params("", "._value") + "))"
return "_swift_stdlib_" + self.name + type.cFuncSuffix + "(" + \
self.params() + ")"
ElementaryFunctions = [
SwiftMathFunction(name="sqrt", kind="intrinsic", comment="/// The square root of `x`."),
SwiftMathFunction(name="cos", kind="intrinsic", comment="/// The cosine of `x`."),
SwiftMathFunction(name="sin", kind="intrinsic", comment="/// The sine of `x`."),
SwiftMathFunction(name="tan", comment="/// The tangent of `x`."),
SwiftMathFunction(name="sqrt", kind="intrinsic",
comment="/// The square root of `x`."),
SwiftMathFunction(name="cos", kind="intrinsic",
comment="/// The cosine of `x`."),
SwiftMathFunction(name="sin", kind="intrinsic",
comment="/// The sine of `x`."),
SwiftMathFunction(name="tan",
comment="/// The tangent of `x`."),
SwiftMathFunction(name="acos"),
SwiftMathFunction(name="asin"),
SwiftMathFunction(name="atan"),
@@ -48,15 +57,18 @@ ElementaryFunctions = [
SwiftMathFunction(name="log2", kind="intrinsic"),
SwiftMathFunction(name="log10", kind="intrinsic"),
SwiftMathFunction(name="log1p"),
# SwiftMathFunction(name="pow", kind="intrinsic", args="xy"), Handled separately for edge cases.
# SwiftMathFunction(name="root", args="xn"), Handled separately for implementation.
# SwiftMathFunction(name="pow", kind="intrinsic", args="xy"), Handled
# separately for edge cases.
# SwiftMathFunction(name="root", args="xn"), Handled separately for
# implementation.
]
RealFunctions = [
# SwiftMathFunction(name="atan2"), Handled separately for explicit arg labels.
# SwiftMathFunction(name="atan2"), Handled separately for explicit
# argument labels.
SwiftMathFunction(name="erf"),
SwiftMathFunction(name="erfc"),
SwiftMathFunction(name="hypot", args="xy"),
SwiftMathFunction(name="tgamma", swiftName="gamma"),
# SwiftMathFunction(name="lgamma"), Handled separately to handle sign result.
# SwiftMathFunction(name="lgamma"), Handled separately for sign result.
]