114 points · by adamthekiwi99 · 2y ago · 28 comments
Check out the web-demo to run the compiler in the browser, along with a graphical example using JavaScript interop! https://adam-mcdaniel.net/sage
Sage is designed to be portable, but also useful. To prove its usefulness, I used it to implement a user-space for a new operating system: SageOS https://github.com/adam-mcdaniel/sage-os The language also runs on embedded devices, like the flipper zero!
This is an interesting snippet from your website, did this project intentionally start out as an attempt to design around a Turing machine? Or is it just safe to say that all languages executing on a stack with no heap are Turing machines?
This is the work that inspired Sage: Harbor (https://github.com/adam-mcdaniel/harbor). My goal with Sage was to take everything that makes a brainfuck-like programming language easy to compile, while also keeping all the time complexity and optimizations of regular algorithms. So, in that sense, it started out as an attempt to design around a Turing machine -- I wanted this to be a dialect of brainfuck. The VM doesn't use any stack operations, just operations on a tape pointer + an accumulator!
However I am confused if the enum's are structural or nominal. It seems necessary to state which enum a variant comes from, like `Direction of South` (for that matter it seems the same is true when constructing structs?). Can you cast enum values to a wider enum type? Or combine different enum values (e.g. through branching - the return of `match`) to construct a value of a wider enum?
``` enum Option<T> {Some(T), Nothing}
// Create a value with an inline type that doesn't use the nominal `Option`
let opt1 = enum {Some(Int), Nothing} of Some(5);
// Define a second option value, which is assigned with the first
let opt2: Option<Int> = opt1;
// Print the result
println(opt2); ```
You can create a variant of an inline `enum` type, and then typecheck it against another structurally equal type if you so choose!
I hope this example properly illustrates how powerful the structural type-checking is with enums!
``` enum Option<T> {Some(T), Nothing};
let opt1 = enum {Some(Int)} of Some(5);
let opt2: Option<Int> = opt1; ```
Thanks for checking out the project, I'm glad I was able to surprise you haha! :)
I mean, it's hard to tell but it basically looks exactly like Rust but without lifetimes/borrow checks.
I put all the example programs in text on the web-demo, though, if you want to see more there! You can copy, read, or modify them there!
https://adam-mcdaniel.net/sage
It's different from Rust in that it has structural typing and a more Python-like experience! Types are constants, and can be printed with `print` like other values
Thanks for your input! I hope you like the project!
I might just go with a completely made up word to avoid any trademarks entirely haha
I was thinking "Pragmata", or something along those lines.
Continuing with natureish themes: Alga Moss Myco Wisp Ivy
I love these suggestions, especially Moss and Ivy! Thank you!
But definitely no garbage collection (although, a target could implement it against the standard and it would work)
Thanks for checking out the project!