From 6f254123dde5a279b17e9e48024930c5f63b57ba Mon Sep 17 00:00:00 2001 From: Adam McDaniel Date: Wed, 4 Sep 2024 18:25:07 -0400 Subject: [PATCH] Added to changelog --- CHANGELOG.md | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a889ee2..4e00fc55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -76,4 +76,113 @@ New VM instructions: ### Fixed -Generated code size is now up to 7x smaller than before. \ No newline at end of file +Generated code size is now up to 7x smaller than before. + +## [0.1.0-alpha] - 2024-9-4 + +Sage has just gotten a major upgrade, with a new module system📦 parser📝 and the Sage Lisp Preprocessor🛸!!! + +### Added + +- [Sage lisp compile time preprocessor language](https://github.com/adam-mcdaniel/sage-lisp) +```rs +// Define some code that modifies the AST of the expression it's called on +#![(defun square_sage_const(x) { + // Get a constant integer + (define n x@"ConstExpr"@"Int") + // Return the constant integer squared + ["ConstExpr" ["Float" n * n]] +})] + +// Call the compile time macro on 5. +// This will cause the compiler to perceive this code as `println(25)` +println(#[square_sage_const] 5); +``` + +- Module system + +```rs +// Import a module from a file named `from_file.sg` +mod from_file; + +// Define a module `io` with `getchar` +mod io { + fun getchar(): Char { + let mut ch = '\0'; + input(&mut ch); + return ch; + } +} + +// A module to test importing from other modules +mod testing { + mod internals { + // Import getchar from two modules up + from io import getchar; + + // Use it in a function + fun get_two(): (Char, Char) { (getchar(), getchar()) } + } + + // Get two chars and print them + fun get_two_then_print() { + // Import from a submodule, which imports from a supermodule + from internals import get_two; + let (a, b) = get_two(); + print(a, b); + } +} + +from testing import get_two_then_print; +get_two_then_print(); + +// Get two values and print them +for let mut i=0; i<6; i+=1; { + // We can also use the full path name + testing.get_two_then_print(); +} +``` + +- Standard library + +```rs +from std.fallible import Option, Result; + +enum Error { + DivideByZero { numerator: Int }, + Custom(&Char) +} + +fun divide(n: Int, d: Int): Option { + match d { + 0 => Option of Nothing, + _ => Option of Some(n / d) + } +} + + +fun main(): Result<(), Error> { + println(divide(5, 2)); + println(divide(5, 0)); + + return Result<(), Error> of Ok(()); +} + +println(main()); +``` + +- Better constant evaluation +- `from module.submodule import x, y as alias_for_y;` import statements +- `from module.submodule import *` import statements + +### Changed + +- The `def` keyword has been changed in favor of `fun`. +- `for` loops now have an extra semicolon on the last statement. `i += 1 {` becomes `i += 1; {`. + +### Fixed + +The compiler is significantly faster -- about 20 times faster at compiling the AES example. +This is mainly due to the much faster parser implemented with Nom instead of Pest. +There are also several optimizations with constant evaluation I added, along with optimizations +for how declarations are typechecked. \ No newline at end of file