Skip to content

Commit d163456

Browse files
committed
Update Docs
1 parent 04d7ab4 commit d163456

79 files changed

Lines changed: 4437 additions & 39 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ cache/
66
.vpm/
77
Vix-lang/
88
XpmCode/
9+
Vix-lang*/

.vitepress/config.mts

Lines changed: 308 additions & 20 deletions
Large diffs are not rendered by default.

index.md

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ Vix 是一种轻量级、静态类型的编译型语言,目标是在保持语
1414

1515
| 版本 | 文档 |
1616
|------|------|
17-
| **v0.2.0** (最新) | [中文](/v0.2.0/zh_CN/what-is-vix) \| [English](/v0.2.0/en/what-is-vix) \| [更新日志](/v0.2.0/zh_CN/release-notes) |
17+
| **v0.3.0** (最新) | [中文](/v0.3.0/zh_CN/what-is-vix) \| [English](/v0.3.0/en/what-is-vix) \| [更新日志](/v0.3.0/zh_CN/release-notes) |
18+
| **v0.2.0** | [中文](/v0.2.0/zh_CN/what-is-vix) \| [English](/v0.2.0/en/what-is-vix) \| [更新日志](/v0.2.0/zh_CN/release-notes) |
1819
| **v0.1.0** | [中文](/v0.1.0/zh_CN/what-is-vix) \| [English](/v0.1.0/en/what-is-vix) |
1920

2021
## 特性概览
@@ -57,7 +58,8 @@ make
5758
创建 `hello.vix`
5859

5960
```vix
60-
fn main() -> i32 {
61+
fn main(): i32
62+
{
6163
print("Hello, Vix!")
6264
return 0
6365
}
@@ -79,14 +81,16 @@ fn main() -> i32 {
7981
### 斐波那契
8082

8183
```vix
82-
fn fib(n: i32) -> i32 {
84+
fn fib(n: i32): i32
85+
{
8386
if (n <= 1) {
8487
return n
8588
}
8689
return fib(n - 1) + fib(n - 2)
8790
}
8891
89-
fn main() -> i32 {
92+
fn main(): i32
93+
{
9094
print(fib(10))
9195
return 0
9296
}
@@ -95,8 +99,9 @@ fn main() -> i32 {
9599
### for 循环
96100

97101
```vix
98-
fn main() -> i32 {
99-
mut sum = 0
102+
fn main(): i32
103+
{
104+
let mut sum = 0
100105
for (i in 1 .. 100) {
101106
sum = sum + i
102107
}
@@ -107,19 +112,18 @@ fn main() -> i32 {
107112

108113
## 文档
109114

110-
- [CONTRIBUTING.md](/v0.1.0/zh_CN/CONTRIBUTING.md) —— 贡献指南,如何参与项目开发
111-
- [control-flow.md](/v0.1.0/zh_CN/control-flow.md) —— 控制流语句(if、循环等)的语法与用法
112-
- [functions.md](/v0.1.0/zh_CN/functions.md) —— 函数定义、调用、泛型等特性
113-
- [getting-started.md](/v0.1.0/zh_CN/getting-started.md) —— 快速入门指南,安装与第一个程序
114-
- [modules.md](/v0.1.0/zh_CN/modules.md) —— 模块系统,导入与导出规则
115-
- [pointers.md](/v0.1.0/zh_CN/pointers.md) —— 指针的声明、解引用、运算及使用示例
116-
- [stdlib.md](/v0.1.0/zh_CN/stdlib.md) —— 标准库提供的函数与常用模块
117-
- [structs.md](/v0.1.0/zh_CN/structs.md) —— 结构体定义、实例化、字段访问
118-
- [syntax.md](/v0.1.0/zh_CN/syntax.md) —— 完整语法参考,包含 EBNF 形式
119-
- [types.md](/v0.1.0/zh_CN/types.md) —— 类型系统:基本类型、泛型、联合类型等
120-
- [what-is-vix.md](/v0.1.0/zh_CN/what-is-vix.md) —— Vix 语言简介与设计目标
121-
122-
> 提示:如果你只想从零开始跑通一次编译 + 运行,建议先看 [getting-started.md](/v0.1.0/zh_CN/getting-started.md)
115+
- [control-flow.md](/v0.3.0/zh_CN/control-flow.md) —— 控制流语句(if、循环等)的语法与用法
116+
- [functions.md](/v0.3.0/zh_CN/functions.md) —— 函数定义、调用、泛型等特性
117+
- [getting-started.md](/v0.3.0/zh_CN/getting-started.md) —— 快速入门指南,安装与第一个程序
118+
- [modules.md](/v0.3.0/zh_CN/modules.md) —— 模块系统,导入与导出规则
119+
- [pointers.md](/v0.3.0/zh_CN/pointers.md) —— 指针的声明、解引用、运算及使用示例
120+
- [stdlib.md](/v0.3.0/zh_CN/stdlib.md) —— 标准库提供的函数与常用模块
121+
- [structs.md](/v0.3.0/zh_CN/type-struct.md) —— 结构体定义、实例化、字段访问
122+
- [syntax.md](/v0.3.0/zh_CN/syntax.md) —— 完整语法参考,包含 EBNF 形式
123+
- [types.md](/v0.3.0/zh_CN/types.md) —— 类型系统:基本类型、泛型、联合类型等
124+
- [what-is-vix.md](/v0.3.0/zh_CN/what-is-vix.md) —— Vix 语言简介与设计目标
125+
126+
> 提示:如果你只想从零开始跑通一次编译 + 运行,建议先看 [getting-started.md](/v0.3.0/zh_CN/getting-started.md)
123127
124128
## 参与贡献
125129

v0.3.0/en/acknowledgements.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Acknowledgements
2+
3+
Vix Language is built on the shoulders of these open-source projects and communities.
4+
5+
## Technology
6+
7+
- **LLVM** — Compiler backend infrastructure
8+
- **Flex** — Lexer generator
9+
- **Bison** — Parser generator
10+
- **CMake** — Build system
11+
12+
## Core Contributors
13+
14+
- Daweidie — Project creator, core developer
15+
- Community contributors — See GitHub contributors list
16+
17+
## Inspiration
18+
19+
- **Rust** — Ownership and borrow checking concepts
20+
- **C** — Performance and low-level control
21+
- **Go** — Simplicity philosophy
22+
- **OCaml** — Hindley-Milner type inference
23+
24+
## Contact
25+
26+
- GitHub: [https://github.com/vixlang](https://github.com/vixlang)
27+
- Email: popolk1871@outlook.com

v0.3.0/en/compiler-cli.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# Compiler CLI Reference
2+
3+
## Usage
4+
5+
```
6+
vixc [options] <input.vix>
7+
vixc file1.o file2.o ... -o <output>
8+
```
9+
10+
## Options
11+
12+
| Flag | Description |
13+
|------|-------------|
14+
| `-o <file>` | Write output to `<file>` |
15+
| `-S [file]` | Emit assembly (default: `<input>.s`) |
16+
| `-obj [file]` | Emit object file (default: `<input>.o`) |
17+
| `-ll [file]` | Emit LLVM IR (default: `<input>.ll`) |
18+
| `-llvm` | Print LLVM IR to stdout |
19+
| `-ast` | Print AST to stdout |
20+
| `--debug` | Enable debug output |
21+
| `--check` | Syntax & type check only |
22+
| `--time` | Show phase timing breakdown |
23+
| `-opt=lN` | Set optimization level (N = 0..3) |
24+
| `--target=<triple>` | Set codegen/link target triple |
25+
| `-v, --version` | Display compiler version |
26+
| `-h, --help` | Display help message |
27+
28+
## Attributes
29+
30+
```vix
31+
#[no_std] // Don't link standard library
32+
#[no_main] // Don't require a main function
33+
```
34+
35+
## Examples
36+
37+
```bash
38+
# Compile to executable
39+
vixc hello.vix -o hello
40+
41+
# Type check only
42+
vixc hello.vix --check
43+
44+
# View AST
45+
vixc hello.vix -ast
46+
47+
# View LLVM IR
48+
vixc hello.vix -llvm
49+
50+
# Optimization level 3
51+
vixc hello.vix -opt=l3 -o hello
52+
53+
# Cross-compile to ARM64
54+
vixc hello.vix --target=aarch64-linux-gnu -o hello
55+
56+
# Cross-compile to WebAssembly
57+
vixc hello.vix --target=wasm32-unknown-unknown -o hello.wasm
58+
59+
# Multi-object file linking
60+
vixc a.o b.o c.o -o program
61+
```
62+
63+
## Linker C API
64+
65+
```c
66+
typedef struct {
67+
const char* target_triple;
68+
int bare_mode;
69+
const char* linker_script;
70+
int static_link;
71+
const char* entry_point;
72+
const char* libc_dir;
73+
} VixLinkOptions;
74+
75+
int vix_link(const char* obj_file, const char* output_file,
76+
const VixLinkOptions* options, const char** error_msg);
77+
78+
int vix_link_multi(const char** obj_files, int obj_count,
79+
const char* output_file,
80+
const VixLinkOptions* options, const char** error_msg);
81+
```

v0.3.0/en/compiler.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Compiler Architecture
2+
3+
vixc is an AOT compiler that translates Vix sources to native executables. The frontend is written in C, backend in C++.
4+
5+
## Compilation Pipeline
6+
7+
```
8+
Source → Flex Lexer → Bison Parser → AST
9+
→ Import Inlining → Semantic Analysis → Type Check → Ownership Check
10+
→ LLVM IR Gen → LLC Object → LLD Link → Executable
11+
```
12+
13+
## Source Organization
14+
15+
```
16+
src/
17+
├── main.c # Entry point, CLI, pipeline orchestration
18+
├── ast/ast.c # AST node creation, manipulation, import inlining
19+
├── parser/
20+
│ ├── lexer.l # Flex lexer
21+
│ └── parser.y # Bison parser
22+
├── semantic/
23+
│ └── semantic.c # Symbol table, scope analysis
24+
├── Typeck/
25+
│ ├── Typeck.cpp # Hindley-Milner type checker
26+
│ ├── TypeckInfer.cpp # C bridge
27+
│ └── LayOut.cpp # Type size/alignment
28+
├── Ownership/
29+
│ └── Ownership.cpp # Ownership & borrow checker
30+
├── compiler/
31+
│ ├── CodeGen.cpp # LLVM IR generation
32+
│ ├── Passes.cpp # LLVM optimization
33+
│ ├── Llc/ # LLVM IR → object
34+
│ └── Linker/ # LLD linking
35+
├── utils/error.c # Error reporting
36+
└── std/ # Standard library
37+
```
38+
39+
## Headers
40+
41+
| File | Purpose |
42+
|------|---------|
43+
| `include/ast.h` | AST node types, TypeInfo |
44+
| `include/codegen.h` | `llvm_emit_from_ast()` |
45+
| `include/compiler.h` | Error reporting API |
46+
| `include/env.h` | TypeEnv class |
47+
| `include/ownership.h` | `ownership_check_program()` |
48+
| `include/semantic.h` | Symbol table API |
49+
| `include/type.h` | Type system (C++ representation) |
50+
| `include/typeck.h` | `typecheck_program()` |
51+
| `include/unify.h` | Unifier engine |
52+
53+
## Build
54+
55+
```bash
56+
cmake -B build -DCMAKE_BUILD_TYPE=Release
57+
cmake --build build --config Release --parallel
58+
```

v0.3.0/en/control-flow.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Control Flow
2+
3+
## if / elif / else
4+
5+
```vix
6+
if (x > 10)
7+
{
8+
print("greater than 10")
9+
} elif (x > 5)
10+
{
11+
print("greater than 5")
12+
} else
13+
{
14+
print("5 or less")
15+
}
16+
```
17+
18+
## while Loop
19+
20+
```vix
21+
let mut i = 0
22+
while (i < 10)
23+
{
24+
print(i)
25+
i += 1
26+
}
27+
```
28+
29+
## for Loop
30+
31+
```vix
32+
for (i in 0 .. 10)
33+
{
34+
print(i) // 0, 1, ..., 9
35+
}
36+
```
37+
38+
## break and continue
39+
40+
```vix
41+
// break
42+
for (i in 0 .. 100)
43+
{
44+
if (i >= 10) { break }
45+
print(i)
46+
}
47+
48+
// continue
49+
for (i in 0 .. 10)
50+
{
51+
if (i % 2 == 0) { continue }
52+
print(i) // odd numbers only
53+
}
54+
```
55+
56+
## Nested Loops
57+
58+
```vix
59+
for (x in 1 .. 3)
60+
{
61+
for (y in 1 .. 3)
62+
{
63+
print(x, y)
64+
}
65+
}
66+
```

v0.3.0/en/function-extern.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Extern Functions
2+
3+
## extern "C" Block
4+
5+
```vix
6+
extern "C"
7+
{
8+
fn printf(format: ptr, ...): i32
9+
fn malloc(size: usize): ptr
10+
fn free(ptr: ptr): void
11+
fn strlen(s: ptr): usize
12+
}
13+
```
14+
15+
## Variadic Functions
16+
17+
```vix
18+
extern "C"
19+
{
20+
fn printf(format: ptr, ...): i32
21+
fn fprintf(file: ptr, format: ptr, ...): i32
22+
}
23+
```
24+
25+
## Calling Extern Functions
26+
27+
```vix
28+
fn main(): i32
29+
{
30+
let msg = "Hello from C!\n"
31+
printf(msg)
32+
return 0
33+
}
34+
```
35+
36+
## Notes
37+
38+
- Extern declarations are registered in the outer scope
39+
- Avoid naming public wrappers the same as extern declarations (causes recursion)
40+
- Use `ptr` for C pointer types in FFI

0 commit comments

Comments
 (0)