diff --git a/assets/examples/loops.rhea b/assets/examples/loops.rhea new file mode 100644 index 0000000..ca2167f --- /dev/null +++ b/assets/examples/loops.rhea @@ -0,0 +1,13 @@ +func main(){ + var i = 0; + loop { + match i { + 10 -> break; + } + i = i + 1; + } + loop {} +} + + + diff --git a/assets/examples/match.rhea b/assets/examples/match.rhea new file mode 100644 index 0000000..1062754 --- /dev/null +++ b/assets/examples/match.rhea @@ -0,0 +1,9 @@ +var std = import "std"; +var print = std.print; + +func main() { + match 2 { + 1 -> { print("One") } + 2 -> { print("Two") } + } +} \ No newline at end of file diff --git a/assets/libraries/math/constants.rhea b/assets/libraries/math/constants.rhea index 50db5b9..9abab85 100644 --- a/assets/libraries/math/constants.rhea +++ b/assets/libraries/math/constants.rhea @@ -3,4 +3,7 @@ const C = 299_792_458; const pi = 3.141592653589793; -const tau = 6.283185307179586; \ No newline at end of file +const π = pi; + +const tau = 6.283185307179586; +const 𝜏 = tau; \ No newline at end of file diff --git a/assets/libraries/math/math.rhea b/assets/libraries/math/math.rhea index 8e22b41..e1f25ea 100644 --- a/assets/libraries/math/math.rhea +++ b/assets/libraries/math/math.rhea @@ -1 +1,24 @@ -var constants = include "constants"; \ No newline at end of file +var constants = include "constants"; + +func square_root(value){ + match value{ + 0..1 -> return value; + value -> { + var y = x; + var z = (y + (x/y)) / 2; + // NOTE: not finalized syntax + while abs(y - z) >= 0.00001{ + y = z + z = (y + (x/y)) / 2 + } + return z; + } + } +} +var sqrt = square_root; +var √ = square_root; + +func absolute_value(value){ + +} +var abs = absolute_value; \ No newline at end of file diff --git a/assets/libraries/std/io.rhea b/assets/libraries/std/io.rhea index 90f0d10..3dc74b6 100644 --- a/assets/libraries/std/io.rhea +++ b/assets/libraries/std/io.rhea @@ -1 +1,6 @@ -var log = include "log"; \ No newline at end of file +var log = include "log"; + +func print(value) { + // TODO: define an api for output +} + diff --git a/assets/libraries/std/log.rhea b/assets/libraries/std/log.rhea index 3237ccb..1b6a90b 100644 --- a/assets/libraries/std/log.rhea +++ b/assets/libraries/std/log.rhea @@ -1,5 +1,25 @@ -func error(){} -func warn(){} -func info(){} -func debug(){} -func trace(){} \ No newline at end of file +var io = include "io"; +var print = io.print; + +// TODO: include time in the log + + +func error(value){ + print("error " + value) +} + +func warn(value){ + print("warn " + value) +} + +func info(value){ + print("info " + value) +} + +func debug(value){ + print("debug " + value) +} + +func trace(value){ + print("trace " + value) +} \ No newline at end of file diff --git a/assets/libraries/std/std.rhea b/assets/libraries/std/std.rhea index 4b29b34..468fd3b 100644 --- a/assets/libraries/std/std.rhea +++ b/assets/libraries/std/std.rhea @@ -1,2 +1,4 @@ -var io = include "std.io"; -var math = include "math" \ No newline at end of file +var io = include "io"; +var math = include "math"; + +var print = io.print; \ No newline at end of file diff --git a/src/syntax/token.rs b/src/syntax/token.rs index 044bb36..ecfc47a 100644 --- a/src/syntax/token.rs +++ b/src/syntax/token.rs @@ -58,6 +58,7 @@ pub enum Token { #[token("const")] Const, #[token("var")] Var, #[token("func")] Func, + // Modules aren't real here ondra just variables with imported functions #[token("module")] Module, #[regex(