Skip to content

Commit bca43e8

Browse files
committed
feat: update docs
1 parent 464f4c1 commit bca43e8

File tree

9 files changed

+105
-213
lines changed

9 files changed

+105
-213
lines changed

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ on:
1212
- '**/Kagari.*'
1313
- 'codecov.yml'
1414

15+
concurrency:
16+
group: ${{ github.workflow }}-${{ github.ref }}
17+
cancel-in-progress: true
18+
1519
jobs:
1620
artifacts:
1721
name: Artifacts

README.md

Lines changed: 2 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -11,174 +11,5 @@
1111
此项目目前处于早期开发阶段,不建议用于生产环境。
1212
[项目地址](https://github.com/Pivot-Studio/pivot-lang)
1313

14-
## 安装
15-
[此处](https://lang.pivotstudio.cn/tutorial/installation.html)
16-
17-
## 文档地址
18-
https://lang.pivotstudio.cn
19-
20-
## CONTRIBUTING
21-
[CONTRIBUTING](CONTRIBUTING.md)
22-
中文见[此处](https://lang.pivotstudio.cn/CONTRIBUTING-CN.html)
23-
欢迎加入[社区群](https://jq.qq.com/?_wv=1027&k=I5vdShVl)
24-
25-
## dependencies
26-
- [llvm-14](https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.6)
27-
- [rust](https://www.rust-lang.org/)
28-
29-
**重要**:如果你想参与开发,请先在项目目录`make vm install`,然后根据自己是linux还是mac运行`make devlinux`或者`make devmac`
30-
31-
## 特点
32-
- 静态编译(jit模式与immix gc不兼容,因为llvm生成自定义stackmap[目前必需要静态编译](https://llvm.org/docs/GarbageCollection.html#emitting-assembly-code-gcmetadataprinter)
33-
- 极其方便的rust互操作
34-
- 支持debug
35-
- 支持lsp,自带vsc插件,能提供优秀的代码支持
36-
37-
38-
## 项目结构
39-
40-
- [vm](vm) 包含rumtime
41-
- [src](src) 编译器源码所在
42-
- [internal_macro](internal_macro) 内部过程宏
43-
44-
## grammar
45-
46-
```ebnf
47-
add_exp =
48-
| mul_exp ("+" | "-" add_exp)?
49-
;
50-
51-
mul_exp =
52-
| unary_exp ("*"|"/" mul_exp)?
53-
;
54-
55-
unary_exp =
56-
| pointer_exp
57-
| ("-" | "!") pointer_exp
58-
;
59-
60-
61-
pointer_exp = ("&"|"*")* complex_exp;
62-
63-
complex_exp = primary_exp (take_exp_op|array_element_op|call_function_op)*;
64-
65-
take_exp_op = ("." identifier) ;
66-
67-
array_element_op = ('[' logic_exp ']') ;
68-
69-
call_function_op = ("(" (logic_exp (","logic_exp)*)? ")") ;
70-
71-
primary_exp =
72-
| number
73-
| bool_const
74-
| parantheses_exp
75-
| extern_identifier
76-
| struct_init_exp
77-
| string_literal
78-
;
79-
80-
parantheses_exp = "(" logic_exp ")";
81-
82-
number = [0-9]+ ("." number)? ;
83-
84-
identifier = [a-zA-Z_][a-zA-Z0-9_]* ;
85-
86-
extern_identifier = (identifier "::")* identifier ;
87-
88-
bool_const =
89-
| "true"
90-
| "false"
91-
;
92-
93-
compare_exp =
94-
| add_exp (("<=" | "<"|">="|">"|"=="|"!=") add_exp)*
95-
;
96-
97-
logic_exp =
98-
| compare_exp (("&&"|"||") compare_exp)*
99-
;
100-
101-
struct_init_exp =
102-
| type_name "{" (struct_init_exp_field ("," struct_init_exp_field)* )? "}"
103-
;
104-
105-
struct_init_exp_field = identifier ":" logic_exp ;
106-
107-
assignee = pointer_exp;
108-
109-
assignment = assignee "=" logic_exp ;
110-
111-
new_variable = "let" identifier "=" logic_exp ;
112-
113-
global_variable = "const" identifier "=" logic_exp ;
114-
115-
if_statement = "if" logic_exp statement_block ("else" if_statement | statement_block)?;
116-
117-
while_statement = "while" logic_exp statement_block ;
118-
119-
for_statement = "for" (assignment | new_variable) ";" logic_exp ";" assignment statement_block;
120-
121-
statement_block = "{" statements "}" ;
122-
123-
impl_block = "impl" extern_identifier "{" function_def* "}" ;
124-
125-
statements = statement* ;
126-
127-
break_statement = "break" ";" ;
128-
129-
continue_statement = "continue" ";" ;
130-
131-
statement =
132-
| assignment ";"
133-
| new_variable ";"
134-
| return_statement
135-
| if_statement
136-
| while_statement
137-
| break_statement
138-
| continue_statement
139-
| complex_exp ";"
140-
;
141-
142-
toplevel_statement =
143-
| struct_def
144-
| function_def
145-
| global_variable
146-
| use_statement ";"
147-
;
148-
149-
program = toplevel_statement* ;
150-
151-
function_def = "fn" identifier "(" (typed_identifier (","typed_identifier)*)? ")" type_name (statement_block | ";") ;
152-
153-
generic_type = "<" type_name ("|" type_name)* ">" ;
154-
155-
generic_type_def = "<" identifier ("|" identifier)* ">" ;
156-
157-
struct_def = "struct" identifier generic_type_def? "{" struct_field* "}" ;
158-
159-
type_name = "*"* extern_identifier ;
160-
161-
typed_identifier = identifier ":" type_name ;
162-
163-
struct_field = typed_identifier ";" ;
164-
165-
return_statement = "return" logic_exp ";" ;
166-
167-
use_statement = "use" identifier ("::" identifier)* ";" ;
168-
169-
string_literal = "\"" [^"]* "\"" ;
170-
171-
trait_def = "trait" identifier generic_type_def? (":" type_add)? "{" function_def* "}" ;
172-
173-
type_add = type_name ("+" type_name)* ;
174-
175-
macro_match_exp =
176-
| any_exp_except_dollar_and_parantheses
177-
| "$" identifier ":" tp
178-
| "(" macro_match_exp * ")" "*"
179-
| "(" macro_match_exp * ")" "+"
180-
| "(" macro_match_exp * ")"
181-
;
182-
183-
macro_match_arm = "(" macro_match_exp* ")" "=>" statement_block ;
184-
```
14+
## 官网
15+
[https://lang.pivotstudio.cn](https://lang.pivotstudio.cn)

book/src/About.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Pivot Lang
2+
3+
[![codecov](https://codecov.io/gh/Pivot-Studio/pivot-lang/branch/master/graph/badge.svg?token=CA17PWK0EG)](https://codecov.io/gh/Pivot-Studio/pivot-lang)
4+
[![release](https://github.com/Pivot-Studio/pivot-lang/actions/workflows/release.yml/badge.svg)](https://github.com/Pivot-Studio/pivot-lang/actions/workflows/release.yml)
5+
[![test](https://github.com/Pivot-Studio/pivot-lang/actions/workflows/test.yml/badge.svg)](https://github.com/Pivot-Studio/pivot-lang/actions/workflows/test.yml)
6+
7+
8+
![codecov](https://codecov.io/gh/Pivot-Studio/pivot-lang/branch/master/graphs/sunburst.svg?token=CA17PWK0EG)
9+
10+
此项目目前处于早期开发阶段,不建议用于生产环境。
11+
[项目地址](https://github.com/Pivot-Studio/pivot-lang)
12+
13+
## 安装
14+
[此处](https://lang.pivotstudio.cn/docs/tutorial/installation.html)
15+
16+
## 官网
17+
[https://lang.pivotstudio.cn](https://lang.pivotstudio.cn)
18+
19+
## CONTRIBUTING
20+
[CONTRIBUTING](CONTRIBUTING.md)
21+
中文见[此处](https://lang.pivotstudio.cn/CONTRIBUTING-CN.html)
22+
欢迎加入[社区群](https://jq.qq.com/?_wv=1027&k=I5vdShVl)
23+
24+
## dependencies
25+
- [llvm-14](https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.6)
26+
- [rust](https://www.rust-lang.org/)
27+
28+
**重要**:如果你想参与开发,请先在项目目录`make vm install`,然后根据自己是linux还是mac运行`make devlinux`或者`make devmac`
29+
30+
## 特点
31+
- 静态编译 与 ~~比较残废的~~ jit支持
32+
- 极其方便的rust互操作
33+
- 支持debug
34+
- 支持lsp,自带vsc插件,能提供优秀的代码支持
35+
- 有gc,自动管理内存
36+
37+
38+

book/src/SUMMARY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Summary
22

3-
- [About](../../README.md)
3+
- [About](./About.md)
44

55
# Tutorial
66

book/src/tutorial/basicproject.md

Lines changed: 46 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
11
# 基础项目
2+
3+
4+
5+
## 两种编译模型介绍
6+
7+
Pivot Lang存在两种不同的编译方案:
8+
- 静态编译:编译器会将源码编译成一个可执行文件,能给在操作系统上原生运行
9+
- jit编译:编译器会将源码编译成一个字节码文件,然后在运行时使用编译器指令进行解释执行
10+
11+
```admonish warning
12+
目前不建议使用jit模式,因为它与我们新的immix gc的stackmap不兼容,详细情况请看[这里](../references/stackmap.md)
13+
```
14+
15+
目前这两种方案使用的编译器是同一个可执行文件(plc),然而他们在依赖和功能上存在一些差别,
16+
下方是一个简单的对比图:
17+
18+
19+
20+
| | jit | 静态编译 |
21+
| ---------------------------- | --- | -------- |
22+
| 完整的pivot lang功能支持 |||
23+
| 生成可执行文件 |||
24+
| 启动速度 |||
25+
| 依赖预编译的pivot lang系统库 |||
26+
| 运行时优化 |||
27+
| 支持debug |||
28+
| stackmap支持 |||
29+
30+
31+
232
## 项目结构
333

4-
一个最基础的pivot lang项目由一个配置文件和一个源文件组成。配置文件用于指定项目的一些基本信息,源文件用于编写pivot lang代码。其结构如下:
34+
35+
36+
一个最基础的pivot lang项目由一个配置文件和一个源文件组成。
37+
38+
你可以使用`plc new test`来在test 目录下生成他们。
39+
40+
配置文件用于指定项目的一些基本信息,源文件用于编写pivot lang代码。其结构如下:
541

642
```
7-
.
43+
test
844
├── Kagari.toml
945
└── main.pi
1046
```
@@ -24,22 +60,21 @@ entry指定了该项目的入口文件,即编译器将从该文件开始编译
2460
{{#include example/main.pi}}
2561
```
2662
源文件的后缀名必须为`.pi`
27-
在示例中,我们调用了一个系统库重的函数`printi64ln`,该函数用于打印一个i64类型的值并换行。此源代码编译后执行会输出`666`
28-
> 重要:`printi64ln`函数是目前pl runtime中的一个测试用内置函数,此函数可能会在未来移除
63+
在示例中,我们调用了一个系统库重的函数`print_s`,该函数用于打印一个字符串类型的值并换行。此源代码编译后执行会输出`Hello World`
64+
2965

3066
## 编译
31-
如果你已经安装了`plc`,那么你可以在项目根目录下执行`plc main.pi`命令来编译该项目。此指令会生成一个名叫`out.bc`的文件,还有一些中间文件
67+
如果你已经安装了`plc`,那么你可以在项目根目录下执行`plc main.pi`命令来编译该项目。此指令会生成一个名叫`out`的文件,
68+
还有一些中间文件(在target目录下)。
3269

33-
> 如果你配置了静态编译环境,还会生成一个叫做`out`的文件,该文件是一个可执行文件,可以直接运行
34-
> 而如果你只有jit环境,该文件不会生成,并且编译命令会输出一个clang报错和两行warning,这是正常现象
3570

36-
## jit运行
71+
```admonish tip title="如果你想尝试jit模式的话"
72+
编译时带上`--jit`参数,如`plc main.pi --jit`,这样编译出来的文件会带有`bc`后缀,如`out.bc`。
3773
38-
编译后输入`plc run out.bc`可以jit运行该项目,其输出结果如下:
74+
编译后输入`plc run out.bc`可以jit运行该项目
3975
4076
```
41-
666
42-
```
77+
4378

4479

4580

book/src/tutorial/example/main.pi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::io;
22
pub fn main() i64 {
3-
io::printi64ln(666);
3+
io::print_s("Hello, world!\n");
44
return 0;
55
}
66

book/src/tutorial/installation.md

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,5 @@
11
# Installation
22

3-
## 选择你需要的编译模型
4-
5-
Pivot Lang存在两种不同的编译方案:
6-
- 静态编译:编译器会将源码编译成一个可执行文件,能给在操作系统上原生运行
7-
- ~~jit编译:编译器会将源码编译成一个字节码文件,然后在运行时使用编译器指令进行解释执行~~
8-
9-
```admonish warning
10-
目前jit模式暂时不可用,因为它与我们新的immix gc不兼容,详细情况请看[这里](../references/stackmap.md)
11-
```
12-
13-
目前这两种方案使用的编译器是同一个可执行文件(plc),然而他们在依赖和功能上存在一些差别,
14-
下方是一个简单的对比图:
15-
16-
17-
18-
| | jit | 静态编译 |
19-
| ---------------------------- | --- | -------- |
20-
| 完整的pivot lang功能支持 |||
21-
| 生成可执行文件 |||
22-
| 启动速度 |||
23-
| 依赖llvm |||
24-
| 依赖预编译的pivot lang系统库 |||
25-
| 运行时优化 |||
26-
| 支持debug |||
27-
| stackmap支持 |||
28-
29-
可以看出,just in time模式的编译器依赖比静态编译少很多,因此如果你不需要debug功能,建议使用jit模式。如果你想要体验完整功能,建议使用静态编译。
303

314

325
## Windows

book/src/tutorial/vscsupport.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@
33
我们建议开发者使用Visual Studio Code作为开发工具,因为我们提供了丰富的插件支持。
44

55

6+
```admonish note
7+
您可能也注意到了,我们的语言服务器可以被编译成webassembly并直接运行在浏览器中。如果你想只在在浏览器中体验
8+
pivot-lang,可以访问[https://lang.pivotstudio.cn](https://lang.pivotstudio.cn)。
9+
10+
```
11+
612
## vsc插件安装
713
在vsc插件市场搜索`pivot-lang support`,安装第一个即可
814
![](2022-10-23-00-17-08.png)
915

10-
> 注意:pivot-lang support插件依赖于plc命令,你必须确保plc文件安装路径在环境变量`PATH`
16+
17+
```admonish note
18+
pivot-lang support插件依赖于plc命令,你必须确保plc文件安装路径在环境变量`PATH`中
19+
20+
```
21+
1122

1223
## 支持功能
1324
- [x] vsc debug

src/utils/plc_new.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ project = "{}"
4848
path.join("main.pi"),
4949
r#"use std::io;
5050
fn main() i64 {
51-
io::printi64ln(666);
51+
io::print_s("Hello World\n");
5252
return 0;
5353
}
5454
"#

0 commit comments

Comments
 (0)