From 53b253b9e9b036ad62577471b38db59ff16af32c Mon Sep 17 00:00:00 2001 From: Sam Vervaeck Date: Mon, 25 May 2020 11:05:06 +0200 Subject: [PATCH] Some minor fixes to standard library --- stdlib/lang/bolt.bolt | 9 ++++++--- stdlib/lib.bolt | 8 ++++++++ stdlib/math.bolt | 25 ------------------------- stdlib/numbers.bolt | 26 ++++++++++++++++++++++++++ stdlib/option.bolt | 1 - stdlib/vec.bolt | 3 +++ 6 files changed, 43 insertions(+), 29 deletions(-) create mode 100644 stdlib/lib.bolt create mode 100644 stdlib/numbers.bolt create mode 100644 stdlib/vec.bolt diff --git a/stdlib/lang/bolt.bolt b/stdlib/lang/bolt.bolt index e64ce19d7..53b59801d 100644 --- a/stdlib/lang/bolt.bolt +++ b/stdlib/lang/bolt.bolt @@ -1,10 +1,13 @@ +import "../option" +import "../numbers" + mod Bolt::Lang { pub struct Pos { - offset: Int, - line: Int, - column: Int, + offset: usize, + line: usize, + column: usize, } pub struct Span { diff --git a/stdlib/lib.bolt b/stdlib/lib.bolt new file mode 100644 index 000000000..0f5da39d0 --- /dev/null +++ b/stdlib/lib.bolt @@ -0,0 +1,8 @@ + +pub import "./option" +pub import "./either" +pub import "./string" +pub import "./math.bolt" +pub import "./vec.bolt" +pub import "./lang/bolt" + diff --git a/stdlib/math.bolt b/stdlib/math.bolt index adba90709..1ba6e9cc8 100644 --- a/stdlib/math.bolt +++ b/stdlib/math.bolt @@ -1,29 +1,4 @@ -pub struct i32; -pub struct i64; -pub struct isize; -pub struct u32; -pub struct u64; -pub struct usize; - -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 { diff --git a/stdlib/numbers.bolt b/stdlib/numbers.bolt new file mode 100644 index 000000000..d0643a84f --- /dev/null +++ b/stdlib/numbers.bolt @@ -0,0 +1,26 @@ + +pub struct i32; +pub struct i64; +pub struct isize; +pub struct u32; +pub struct u64; +pub struct usize; + +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) +} + diff --git a/stdlib/option.bolt b/stdlib/option.bolt index 920da083b..3a38474ea 100644 --- a/stdlib/option.bolt +++ b/stdlib/option.bolt @@ -1,4 +1,3 @@ pub struct Option; - diff --git a/stdlib/vec.bolt b/stdlib/vec.bolt new file mode 100644 index 000000000..ee5538673 --- /dev/null +++ b/stdlib/vec.bolt @@ -0,0 +1,3 @@ + +pub struct Vec; +