Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/xnacly/seascript
SeaScript is a small c superset programming language that compiles to c
https://github.com/xnacly/seascript
c compiler go
Last synced: about 2 months ago
JSON representation
SeaScript is a small c superset programming language that compiles to c
- Host: GitHub
- URL: https://github.com/xnacly/seascript
- Owner: xNaCly
- License: mit
- Created: 2023-09-01T13:14:45.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-10-23T12:12:06.000Z (about 1 year ago)
- Last Synced: 2023-10-24T11:35:45.925Z (about 1 year ago)
- Topics: c, compiler, go
- Language: Go
- Homepage:
- Size: 65.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SeaScript
SeaScript is a small language that compiles to C. SeaScript is intended to improve the c experience drastically with the following features:
- result types
- functions attached to structs
- omitting most of the typ declarations
- providing useful data structures, such as growing arrays and hash maps
- 0 cost abstractions for functional approaches, such as filter, map, forEach
- template strings
- booleans
- 0 cost interoperability with the c ecosystemSeaScript is designed to automatically provide allocation and deallocation for
data structures and abstractions. The goal is to compute valid, performant and
safe c while allowing the developer to use a language that's minimal, nice to
read and that provides the base line of features required for modern
applications.## Compiler usage
```
$ cat main.sea
#include
puts("Hello (Sea)World!")
$ seacc main.sea
$ cat main.c
#include
#includeint main(void) {
puts("Hello (SeaWorld)");
return EXIT_SUCCESS;
}
```## Syntax
```seascript
:: include header files
#include:: variables
age = 24
money = 129.01
name = "anon":: lists
list = [5 4 3 2 1]
friends = ["jonathan" "mike"]:: functions
square [n: number]: number {
return n*n
}:: single line function
printer2n [a: number b: number]: void {
printf("%d %d\n" a b)
}:: calling functions
printer2n(square(12) square(2)):: iterating over lists
list.each(n {
printf("%f\n" n)
}):: c block
@c{
void print(int a, int b) {
printf("%d %d\n", a, b);
}
}:: using functions defined in c block
print(1 2):: results
sqrt [n: number]: Result[number] {
if n < 0 {
return Result{error: "can't compute sqrt for negative numbers"}
}
res = sqrt(n)
if res < 0 {
return Result{error: "couldn't compute sqrt of {n}"}
}
return Result{value: res}
}:: consuming results
res = sqrt(-5).unwrap() :: this will fail and stop the process
print(res):: structs
person = {
age: 24,
money: 102_910.99,
name: "seal",
toString [s: self]: string {
return "{s.name} | {s.age} | {s.money}",
}
}:: accessing struct properties
isTeenager = person.age > 13 && person.age < 20:: updating struct properties
if isTeenager {
person.age = 14
} else if person.age == 20 {
person.age = 0
} else {
puts("unhandled age")
}:: calling struct functions
puts(person.toString())
```