112 lines
2.3 KiB
Plaintext
112 lines
2.3 KiB
Plaintext
# Builtin arithmetic operators for Peon
|
|
# Note: Most of these do nothing on their own. All they do
|
|
# is serve as placeholders for emitting specific VM
|
|
# instructions. They're implemented this way because:
|
|
# - They tie into the existing type system nicely
|
|
# - It makes the implementation easier and more flexible
|
|
|
|
|
|
operator `+`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): T {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`(a, b: float): float {
|
|
#pragma[magic: "AddFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `+`(a, b: float32): float32 {
|
|
#pragma[magic: "AddFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `-`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): T {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: float64): float64 {
|
|
#pragma[magic: "SubtractFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: float32): float32 {
|
|
#pragma[magic: "SubtractFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `-`*[T: int | int32 | int16 | int8](a: T): T {
|
|
#pragma[magic: "Negate", pure]
|
|
}
|
|
|
|
|
|
operator `-`*[T: uint64 | uint32 | uint16 | uint8](a: T): T {
|
|
#pragma[error: "unsigned integer cannot be negative"]
|
|
}
|
|
|
|
|
|
operator `-`*(a: float64): float64 {
|
|
#pragma[magic: "NegateFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a: float32): float32 {
|
|
#pragma[magic: "NegateFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a: inf): inf {
|
|
#pragma[magic: "NegInf", pure]
|
|
}
|
|
|
|
|
|
operator `*`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): T {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: float64): float64 {
|
|
#pragma[magic: "MultiplyFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: float32): float32 {
|
|
#pragma[magic: "MultiplyFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `/`*[T: int | int32 | int16 | int8](a, b: T): T {
|
|
#pragma[magic: "SignedDivide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*[T: uint64 | uint32 | uint16 | uint8](a, b: T): T {
|
|
#pragma[magic: "Divide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: float64): float64 {
|
|
#pragma[magic: "DivFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: float32): float32 {
|
|
#pragma[magic: "DivFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `**`*[T: int | int32 | int16 | int8](a, b: T): T {
|
|
#pragma[magic: "SignedPow", pure]
|
|
}
|
|
|
|
|
|
operator `**`*[T: uint64 | uint32 | uint16 | uint8](a, b: T): T {
|
|
#pragma[magic: "Pow", pure]
|
|
}
|
|
|
|
|
|
operator `%`*(a, b: int64): int64 {
|
|
#pragma[magic: "SignedMod", pure]
|
|
}
|