stdlib: Use Conlang module layout
This commit is contained in:
462
stdlib/std/num.cl
Normal file
462
stdlib/std/num.cl
Normal file
@@ -0,0 +1,462 @@
|
||||
//! The primitive numeric types
|
||||
|
||||
#[intrinsic = "bool"]
|
||||
pub type bool;
|
||||
|
||||
#[intrinsic = "char"]
|
||||
pub type char;
|
||||
|
||||
#[intrinsic = "i8"]
|
||||
pub type i8;
|
||||
|
||||
#[intrinsic = "i16"]
|
||||
pub type i16;
|
||||
|
||||
#[intrinsic = "i32"]
|
||||
pub type i32;
|
||||
|
||||
#[intrinsic = "i64"]
|
||||
pub type i64;
|
||||
|
||||
#[intrinsic = "isize"]
|
||||
pub type isize;
|
||||
|
||||
#[intrinsic = "u8"]
|
||||
pub type u8;
|
||||
|
||||
#[intrinsic = "u16"]
|
||||
pub type u16;
|
||||
|
||||
#[intrinsic = "u32"]
|
||||
pub type u32;
|
||||
|
||||
#[intrinsic = "u64"]
|
||||
pub type u64;
|
||||
|
||||
#[intrinsic = "usize"]
|
||||
pub type usize;
|
||||
|
||||
// Contains implementations for (TODO) overloaded operators on num types
|
||||
pub mod ops {
|
||||
use super::*;
|
||||
// Represents an ordering comparison verdict
|
||||
pub enum Ordering {
|
||||
Less,
|
||||
Equal,
|
||||
Greater,
|
||||
}
|
||||
|
||||
impl bool {
|
||||
pub const MIN: Self = false;
|
||||
pub const MAX: Self = true;
|
||||
pub const BIT_WIDTH: u32 = 1;
|
||||
pub fn default() -> Self {
|
||||
false
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl char {
|
||||
pub fn default() -> Self {
|
||||
'\u{1f988}'
|
||||
}
|
||||
}
|
||||
|
||||
impl u8 {
|
||||
pub const MIN: Self = 0;
|
||||
pub const MAX: Self = !0;
|
||||
pub const BIT_WIDTH: u32 = 1;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl u16 {
|
||||
pub const MIN: Self = 0;
|
||||
pub const MAX: Self = !0;
|
||||
pub const BIT_WIDTH: u32 = 2;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl u32 {
|
||||
pub const MIN: Self = 0;
|
||||
pub const MAX: Self = !0;
|
||||
pub const BIT_WIDTH: u32 = 4;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl u64 {
|
||||
pub const MIN: Self = 0;
|
||||
pub const MAX: Self = !0;
|
||||
pub const BIT_WIDTH: u32 = 8;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl usize {
|
||||
pub const MIN: Self = __march_ptr_width_unsigned_min();
|
||||
pub const MAX: Self = __march_ptr_width_unsigned_max();
|
||||
pub const BIT_WIDTH: u32 = __march_ptr_width_bits();
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl i8 {
|
||||
pub const MIN: Self = -128;
|
||||
pub const MAX: Self = 127;
|
||||
pub const BIT_WIDTH: u32 = 1;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl i16 {
|
||||
pub const MIN: Self = -32768;
|
||||
pub const MAX: Self = 32767;
|
||||
pub const BIT_WIDTH: u32 = 2;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl i32 {
|
||||
pub const MIN: Self = -2147483648;
|
||||
pub const MAX: Self = 2147483647;
|
||||
pub const BIT_WIDTH: u32 = 4;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl i64 {
|
||||
pub const MIN: Self = -9223372036854775808;
|
||||
pub const MAX: Self = 9223372036854775807;
|
||||
pub const BIT_WIDTH: u32 = 8;
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
|
||||
impl isize {
|
||||
pub const MIN: Self = __march_ptr_width_signed_min();
|
||||
pub const MAX: Self = __march_ptr_width_signed_max();
|
||||
pub const BIT_WIDTH: u32 = __march_ptr_width_bits();
|
||||
pub fn default() -> Self {
|
||||
0
|
||||
}
|
||||
pub fn mul(a: Self, b: Self) -> Self {
|
||||
a * b
|
||||
}
|
||||
pub fn div(a: Self, b: Self) -> Self {
|
||||
a / b
|
||||
}
|
||||
pub fn rem(a: Self, b: Self) -> Self {
|
||||
a % b
|
||||
}
|
||||
pub fn add(a: Self, b: Self) -> Self {
|
||||
a + b
|
||||
}
|
||||
pub fn sub(a: Self, b: Self) -> Self {
|
||||
a - b
|
||||
}
|
||||
pub fn shl(a: Self, b: u32) -> Self {
|
||||
a << b
|
||||
}
|
||||
pub fn shr(a: Self, b: u32) -> Self {
|
||||
a >> b
|
||||
}
|
||||
pub fn and(a: Self, b: Self) -> Self {
|
||||
a & b
|
||||
}
|
||||
pub fn or(a: Self, b: Self) -> Self {
|
||||
a | b
|
||||
}
|
||||
pub fn xor(a: Self, b: Self) -> Self {
|
||||
a ^ b
|
||||
}
|
||||
}
|
||||
}
|
||||
4
stdlib/std/str.cl
Normal file
4
stdlib/std/str.cl
Normal file
@@ -0,0 +1,4 @@
|
||||
//! TODO: give conland a string type
|
||||
use super::num::u8;
|
||||
|
||||
type str = [u8];
|
||||
79
stdlib/std/test.cl
Normal file
79
stdlib/std/test.cl
Normal file
@@ -0,0 +1,79 @@
|
||||
|
||||
//! Tests for funky behavior
|
||||
use super::preamble::*;
|
||||
|
||||
struct UnitLike;
|
||||
|
||||
struct TupleLike(super::num::i32, super::self::test::char)
|
||||
|
||||
struct StructLike {
|
||||
pub member1: UnitLike,
|
||||
member2: TupleLike,
|
||||
}
|
||||
|
||||
enum NeverLike;
|
||||
|
||||
enum EmptyLike {
|
||||
Empty,
|
||||
}
|
||||
|
||||
enum Hodgepodge {
|
||||
Empty,
|
||||
UnitLike (),
|
||||
Tuple (TupleLike),
|
||||
StructEmpty {},
|
||||
StructLike { member1: UnitLike, member2: TupleLike },
|
||||
}
|
||||
|
||||
fn noop () -> bool {
|
||||
loop if false {
|
||||
|
||||
} else break loop if false {
|
||||
|
||||
} else break loop if false {
|
||||
|
||||
} else break true;
|
||||
}
|
||||
|
||||
fn while_else() -> i32 {
|
||||
while conditional {
|
||||
pass
|
||||
} else {
|
||||
fail
|
||||
}
|
||||
}
|
||||
|
||||
fn if_else() -> i32 {
|
||||
// block 1
|
||||
let x = 10;
|
||||
let y = x + 2;
|
||||
|
||||
if x > 10
|
||||
// compare x and 10
|
||||
// end block 1, goto block 2 else goto block 3
|
||||
{
|
||||
// block 2
|
||||
4
|
||||
// end block 2, goto block 4
|
||||
} else {
|
||||
// block 3
|
||||
5
|
||||
// end block 3, goto block 4
|
||||
}
|
||||
// block 4
|
||||
}
|
||||
|
||||
mod horrible_imports {
|
||||
mod foo {
|
||||
use super::{bar::*, baz::*};
|
||||
struct Foo(&Foo, &Bar)
|
||||
}
|
||||
mod bar {
|
||||
use super::{foo::*, baz::*};
|
||||
struct Bar(&Foo, &Baz)
|
||||
}
|
||||
mod baz {
|
||||
use super::{foo::*, bar::*};
|
||||
struct Baz(&Foo, &Bar)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user