Skip to content

Commit

Permalink
Added to changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-mcdaniel committed Sep 4, 2024
1 parent b5bc3bd commit 6f25412
Showing 1 changed file with 110 additions and 1 deletion.
111 changes: 110 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,113 @@ New VM instructions:

### Fixed

Generated code size is now up to 7x smaller than before.
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<Int> {
match d {
0 => Option<Int> of Nothing,
_ => Option<Int> 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.

0 comments on commit 6f25412

Please sign in to comment.