From 1068dae5d618891a5b4929184470684c433607a2 Mon Sep 17 00:00:00 2001 From: Sam Vervaeck Date: Sun, 24 May 2020 21:34:10 +0200 Subject: [PATCH] Clean up to make room for new standard library --- stdlib/Boltfile | 1 + stdlib/either.bolt | 3 +++ stdlib/io.bolt | 11 ++--------- stdlib/lang/bolt.bolt | 2 +- stdlib/main.bolt | 0 stdlib/math.bolt | 35 +++++++++++++++++++++++++++-------- stdlib/option.bolt | 4 ++++ stdlib/string.bolt | 3 +++ stdlib/syntax.bolt | 5 ----- 9 files changed, 41 insertions(+), 23 deletions(-) create mode 100644 stdlib/either.bolt delete mode 100644 stdlib/main.bolt create mode 100644 stdlib/option.bolt create mode 100644 stdlib/string.bolt delete mode 100644 stdlib/syntax.bolt diff --git a/stdlib/Boltfile b/stdlib/Boltfile index e69de29bb..8b1378917 100644 --- a/stdlib/Boltfile +++ b/stdlib/Boltfile @@ -0,0 +1 @@ + diff --git a/stdlib/either.bolt b/stdlib/either.bolt new file mode 100644 index 000000000..6cf853562 --- /dev/null +++ b/stdlib/either.bolt @@ -0,0 +1,3 @@ + +pub struct Either; + diff --git a/stdlib/io.bolt b/stdlib/io.bolt index 3fb7e92e4..fae35db12 100644 --- a/stdlib/io.bolt +++ b/stdlib/io.bolt @@ -1,12 +1,5 @@ -pub struct String; - -pub struct Either { - is_right: bool, - value: L | R, -} - -mod io { +mod IO { pub type Result = Either; @@ -36,5 +29,5 @@ mod io { } -print("Hello, world!"); +// IO::print("Hello, world!"); diff --git a/stdlib/lang/bolt.bolt b/stdlib/lang/bolt.bolt index c0c25a243..e64ce19d7 100644 --- a/stdlib/lang/bolt.bolt +++ b/stdlib/lang/bolt.bolt @@ -1,5 +1,5 @@ -mod Bolt.Lang { +mod Bolt::Lang { pub struct Pos { offset: Int, diff --git a/stdlib/main.bolt b/stdlib/main.bolt deleted file mode 100644 index e69de29bb..000000000 diff --git a/stdlib/math.bolt b/stdlib/math.bolt index 4a44ffbe3..bb2fea185 100644 --- a/stdlib/math.bolt +++ b/stdlib/math.bolt @@ -1,7 +1,32 @@ -newtype Int; +pub struct i32; +pub struct i64; +pub struct isize; +pub struct u32; +pub struct u64; +pub struct usize; -pub fn fac(n: Int) -> Int { +trait Num; + +fn (a: N) + (b: N) -> N where N: Num { + N::add(a, b) +} + +fn (a: N) - (b: N) -> N where N: Num { + N::sub(a, b) +} + +fn (a: N) / (b: N) -> N where N: Num { + N::div(a, b) +} + +fn (a: N) * (b: N) -> N where N: Num { + N::mul(a, b) +} + +// precedence a + b < a * b; + +pub fn fac(n: I) -> I where I: int { if n == 0 { return 1 } else { @@ -9,9 +34,3 @@ pub fn fac(n: Int) -> Int { } } -fn (a: Int) + (b: Int) -> Int { - -} - -precedence a + b < a * b; - diff --git a/stdlib/option.bolt b/stdlib/option.bolt new file mode 100644 index 000000000..920da083b --- /dev/null +++ b/stdlib/option.bolt @@ -0,0 +1,4 @@ + +pub struct Option; + + diff --git a/stdlib/string.bolt b/stdlib/string.bolt new file mode 100644 index 000000000..d1251c063 --- /dev/null +++ b/stdlib/string.bolt @@ -0,0 +1,3 @@ + +pub struct String; + diff --git a/stdlib/syntax.bolt b/stdlib/syntax.bolt deleted file mode 100644 index bc019d8de..000000000 --- a/stdlib/syntax.bolt +++ /dev/null @@ -1,5 +0,0 @@ - -import "lang/bolt" ( - Identifier, - Syntax, -);