Skip to content

Commit 336be9c

Browse files
authored
chore: updated lsp-types & some minimum fixes (#401)
* chore: updated lsp-types & some minimum fixes * feat: basic sort * feat: implement quick sort * fix: some code gen bugs * chore: some clean up * fix: rust toolchain ci
1 parent 2595752 commit 336be9c

File tree

18 files changed

+310
-39
lines changed

18 files changed

+310
-39
lines changed

.github/workflows/bench.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ jobs:
3131
sudo apt-get install libasound2-dev libudev-dev
3232
3333
- name: Install Rust (stable)
34-
uses: dtolnay/rust-toolchain@stable
35-
with:
36-
profile: minimal
37-
override: true
34+
uses: dsherret/rust-toolchain-file@v1
3835

3936
- name: Install LLVM
4037
uses: Pivot-Studio/setup-llvm@main

.github/workflows/npmpkg.yml

+1-5
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,8 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- uses: actions/checkout@v4
19-
- uses: dtolnay/rust-toolchain@stable
19+
- uses: dsherret/rust-toolchain-file@v1
2020
name: Install Rust (stable)
21-
- uses: dtolnay/rust-toolchain@stable
22-
with:
23-
profile: minimal
24-
override: true
2521
- name: install rust
2622
run: cargo install wasm-pack
2723
- name: build wasm

.github/workflows/release.yml

+1-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,7 @@ jobs:
5656
submodules: true
5757

5858
- name: Install Rust (stable)
59-
uses: dtolnay/rust-toolchain@stable
60-
with:
61-
profile: minimal
62-
override: true
59+
uses: dsherret/rust-toolchain-file@v1
6360

6461
- uses: actions/cache@v3
6562
name: Cache Cargo

.github/workflows/test.yml

+4-14
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@ jobs:
4646
sudo apt-get install libasound2-dev libudev-dev
4747
4848
- name: Install Rust (stable)
49-
uses: dtolnay/rust-toolchain@stable
50-
with:
51-
profile: minimal
52-
override: true
49+
uses: dsherret/rust-toolchain-file@v1
5350

5451
- name: Install LLVM
5552
uses: Pivot-Studio/setup-llvm@main
@@ -106,11 +103,7 @@ jobs:
106103
uses: Pivot-Studio/setup-llvm@main
107104

108105
- name: Install toolchain
109-
uses: dtolnay/rust-toolchain@stable
110-
with:
111-
profile: minimal
112-
override: true
113-
components: rustfmt, llvm-tools-preview
106+
uses: dsherret/rust-toolchain-file@v1
114107

115108

116109
- uses: Swatinem/rust-cache@v2
@@ -159,11 +152,8 @@ jobs:
159152
submodules: true
160153

161154
- name: Install stable toolchain
162-
uses: dtolnay/rust-toolchain@stable
163-
with:
164-
profile: minimal
165-
override: true
166-
components: clippy, rustfmt
155+
uses: dsherret/rust-toolchain-file@v1
156+
167157

168158
- uses: Swatinem/rust-cache@v2
169159

Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
name = "pivot-lang"
33
version = "0.1.1"
44
edition = "2021"
5-
rust-version = "1.75.0"
65

76
authors = ["The pivot-lang Authors"]
87

planglib/core/__private.pi

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ use core::hash;
77
use core::eq;
88
use core::coro;
99
use core::process;
10+
use core::ord;
1011
// use core::cols::hashtable;

planglib/core/ord.pi

+201
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
1+
2+
pub trait Ord<T> {
3+
fn cmp(other: T) i64;
4+
}
5+
6+
impl Ord<i64> for i64 {
7+
fn cmp(other: i64) i64 {
8+
if *self < other {
9+
return -1;
10+
} else if *self > other {
11+
return 1;
12+
} else {
13+
return 0;
14+
}
15+
}
16+
}
17+
18+
impl Ord<i32> for i32 {
19+
fn cmp(other: i32) i64 {
20+
if *self < other {
21+
return -1;
22+
} else if *self > other {
23+
return 1;
24+
} else {
25+
return 0;
26+
}
27+
}
28+
}
29+
30+
impl Ord<i16> for i16 {
31+
fn cmp(other: i16) i64 {
32+
if *self < other {
33+
return -1;
34+
} else if *self > other {
35+
return 1;
36+
} else {
37+
return 0;
38+
}
39+
}
40+
}
41+
42+
impl Ord<i8> for i8 {
43+
fn cmp(other: i8) i64 {
44+
if *self < other {
45+
return -1;
46+
} else if *self > other {
47+
return 1;
48+
} else {
49+
return 0;
50+
}
51+
}
52+
}
53+
54+
impl Ord<u64> for u64 {
55+
fn cmp(other: u64) i64 {
56+
if *self < other {
57+
return -1;
58+
} else if *self > other {
59+
return 1;
60+
} else {
61+
return 0;
62+
}
63+
}
64+
}
65+
66+
impl Ord<u32> for u32 {
67+
fn cmp(other: u32) i64 {
68+
if *self < other {
69+
return -1;
70+
} else if *self > other {
71+
return 1;
72+
} else {
73+
return 0;
74+
}
75+
}
76+
}
77+
78+
impl Ord<u16> for u16 {
79+
fn cmp(other: u16) i64 {
80+
if *self < other {
81+
return -1;
82+
} else if *self > other {
83+
return 1;
84+
} else {
85+
return 0;
86+
}
87+
}
88+
}
89+
90+
impl Ord<u8> for u8 {
91+
fn cmp(other: u8) i64 {
92+
if *self < other {
93+
return -1;
94+
} else if *self > other {
95+
return 1;
96+
} else {
97+
return 0;
98+
}
99+
}
100+
}
101+
102+
impl Ord<f64> for f64 {
103+
fn cmp(other: f64) i64 {
104+
if *self < other {
105+
return -1;
106+
} else if *self > other {
107+
return 1;
108+
} else {
109+
return 0;
110+
}
111+
}
112+
}
113+
114+
impl Ord<f32> for f32 {
115+
fn cmp(other: f32) i64 {
116+
if *self < other {
117+
return -1;
118+
} else if *self > other {
119+
return 1;
120+
} else {
121+
return 0;
122+
}
123+
}
124+
}
125+
126+
impl Ord<bool> for bool {
127+
fn cmp(other: bool) i64 {
128+
if *self == other {
129+
return 0;
130+
} else if *self {
131+
return 1;
132+
} else {
133+
return -1;
134+
}
135+
}
136+
}
137+
138+
impl Ord<i128> for i128 {
139+
fn cmp(other: i128) i64 {
140+
if *self < other {
141+
return -1;
142+
} else if *self > other {
143+
return 1;
144+
} else {
145+
return 0;
146+
}
147+
}
148+
}
149+
150+
impl Ord<u128> for u128 {
151+
fn cmp(other: u128) i64 {
152+
if *self < other {
153+
return -1;
154+
} else if *self > other {
155+
return 1;
156+
} else {
157+
return 0;
158+
}
159+
}
160+
}
161+
162+
pub trait Sort {
163+
fn sort() void;
164+
}
165+
166+
impl <T:Ord<T>> Sort for [T] {
167+
fn sort() void {
168+
// quick sort
169+
let arr = *self;
170+
let n = arr_len(arr);
171+
if n <= 1 {
172+
return;
173+
}
174+
let pivot = arr[n / 2];
175+
let i = 0;
176+
let j = n - 1;
177+
while i <= j {
178+
while arr[i].cmp(pivot) < 0 {
179+
i = i + 1;
180+
}
181+
while arr[j].cmp(pivot) > 0 {
182+
j = j - 1;
183+
}
184+
if i <= j {
185+
let tmp = arr[i];
186+
arr[i] = arr[j];
187+
arr[j] = tmp;
188+
i = i + 1;
189+
j = j - 1;
190+
}
191+
}
192+
if j > 0 {
193+
arr_slice(arr, 0, j + 1).sort();
194+
}
195+
if i < n {
196+
arr_slice(arr, i, n-i).sort();
197+
}
198+
return;
199+
}
200+
}
201+

planglib/std/io.pi

+3
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ pub fn open(s:string, flag:i32) File {
3939
return File{fd:LibC__open(s.raw(), s.byte_len(), flag)};
4040
}
4141

42+
/// # File
43+
///
44+
/// a simple wrapper around fd
4245
pub struct File {
4346
fd:i32;
4447
}

rust-toolchain.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[toolchain]
2+
channel = "1.75.0"
3+
components = ["rustfmt", "clippy"]

src/ast/ctx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ impl<'a, 'ctx> Ctx<'a> {
694694
}
695695
if let Some(GlobalVar {
696696
tp: pltype, range, ..
697-
}) = parent.plmod.get_global_symbol(name)
697+
}) = parent.get_root_ctx().plmod.get_global_symbol(name)
698698
{
699699
return builder
700700
.get_global_var_handle(&parent.plmod.get_full_name(name))

src/ast/ctx/lsp.rs

+19-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
use lsp_types::InlayHintKind;
88

99
use lsp_types::InlayHint;
10+
use lsp_types::InlayHintLabelPart;
11+
use lsp_types::MarkupContent;
1012

1113
use super::super::pltype::PLType;
1214

@@ -104,11 +106,24 @@ impl Ctx<'_> {
104106
if self.need_highlight.borrow().ne(&0) || self.in_macro {
105107
return;
106108
}
109+
let colon = InlayHintLabelPart {
110+
value: ": ".to_string(),
111+
..Default::default()
112+
};
113+
let type_label = InlayHintLabelPart {
114+
value: pltype.borrow().get_name(),
115+
tooltip: Some(lsp_types::InlayHintLabelPartTooltip::MarkupContent(
116+
MarkupContent {
117+
kind: lsp_types::MarkupKind::Markdown,
118+
value: pltype.borrow().get_docs().unwrap_or("".to_string()),
119+
},
120+
)),
121+
..Default::default()
122+
};
123+
107124
let hint = InlayHint {
108125
position: range.to_diag_range().end,
109-
label: lsp_types::InlayHintLabel::String(
110-
": ".to_string() + &pltype.borrow().get_name(),
111-
),
126+
label: lsp_types::InlayHintLabel::LabelParts(vec![colon, type_label]),
112127
kind: Some(InlayHintKind::TYPE),
113128
text_edits: None,
114129
tooltip: None,
@@ -124,7 +139,7 @@ impl Ctx<'_> {
124139
}
125140
let hint = InlayHint {
126141
position: range.to_diag_range().start,
127-
label: lsp_types::InlayHintLabel::String(name + ": "),
142+
label: lsp_types::InlayHintLabel::String(name + ":"),
128143
kind: Some(InlayHintKind::TYPE),
129144
text_edits: None,
130145
tooltip: None,

src/ast/node/control.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl Node for WhileNode {
182182
ctx.emit_comment_highlight(&self.comments[0]);
183183
NodeOutput::default()
184184
.with_term(if terminator.is_return() {
185-
TerminatorEnum::Return
185+
terminator
186186
} else {
187187
TerminatorEnum::None
188188
})

0 commit comments

Comments
 (0)