Skip to content

Commit f230da0

Browse files
committed
feat: colorful help
1 parent 0710108 commit f230da0

File tree

7 files changed

+50
-33
lines changed

7 files changed

+50
-33
lines changed

Cargo.lock

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

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ rowan = "0.15"
2121
dissimilar = "1.0"
2222
stderrlog = "0.5"
2323
log = "0.4"
24-
clap = { version = "4.1", features = ["derive"] }
24+
clap = { version = "4.1", features = ["derive", "unstable-styles"] }
2525
colored = "2.0"
2626
serde = "1.0"
2727
lsp-types = { branch = "master", features = ["proposed"], git = "https://github.com/Pivot-Studio/lsp-types" }
@@ -42,6 +42,7 @@ indicatif = "0.17"
4242
parking_lot = "0.12"
4343
derivative = "2.2"
4444
console = "0.15"
45+
anstyle = "1.0"
4546

4647
[target.'cfg(target_arch = "wasm32")'.dependencies]
4748
wasm-bindgen = "0.2"

immix/benches/immix_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ struct GCTestObj {
9898
d: *mut u64,
9999
e: *mut GCTestObj,
100100
}
101-
fn gctest_vtable(
101+
extern "C" fn gctest_vtable(
102102
ptr: *mut u8,
103103
gc: &Collector,
104104
mark_ptr: VisitFunc,

immix/benches/immix_stress_bench.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct GCTestObj {
5959
d: *mut u64,
6060
e: *mut GCTestObj,
6161
}
62-
fn gctest_vtable(
62+
extern "C" fn gctest_vtable(
6363
ptr: *mut u8,
6464
gc: &Collector,
6565
mark_ptr: VisitFunc,

immix/src/collector.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ struct CollectorStatus {
4747
collecting: bool,
4848
}
4949

50-
pub type VisitFunc = unsafe fn(&Collector, *mut u8);
50+
pub type VisitFunc = unsafe extern "C" fn(&Collector, *mut u8);
5151

52-
pub type VtableFunc = fn(*mut u8, &Collector, VisitFunc, VisitFunc, VisitFunc);
52+
pub type VtableFunc = extern "C" fn(*mut u8, &Collector, VisitFunc, VisitFunc, VisitFunc);
5353

5454
impl Drop for Collector {
5555
fn drop(&mut self) {
@@ -234,7 +234,7 @@ impl Collector {
234234
}
235235

236236
/// precise mark a pointer
237-
unsafe fn mark_ptr(&self, ptr: *mut u8) {
237+
unsafe extern "C" fn mark_ptr(&self, ptr: *mut u8) {
238238
let father = ptr;
239239
let mut ptr = *(ptr as *mut *mut u8);
240240
// println!("mark ptr {:p} -> {:p}", father, ptr);
@@ -330,7 +330,7 @@ impl Collector {
330330
///
331331
/// it self does not mark the object, but mark the object's fields by calling
332332
/// mark_ptr
333-
unsafe fn mark_complex(&self, ptr: *mut u8) {
333+
unsafe extern "C" fn mark_complex(&self, ptr: *mut u8) {
334334
let vptr = *(ptr as *mut *mut u8);
335335
if vptr.is_null() {
336336
return;
@@ -345,7 +345,7 @@ impl Collector {
345345
);
346346
}
347347
/// precise mark a trait object
348-
unsafe fn mark_trait(&self, ptr: *mut u8) {
348+
unsafe extern "C" fn mark_trait(&self, ptr: *mut u8) {
349349
// if !self.thread_local_allocator.as_mut().unwrap().in_heap(ptr)
350350
// &&!self.thread_local_allocator.as_mut().unwrap().in_big_heap(ptr) {
351351
// return;
@@ -644,7 +644,7 @@ mod tests {
644644
d: *mut u64,
645645
e: *mut GCTestObj,
646646
}
647-
fn gctest_vtable(
647+
extern "C" fn gctest_vtable(
648648
ptr: *mut u8,
649649
gc: &Collector,
650650
mark_ptr: VisitFunc,
@@ -667,7 +667,7 @@ mod tests {
667667
d: *mut GCTestBigObj,
668668
}
669669
const BIGOBJ_ALLOC_SIZE: usize = round_n_up!(size_of::<GCTestBigObj>() + 16, 128);
670-
fn gctest_vtable_big(
670+
extern "C" fn gctest_vtable_big(
671671
ptr: *mut u8,
672672
gc: &Collector,
673673
mark_ptr: VisitFunc,

src/ast/builder/llvmbuilder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ impl<'a, 'ctx> LLVMBuilder<'a, 'ctx> {
310310
let stack_ptr = self
311311
.builder
312312
.build_alloca(llvmtp.ptr_type(AddressSpace::default()), "stack_ptr");
313+
self.gc_add_root(stack_ptr.as_basic_value_enum(), obj_type);
313314
self.builder.position_at_end(lb);
314315
self.builder.build_store(stack_ptr, casted_result);
315-
self.gc_add_root(stack_ptr.as_basic_value_enum(), obj_type);
316316
(casted_result.into_pointer_value(), stack_ptr, llvmtp)
317317
}
318318

src/main.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ _______ __ __ __
4141
| \__| $$
4242
\$$ $$
4343
\$$$$$$
44-
"#, long_about = None)]
44+
"#, long_about = None, styles = get_styles())]
4545
struct Cli {
4646
/// Name of the source file
4747
#[arg(value_parser)]
@@ -200,3 +200,18 @@ fn main() {
200200
Cli::command().print_help().unwrap();
201201
}
202202
}
203+
204+
pub fn get_styles() -> clap::builder::Styles {
205+
clap::builder::Styles::styled()
206+
.header(
207+
anstyle::Style::new()
208+
.bold()
209+
.underline()
210+
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::Green))),
211+
)
212+
.literal(
213+
anstyle::Style::new()
214+
.bold()
215+
.fg_color(Some(anstyle::Color::Ansi(anstyle::AnsiColor::BrightGreen))),
216+
)
217+
}

0 commit comments

Comments
 (0)