566 lines
8.7 KiB
Plaintext
566 lines
8.7 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
|
|
|
|
|
|
# TODO: Use generics
|
|
|
|
operator `+`*(a, b: int): int {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: uint64): uint64 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: int32): int32 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: uint32): uint32 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: int16): int16 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: uint16): uint16 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: int8): int8 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: uint8): uint8 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: float64): float64 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `+`*(a, b: float32): float32 {
|
|
#pragma[magic: "Add", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: int): int {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: uint64): uint64 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: int32): int32 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: uint32): uint32 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: int16): int16 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: uint16): uint16 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: int8): int8 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: uint8): uint8 {
|
|
#pragma[magic: "Subtract", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: float64): float64 {
|
|
#pragma[magic: "SubtractFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `-`*(a, b: float32): float32 {
|
|
#pragma[magic: "SubtractFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: int): int {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: uint64): uint64 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: int32): int32 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: uint32): uint32 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: int16): int16 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: uint16): uint16 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: int8): int8 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: uint8): uint8 {
|
|
#pragma[magic: "Multiply", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: float64): float64 {
|
|
#pragma[magic: "MultiplyFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `*`*(a, b: float32): float32 {
|
|
#pragma[magic: "MultiplyFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: int): int {
|
|
#pragma[magic: "SignedDivide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: uint64): uint64 {
|
|
#pragma[magic: "Divide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: int32): int32 {
|
|
#pragma[magic: "SignedDivide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: uint32): uint32 {
|
|
#pragma[magic: "Divide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: int16): int16 {
|
|
#pragma[magic: "SignedDivide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: uint16): uint16 {
|
|
#pragma[magic: "Divide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: int8): int8 {
|
|
#pragma[magic: "SignedDivide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: uint8): uint8 {
|
|
#pragma[magic: "Divide", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: float64): float64 {
|
|
#pragma[magic: "DivFloat64", pure]
|
|
}
|
|
|
|
|
|
operator `/`*(a, b: float32): float32 {
|
|
#pragma[magic: "DivFloat32", pure]
|
|
}
|
|
|
|
|
|
operator `**`*(a, b: int64): int64 {
|
|
#pragma[magic: "SignedPow", pure]
|
|
}
|
|
|
|
|
|
operator `**`*(a, b: uint64): uint64 {
|
|
#pragma[magic: "Pow", pure]
|
|
}
|
|
|
|
|
|
# Comparison operators
|
|
|
|
operator `>`*(a, b: int): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: int): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: int): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
|
|
}
|
|
|
|
operator `!=`*(a, b: int): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: uint64): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: uint64): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: uint64): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: uint64): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: int32): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: int32): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: int32): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: int32): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
operator `>`*(a, b: uint32): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: uint32): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: uint32): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: uint32): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: int16): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: int16): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: int16): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: int16): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: uint16): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: uint16): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: uint16): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: uint16): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: int8): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: int8): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: int8): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: int8): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: uint8): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: uint8): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: uint8): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: uint8): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: float): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: float): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: float): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: float): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>`*(a, b: float32): bool {
|
|
#pragma[magic: "GreaterThan", pure]
|
|
}
|
|
|
|
|
|
operator `<`*(a, b: float32): bool {
|
|
#pragma[magic: "LessThan", pure]
|
|
}
|
|
|
|
|
|
operator `==`*(a, b: float32): bool {
|
|
#pragma[magic: "Equal", pure]
|
|
}
|
|
|
|
|
|
operator `!=`*(a, b: float32): bool {
|
|
#pragma[magic: "NotEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: int): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: int): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: uint64): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: uint64): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: int32): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: int32): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: uint32): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: uint32): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: int16): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: int16): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: uint16): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: uint16): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: int8): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: int8): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: uint8): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: uint8): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: float): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: float): bool {
|
|
#pragma[magic: "LessOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `>=`*(a, b: float32): bool {
|
|
#pragma[magic: "GreaterOrEqual", pure]
|
|
}
|
|
|
|
|
|
operator `<=`*(a, b: float32): 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]
|
|
}
|
|
|
|
|
|
# Assignment operators
|
|
|
|
operator `=`[T: Any](a: var T, b: T) {
|
|
#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"]
|
|
}
|