223 lines
4.6 KiB
Plaintext
223 lines
4.6 KiB
Plaintext
## The peon standard library
|
|
|
|
# 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 `-`*(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]
|
|
}
|
|
|
|
# Comparison operators
|
|
|
|
operator `>`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8 | float | float32](a, b: T): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8 | float | float32](a, b: T): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8 | float | float32](a, b: T): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
|
|
}
|
|
|
|
operator `!=`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8 | float | float32](a, b: T): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8 | float | float32](a, b: T): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8 | float | float32](a, b: T): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `and`*(a, b: bool): bool {
|
|
#pragma[magic: "LogicalAnd", pure]
|
|
}
|
|
|
|
|
|
operator `or`*(a, b: bool): bool {
|
|
#pragma[magic: "LogicalOr", pure]
|
|
}
|
|
|
|
|
|
operator `not`*(a: bool): bool {
|
|
#pragma[magic: "LogicalNot", pure]
|
|
}
|
|
|
|
|
|
operator `&`*(a, b: int): bool {
|
|
#pragma[magic: "And", pure]
|
|
}
|
|
|
|
|
|
operator `|`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): int {
|
|
#pragma[magic: "Or", pure]
|
|
}
|
|
|
|
|
|
operator `~`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a: T): T {
|
|
#pragma[magic: "Not", pure]
|
|
}
|
|
|
|
|
|
operator `>>`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): T {
|
|
#pragma[magic: "RShift", pure]
|
|
}
|
|
|
|
|
|
operator `<<`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): T {
|
|
#pragma[magic: "LShift", pure]
|
|
}
|
|
|
|
|
|
operator `^`*[T: int | uint64 | int32 | uint32 | int16 | uint16 | int8 | uint8](a, b: T): T {
|
|
#pragma[magic: "Xor", pure]
|
|
}
|
|
|
|
|
|
# Assignment operators
|
|
|
|
operator `=`*[T: all](a: var T, b: T) { # TODO: This is just a placeholder right now
|
|
#pragma[magic: "GenericAssign"]
|
|
}
|
|
|
|
|
|
# Some useful builtins
|
|
|
|
fn clock*: float {
|
|
#pragma[magic: "SysClock64", pure]
|
|
}
|
|
|
|
|
|
fn print*(x: int) {
|
|
#pragma[magic: "PrintInt64"]
|
|
}
|
|
|
|
|
|
fn print*(x: uint64) {
|
|
#pragma[magic: "PrintUInt64"]
|
|
}
|
|
|
|
|
|
fn print*(x: float) {
|
|
#pragma[magic: "PrintFloat64"]
|
|
}
|
|
|
|
|
|
fn print*(x: string) {
|
|
#pragma[magic: "PrintString"]
|
|
}
|
|
|
|
|
|
fn print*(x: bool) {
|
|
#pragma[magic: "PrintBool"]
|
|
} |