Files
sx/readme.md
2026-02-10 18:58:04 +02:00

89 lines
1.7 KiB
Markdown

# sx
*** HIGHLY EXPERIMENTAL *** DON'T USE ***
This experiment is trying to answer a few questions:
Q: Can we have an system language to build declarative ui ?
NOTE:
> i hope you have memory... currently it doesn't free anything :D
## Quick Sort Example
```sx
#import "modules/std.sx";
quickSort :: (items: []$T) {
partition :: (items: []T, lo: s32, hi: s32) -> s32 {
pivot := items[hi];
i := lo - 1;
j := lo;
while j < hi {
if items[j] < pivot {
i += 1;
tmp := items[i];
items[i] = items[j];
items[j] = tmp;
}
j += 1;
}
i += 1;
tmp := items[i];
items[i] = items[hi];
items[hi] = tmp;
i;
}
sort :: (items: []T, lo: s32, hi: s32) {
if lo < hi {
pi := partition(items, lo, hi);
sort(items, lo, pi - 1);
sort(items, pi + 1, hi);
}
}
sort(items, 0, items.len - 1);
}
main :: () {
arr := []s32.[1, 2, 3, 5, 2, 2, 3, 4, 5, 6, 6, 1];
quickSort(arr);
for arr {
if it_index > 0 { write(", "); }
print("{}", it);
}
write("\n");
}
```
## Building
Requires **Zig 0.16+** and **LLVM 19**.
```sh
zig build
```
## Usage
```sh
# compile to binary
sx build examples/06-generic.sx
# compile and run
sx run examples/06-generic.sx
# emit LLVM IR
sx ir examples/06-generic.sx
# start the language server
sx lsp
```
## Acknowledgments
- [Jonathan Blow](https://en.wikipedia.org/wiki/Jonathan_Blow) — for Jai, the language that inspired this one
- [Andrew Kelley](https://andrewkelley.me) — for Zig, which made this compiler a joy to write