Skip to content

Commit 68cfaee

Browse files
committed
fix: debug generation
1 parent c11639a commit 68cfaee

File tree

8 files changed

+118
-36
lines changed

8 files changed

+118
-36
lines changed

Cargo.lock

Lines changed: 43 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
## 特点
3434

3535
- 支持静态编译与JIT
36+
- [高性能](./book/src/performance.md)
3637
- REPL
3738
- 热重载
38-
- 极其方便的Rust互操作
39+
- 极其方便的Rust/C互操作
3940
- 支持debug
4041
- 支持lsp,自带[vsc插件](https://github.com/Pivot-Studio/pivot-lang-support),能提供优秀的代码支持
4142
- 有GC,自动管理内存

book/src/About.md

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,42 @@
1919

2020
## CONTRIBUTING
2121

22-
中文见[此处](./CONTRIBUTING-CN.md)
23-
欢迎加入[qq群](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=vjKI1nbRHAIz1UbmDOjttLurEw93mLhA&authKey=U6cUmnIxiptTskr9trZZ9vc2p291uWht8TlzPSOEPXliihLC9vAYMaRwDI0%2FolR8&noverify=0&group_code=688301255)
22+
[CONTRIBUTING](CONTRIBUTING.md)[贡献代码](https://pivotlang.tech/docs/CONTRIBUTING-CN.html)
23+
24+
欢迎加入: [QQ群](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=nlRLeRcRfr0SxXcLYsjsXobP6X7EeV_c&authKey=rdyEXtc0uMqjYS4i%2FJapoi7CUdwtKgtK5V8Xv0WKgIIb9n4ZkFaIo9mgkflqV%2Frf&noverify=0&group_code=688301255) [discord](https://discord.gg/ZYNhYu6sW9)
2425

2526
## dependencies
2627

27-
- [llvm-18](https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.2)
28-
- [rust](https://www.rust-lang.org/)
28+
- [LLVM-18](https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.5)
29+
- [Rust](https://www.rust-lang.org/)
2930

3031
**重要**:如果你想参与开发,请先在项目目录`make vm install`,然后根据自己是linux还是mac运行`make devlinux`或者`make devmac`
3132

3233
## 特点
3334

3435
- 支持静态编译与JIT
36+
- [高性能](./performance.md)
3537
- REPL
3638
- 热重载
37-
- 极其方便的Rust互操作
39+
- 极其方便的Rust/C互操作
3840
- 支持debug
3941
- 支持lsp,自带[vsc插件](https://github.com/Pivot-Studio/pivot-lang-support),能提供优秀的代码支持
4042
- 有GC,自动管理内存
4143
- 强大的类型推断,支持省略大部分类型标注
4244

43-
## 一些ShowCase
45+
## 一些ShowCases
46+
47+
### [Ray Tracing in One Weekend in Pivot Lang](https://github.com/Pivot-Studio/rtweekend-pl)
48+
49+
使用Pivot Lang实现的简单光追
50+
51+
![example](imgs/2024-02-21-11-46-55.png)
52+
53+
### 编辑器支持
54+
55+
![debug](imgs/2024-02-21-11-50-11.png)
56+
57+
![lsp](imgs/2024-02-21-11-50-25.png)
4458

4559
### Hello World
4660

@@ -61,7 +75,7 @@ use core::panic::assert;
6175
use core::eq::*;
6276
6377
fn main() i64 {
64-
let table = hashtable::new_hash_table<string|string>(10 as u64, 1 as u64);
78+
let table = hashtable::new_hash_table(10 as u64, 1 as u64);
6579
table.insert("hello","world");
6680
table.insert("bye","bye");
6781
assert(table.get("hello") is string);
@@ -101,7 +115,7 @@ fn fib(n: i64) i64 {
101115
```pivot
102116
use core::panic;
103117
pub fn main() i64 {
104-
let g = |f: |i64| => i64, x: i64| => i64 {
118+
let g = |f, x| => {
105119
if x == 0 {
106120
return 1;
107121
}
@@ -114,6 +128,7 @@ pub fn main() i64 {
114128
return 0;
115129
}
116130
131+
117132
struct Func<A|F> {
118133
f: |Func<A|F>, A| => F;
119134
}
@@ -126,19 +141,17 @@ impl<A|F> Func<A|F> {
126141
}
127142
128143
fn Y<A|R>(g: ||A| => R, A| => R) |A| => R {
129-
return |x: A| => R {
130-
let in = |f: Func<A|R>, x: A| => R {
144+
// 下方代码的类型推断是一个很好的例子
145+
return |x| => {
146+
return |f, x| => {
131147
return f.call(f, x);
132-
};
133-
let field = |f: Func<A|R>, x: A| => R {
134-
return g(|x: A| => R {
135-
return f.call(f, x);
136-
}, x);
137-
};
138-
let f = Func{
139-
f: field
140-
};
141-
return in(f, x);
148+
}(Func{
149+
f: |f, x| => {
150+
return g(|x| => {
151+
return f.call(f, x);
152+
}, x);
153+
}
154+
}, x);
142155
};
143156
}
144157
@@ -150,5 +163,4 @@ fn fact_recursion(x: i64) i64 {
150163
}
151164
152165
153-
154166
```

book/src/SUMMARY.md

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

33
- [About](./About.md)
4+
- [Performance](./performance.md)
45

56
## Tutorial
67

@@ -13,7 +14,7 @@
1314
- [Operator](./references/operator/README.md)
1415
- [Type Operator](./references/operator/tyops.md)
1516
- [Array](./references/array.md)
16-
- [closure](./references/closure.md)
17+
- [Closure](./references/closure.md)
1718
- [Module](./references/module.md)
1819
- [Method](./references/method.md)
1920
- [Trait](./references/interface.md)

book/src/performance.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Performance
2+
3+
实验证明在经过我们的数次性能优化之后,Pivot Lang的性能已经在很多场景下超越Golang。优化之后的Immix GC在内存分配和回收上的性能也有了很大的提升,能够
4+
在大部分场景下击败别的GC算法。
5+
6+
## GC Benchmark
7+
8+
我们使用知名的`BdwGC`的benchmark代码进行了测试,将Pivot Lang版本与Golang版本以及BdwGC原版进行了对比。
9+
10+
源代码以及结果见:[Pivot Lang GC Benchmark](https://github.com/Chronostasys/gcbench)
11+
12+
## RealLife application performance
13+
14+
我们使用Pivot Lang实现了有名的[ray tracing in one weekend](https://github.com/Pivot-Studio/rtweekend-pl)项目,
15+
渲染速度相比于[golang实现](https://github.com/hunterloftis/oneweekend)有明显性能优势。
16+
17+
> 请注意golang的实现代码中的参数与原书不完全一样,测试是在调整成一样的参数之后进行的。

src/ast/compiler.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,25 @@ pub fn process_llvm_ir<'a>(
220220
let tm = crate::ast::builder::llvmbuilder::get_target_machine(op.optimization.to_llvm());
221221
let llvmmod = ctx.create_module("main");
222222
let m = get_alloc_module(ctx, op);
223+
if op.debug {
224+
let o = PathBuf::from(format!(
225+
"{}/{}",
226+
&ASSET_PATH.lock().unwrap(),
227+
"alloc_fast.o"
228+
));
229+
unsafe {
230+
immix::run_module_pass(
231+
m.as_mut_ptr() as _,
232+
op.optimization as _,
233+
op.debug as _,
234+
op.print_escape as _,
235+
);
236+
}
237+
// if debug, generate one obj file per file, or debug info will be lost
238+
tm.write_to_file(&m, inkwell::targets::FileType::Object, &o)
239+
.unwrap();
240+
output_files.push(o);
241+
}
223242
llvmmod.link_in_module(m).unwrap();
224243
for m in mods {
225244
let m = m.0;

src/ast/node/function.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,6 +1040,7 @@ impl FuncDefNode {
10401040
});
10411041
builder.set_di_file(&ctx.get_file());
10421042
builder.position_at_end_block(bb);
1043+
builder.rm_curr_debug_location();
10431044
// builder.try_set_fn_dbg(self.range.start, ctx.function.unwrap());
10441045
re
10451046
}

0 commit comments

Comments
 (0)