kosu-lang
所属分类:编程语言基础
开发工具:OCaml
文件大小:0KB
下载次数:0
上传日期:2023-08-26 21:06:22
上 传 者:
sh-1993
说明: 试图制作一种编程语言,
(Trying to make a programming language,)
文件列表:
.ocamlformat (150, 2023-08-26)
CHANGELOG.md (2647, 2023-08-26)
LICENSE (35149, 2023-08-26)
Makefile (126, 2023-08-26)
bin/ (0, 2023-08-26)
bin/dune (2023, 2023-08-26)
bin/kosu.ml (1693, 2023-08-26)
bin/kosuc.ml (1694, 2023-08-26)
bin/kosuc_bc.ml (1687, 2023-08-26)
bin/kosurun.ml (1602, 2023-08-26)
doc/ (0, 2023-08-26)
doc/Builtin.md (3335, 2023-08-26)
doc/Control-Flow.md (1846, 2023-08-26)
doc/Function.md (1581, 2023-08-26)
doc/Type.md (1346, 2023-08-26)
dune-project (2147, 2023-08-26)
examples/ (0, 2023-08-26)
examples/game-of-life/ (0, 2023-08-26)
examples/game-of-life/cio.kosu (92, 2023-08-26)
examples/game-of-life/main.kosu (3370, 2023-08-26)
examples/game-of-life/option.kosu (597, 2023-08-26)
examples/game-of-life/vector.kosu (1738, 2023-08-26)
examples/mini-std/ (0, 2023-08-26)
examples/mini-std/Cstd/ (0, 2023-08-26)
examples/mini-std/Cstd/io.kosu (174, 2023-08-26)
examples/mini-std/Cstd/lib.kosu (124, 2023-08-26)
examples/mini-std/Cstd/str.kosu (112, 2023-08-26)
examples/mini-std/Fs/ (0, 2023-08-26)
examples/mini-std/Fs/file.kosu (279, 2023-08-26)
examples/mini-std/Fs/openOption.kosu (1794, 2023-08-26)
examples/mini-std/box.kosu (430, 2023-08-26)
examples/mini-std/list.kosu (2108, 2023-08-26)
examples/mini-std/option.kosu (904, 2023-08-26)
examples/mini-std/result.kosu (273, 2023-08-26)
examples/mini-std/sys.kosu (1806, 2023-08-26)
examples/mini-std/vector.kosu (2206, 2023-08-26)
kosu_lang.opam (734, 2023-08-26)
... ...
# Kosu
Kosu is (or will be at least I hope) a statically-typed, expression-oriented language.
The philosophy of Kosu is to have as control over memory as C (manual memory management, pointers) while having some higher features like generics or sum type.
## Roadmap (For now)
- [x] Lexer
- [x] Parser
- [x] Better syntax error handling
- [x] Better logic error handling
- [x] Ast
- [x] Type checking the Ast
- [x] Annote the Ast with type
- [x] Create an intermediate representation using the 3 adress code method
- [x] Generate basic Arm64 assembly for MacOs
- [x] Generate basic x86_64 assembly
- [x] Fix Syntax issues
- [x] Add while loop
- [x] Fix Immediate encoding on arm64
- [x] Implement Float for both architecture
- [x] Implement Operator overload
== Version 0.1.0 ==
- [ ] Write a register allocator throught graph-coloring method
- [x] Integer/Float size inference
- [ ] Add anonymous function
- [x] Add array Literral
- [x] Fix stack base function parameters on arm64/x86_64
- [ ] Improve c compatibily ABI
## Example
```
const EXIT_SUCCESS = 0;
enum option(wrapper) {
some(wrapper),
none
}
struct point {
x: s8,
y: u8
}
external malloc(_: u64) anyptr;
external print(format: stringl; ...) s32 = "printf";
fn default(option: option(t), default: t) t {
$ switch (option) {
.none => { $ default }
.some(x) => { $ x }
}
}
// Single line comment
fn fibonacci(n: u32) u32 {
$ cases {
of n == 0u32 => { $ 0u32 }
of n == 1u32 => { $ 1u32 }
else { $ fibonacci(n - 1u32) + fibonacci(n - 2u32) }
}
}
fn main() s32 {
/*
Multiple lines comment
*/
const message_opt = .some("Hello world");
const message = message_opt |> default("Never");
discard print("%s\n", message);
$ EXIT_SUCCESS
}
```
## How to build
- You will also need to install [libffi](https://github.com/libffi/libffi):
```bash
$ opam install dune cmdliner menhir
$ cd kosu-lang
$ dune build
```
Once build, the following programs are generated:
| command | description |
| ---- | ------
| `kosuc` | the Kosu native compiler
| `kosu` |the Kosu repl
| `kosuc.bc` | the Kosu bytecode compiler
| `kosurun` | the Kosu bytecode interpreter
### Caution
- ```kosuc.bc``` is highly experimental, segmentation-fault prone and not even terminated.
So unless wanted, you don't have any reason to use ```kosuc.bc``` over ```kosuc```
## How to run
To compile the example above on MacOS (M1)
```bash
$ kosuc --arch arm64 --os macos -o example example.kosu
$ ./example
```
On MacOS (Intel)
```bash
$ kosuc --arch x86_64 --os macos -o example example.kosu
$ ./example
```
On FreeBSD (x86_64)
```bash
$ kosuc --arch x86_64 --os freebsd -o example example.kosu
$ ./example
```
On Linux (x86_64)
```bash
$ kosuc --arch x86_64 --os linux -o example example.kosu
$ ./example
```
## Other
- You can see more detail about:
- in [Readme.md](/doc/Readme.md)
- in [test](/test/files/)
近期下载者:
相关文件:
收藏者: