From 00000639991ab325036dfc2ce8e11b798fcb85fe Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:08:59 +0200 Subject: [PATCH 01/18] feat: started new cli --- Cargo.lock | 127 ++++++++++++++++++++++ compiler/compiler_main/Cargo.toml | 1 + compiler/compiler_main/src/cli.rs | 28 +++++ compiler/compiler_main/src/cmds/astoir.rs | 86 --------------- compiler/compiler_main/src/cmds/mod.rs | 1 - compiler/compiler_main/src/main.rs | 24 +--- 6 files changed, 160 insertions(+), 107 deletions(-) create mode 100644 compiler/compiler_main/src/cli.rs delete mode 100644 compiler/compiler_main/src/cmds/astoir.rs delete mode 100644 compiler/compiler_main/src/cmds/mod.rs diff --git a/Cargo.lock b/Cargo.lock index 7a22001e..12e7acde 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,56 @@ # It is not intended for manual editing. version = 4 +[[package]] +name = "anstream" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is_terminal_polyfill", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" + +[[package]] +name = "anstyle-parse" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "3.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" +dependencies = [ + "anstyle", + "once_cell_polyfill", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.102" @@ -110,6 +160,52 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "clap" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ddb117e43bbf7dacf0a4190fef4d345b9bad68dfc649cb349e7d17d28428e51" +dependencies = [ + "clap_builder", + "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "714a53001bf66416adb0e2ef5ac857140e7dc3a0c48fb28b2f10762fc4b5069f" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2ce8604710f6733aa641a2b3731eaa1e8b3d9973d5e3565da11800813f997a9" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9" + +[[package]] +name = "colorchoice" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" + [[package]] name = "colored" version = "3.1.1" @@ -133,6 +229,7 @@ dependencies = [ "ast", "ast_parser", "astoir", + "clap", "compiler_utils", "diagnostics", "lexer", @@ -177,6 +274,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "inkwell" version = "0.8.0" @@ -199,6 +302,12 @@ dependencies = [ "syn", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + [[package]] name = "lazy_static" version = "1.5.0" @@ -243,6 +352,12 @@ dependencies = [ "rand", ] +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -329,6 +444,12 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "syn" version = "2.0.117" @@ -366,6 +487,12 @@ version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + [[package]] name = "wasi" version = "0.11.1+wasi-snapshot-preview1" diff --git a/compiler/compiler_main/Cargo.toml b/compiler/compiler_main/Cargo.toml index 6a2ddc34..4122199a 100644 --- a/compiler/compiler_main/Cargo.toml +++ b/compiler/compiler_main/Cargo.toml @@ -11,6 +11,7 @@ lexer = { path = "../lexer" } llvm_ir_bridge = { path = "../llvm_ir_bridge", optional = true, default-features = false } diagnostics = { path = "../diagnostics" } compiler_utils = { path = "../compiler_utils" } +clap = { version = "4.0", features = ["derive"] } [features] llvm = ["llvm_ir_bridge"] diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs new file mode 100644 index 00000000..a6b68681 --- /dev/null +++ b/compiler/compiler_main/src/cli.rs @@ -0,0 +1,28 @@ +use clap::{Parser, Subcommand, ValueEnum}; + +#[derive(Parser)] +pub struct Cli { + #[command(subcommand)] + pub command: CLICommand, +} + +#[derive(Clone, Copy, PartialEq, Eq, ValueEnum, Debug)] +pub enum Platform { + AstoIR, + LLVM, +} + +#[derive(Subcommand)] +pub enum CLICommand { + #[command(visible_alias = "b")] + Build { + #[arg(short = 'o')] + out: String, + + #[arg(long, value_enum, default_value = "llvm")] + platform: Platform, + + #[arg(required = true)] + input: Vec, + }, +} diff --git a/compiler/compiler_main/src/cmds/astoir.rs b/compiler/compiler_main/src/cmds/astoir.rs deleted file mode 100644 index 3600ee30..00000000 --- a/compiler/compiler_main/src/cmds/astoir.rs +++ /dev/null @@ -1,86 +0,0 @@ -use std::fs; - -use ast_parser::parse_ast_ctx; -use astoir::{IRLevel, run_astoir_hir, run_astoir_mir}; -use diagnostics::{DiagnosticResult, dump_diagnostics}; -use lexer::lexer::lexer_parse_file; - -use std::process::exit; - -#[cfg(feature = "llvm_ir_bridge")] -use llvm_ir_bridge::bridge_llvm; - -pub fn parse_astoir_command(arguments: Vec) { - if arguments.len() <= 2 { - println!("quickfall astoir paths..."); - return; - } - - let level = match parse_astoir_level(&arguments[2]) { - Ok(v) => v, - Err(_) => return, - }; - - for i in 3..arguments.len() { - let lexer = lexer_parse_file(&arguments[i]).unwrap(); - let ast = parse_ast_ctx(&lexer); - - dump_diagnostics(); - - match level { - IRLevel::HIR => { - let ctx = run_astoir_hir(ast.unwrap()); - let res_path = arguments[i].clone() + ".qfhir"; - - dump_diagnostics(); - - fs::write(res_path, format!("{:#?}", ctx.unwrap())).unwrap() - } - - IRLevel::MIR => { - let ctx = run_astoir_mir(ast.unwrap()); - let res_path = arguments[i].clone() + ".qfmir"; - - dump_diagnostics(); - - let _ = fs::write(res_path, format!("{}", ctx.unwrap())); - } - - IRLevel::LLVM => { - #[cfg(feature = "llvm_ir_bridge")] - { - let ctx = run_astoir_mir(ast.unwrap()); - let res_path = arguments[i].clone() + ".llvm"; - - dump_diagnostics(); - - let ctx = bridge_llvm(&ctx.unwrap()); - - dump_diagnostics(); - - let _ = ctx.module.print_to_file(res_path); - } - - #[cfg(not(feature = "llvm_ir_bridge"))] - { - println!("LLVM target is not bundled!"); - - exit(0); - } - } - } - } -} - -fn parse_astoir_level(str: &String) -> DiagnosticResult { - match str as &str { - "hir" | "HIR" | "h" | "H" => return Ok(IRLevel::HIR), - "mir" | "MIR" | "m" | "M" => return Ok(IRLevel::MIR), - "llvm" | "LLVM" => return Ok(IRLevel::LLVM), - - _ => { - println!("Invalid level"); - exit(0); - } - }; -} diff --git a/compiler/compiler_main/src/cmds/mod.rs b/compiler/compiler_main/src/cmds/mod.rs deleted file mode 100644 index 64e781c6..00000000 --- a/compiler/compiler_main/src/cmds/mod.rs +++ /dev/null @@ -1 +0,0 @@ -pub mod astoir; diff --git a/compiler/compiler_main/src/main.rs b/compiler/compiler_main/src/main.rs index 0ba93868..30237354 100644 --- a/compiler/compiler_main/src/main.rs +++ b/compiler/compiler_main/src/main.rs @@ -1,25 +1,9 @@ -use std::env; +use clap::Parser; -use crate::cmds::astoir::parse_astoir_command; +use crate::cli::{CLICommand, Cli}; -pub mod cmds; +pub mod cli; fn main() { - let arguments: Vec = env::args().collect(); - - if arguments.len() <= 1 { - println!("Usage: quickfall comp|astoir"); - return; - } - - match &arguments[1] as &str { - "astoir" => { - parse_astoir_command(arguments); - } - - _ => { - println!("Invalid subcommand!"); - return; - } - } + let cli = Cli::parse(); } From 2ebccbcc0508837618417cf8fbf58cd56c5e881f Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:18:46 +0200 Subject: [PATCH 02/18] feat: added more arguments and a check command --- compiler/compiler_main/src/cli.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs index a6b68681..bbb89a7c 100644 --- a/compiler/compiler_main/src/cli.rs +++ b/compiler/compiler_main/src/cli.rs @@ -12,9 +12,15 @@ pub enum Platform { LLVM, } +#[derive(Clone, Copy, PartialEq, Eq, ValueEnum, Debug)] +pub enum IRLayer { + HIR, + MIR, +} + #[derive(Subcommand)] pub enum CLICommand { - #[command(visible_alias = "b")] + #[command(visible_alias = "b", about = "Builds the given file(s)")] Build { #[arg(short = 'o')] out: String, @@ -22,7 +28,22 @@ pub enum CLICommand { #[arg(long, value_enum, default_value = "llvm")] platform: Platform, + #[arg(short = 'l', default_value = "ld")] + linker: String, + + #[arg(required = true)] + input: Vec, + }, + + #[command(visible_alias = "ver", about = "Displays the version")] + Version, + + #[command(about = "Checks if a file is valid")] + Check { #[arg(required = true)] input: Vec, + + #[arg(long, value_enum, default_value = "mir")] + layer: IRLayer, }, } From 9b09b424b2479d823adc1a8dc3865015cfa8cd10 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:23:24 +0200 Subject: [PATCH 03/18] feat: added format argument --- compiler/compiler_main/src/cli.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs index bbb89a7c..1311b8cf 100644 --- a/compiler/compiler_main/src/cli.rs +++ b/compiler/compiler_main/src/cli.rs @@ -18,6 +18,17 @@ pub enum IRLayer { MIR, } +#[derive(Clone, Copy, PartialEq, Eq, ValueEnum, Debug)] +pub enum OutputFormat { + #[value(alias = "exec")] + Executable, + + #[value(alias = "o")] + Object, + + IR, +} + #[derive(Subcommand)] pub enum CLICommand { #[command(visible_alias = "b", about = "Builds the given file(s)")] @@ -28,6 +39,9 @@ pub enum CLICommand { #[arg(long, value_enum, default_value = "llvm")] platform: Platform, + #[arg(short = 't', value_enum, long, default_value = "o")] + format: OutputFormat, + #[arg(short = 'l', default_value = "ld")] linker: String, From c2bab051cb67accb33f56acdaabb52a79f8b1dcb Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:26:57 +0200 Subject: [PATCH 04/18] feat: added version display --- compiler/compiler_main/build.rs | 12 ++++++++++++ compiler/compiler_main/src/main.rs | 14 +++++++++++++- compiler/compiler_main/src/version.rs | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 compiler/compiler_main/build.rs create mode 100644 compiler/compiler_main/src/version.rs diff --git a/compiler/compiler_main/build.rs b/compiler/compiler_main/build.rs new file mode 100644 index 00000000..cb884c6b --- /dev/null +++ b/compiler/compiler_main/build.rs @@ -0,0 +1,12 @@ +use std::process::Command; + +fn main() { + let out = Command::new("git") + .args(["rev-parse", "HEAD"]) + .output() + .unwrap(); + + let git_hash = String::from_utf8(out.stdout).unwrap(); + + println!("cargo:rustc-env=GIT_HASH={}", git_hash.trim()); +} diff --git a/compiler/compiler_main/src/main.rs b/compiler/compiler_main/src/main.rs index 30237354..50a13f84 100644 --- a/compiler/compiler_main/src/main.rs +++ b/compiler/compiler_main/src/main.rs @@ -1,9 +1,21 @@ use clap::Parser; -use crate::cli::{CLICommand, Cli}; +use crate::{ + cli::{CLICommand, Cli}, + version::{GIT_HASH, VERSION}, +}; pub mod cli; +pub mod version; fn main() { let cli = Cli::parse(); + + match cli.command { + CLICommand::Version => { + println!("Quickfall v{} (commit {})", VERSION, GIT_HASH); + } + + _ => todo!(), + } } diff --git a/compiler/compiler_main/src/version.rs b/compiler/compiler_main/src/version.rs new file mode 100644 index 00000000..ca1b45fd --- /dev/null +++ b/compiler/compiler_main/src/version.rs @@ -0,0 +1,2 @@ +pub const GIT_HASH: &str = env!("GIT_HASH"); +pub const VERSION: &str = env!("CARGO_PKG_VERSION"); From 932041ff831c835a2d2b539e9dd1784efcdf09fd Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:45:53 +0200 Subject: [PATCH 05/18] feat: added check subcommand --- compiler/compiler_main/src/cmds/check.rs | 25 ++++++++++++++++++++++++ compiler/compiler_main/src/cmds/mod.rs | 11 +++++++++++ compiler/compiler_main/src/main.rs | 19 ++++++++++++++++++ compiler/diagnostics/src/lib.rs | 4 ++++ 4 files changed, 59 insertions(+) create mode 100644 compiler/compiler_main/src/cmds/check.rs create mode 100644 compiler/compiler_main/src/cmds/mod.rs diff --git a/compiler/compiler_main/src/cmds/check.rs b/compiler/compiler_main/src/cmds/check.rs new file mode 100644 index 00000000..b34aef36 --- /dev/null +++ b/compiler/compiler_main/src/cmds/check.rs @@ -0,0 +1,25 @@ +use ast_parser::parse_ast_ctx; +use astoir::{run_astoir_hir, run_astoir_mir}; +use lexer::lexer::lexer_parse_file; + +use crate::{cli::IRLayer, quietlyquit_if_errors}; + +pub fn run_check(path: String, layer: IRLayer) { + let lexer = lexer_parse_file(&path); + quietlyquit_if_errors!(); + + let ast = parse_ast_ctx(&lexer.unwrap()); + quietlyquit_if_errors!(); + + match layer { + IRLayer::HIR => { + let hir = run_astoir_hir(ast.unwrap()); + quietlyquit_if_errors!(); + } + + IRLayer::MIR => { + let mir = run_astoir_mir(ast.unwrap()); + quietlyquit_if_errors!(); + } + } +} diff --git a/compiler/compiler_main/src/cmds/mod.rs b/compiler/compiler_main/src/cmds/mod.rs new file mode 100644 index 00000000..65a2a0cb --- /dev/null +++ b/compiler/compiler_main/src/cmds/mod.rs @@ -0,0 +1,11 @@ +pub mod check; + +#[macro_export] +macro_rules! quietlyquit_if_errors { + () => { + if (diagnostics::has_diagnostics()) { + diagnostics::dump_diagnostics(); + std::process::exit(445); + } + }; +} diff --git a/compiler/compiler_main/src/main.rs b/compiler/compiler_main/src/main.rs index 50a13f84..471623e6 100644 --- a/compiler/compiler_main/src/main.rs +++ b/compiler/compiler_main/src/main.rs @@ -1,11 +1,15 @@ +use std::time::Instant; + use clap::Parser; use crate::{ cli::{CLICommand, Cli}, + cmds::check::run_check, version::{GIT_HASH, VERSION}, }; pub mod cli; +pub mod cmds; pub mod version; fn main() { @@ -16,6 +20,21 @@ fn main() { println!("Quickfall v{} (commit {})", VERSION, GIT_HASH); } + CLICommand::Check { input, layer } => { + let start = Instant::now(); + let count = input.len(); + + for file in input { + run_check(file, layer); + } + + println!( + "No problems could be found in the {} provided files! Checked in {:?}", + count, + start.elapsed() + ) + } + _ => todo!(), } } diff --git a/compiler/diagnostics/src/lib.rs b/compiler/diagnostics/src/lib.rs index 994c6bab..90114d0d 100644 --- a/compiler/diagnostics/src/lib.rs +++ b/compiler/diagnostics/src/lib.rs @@ -70,6 +70,10 @@ pub fn dump_diagnostics() { }) } +pub fn has_diagnostics() -> bool { + DIAGNOSTIC_CONTAINER.with_borrow(|f| return !f.diagnostics.is_empty()) +} + pub fn move_current_diagnostic_pos(pos: SpanPosition) { CURR_DIAGNOSTIC_POS.with_borrow_mut(|f| { *f = Some(pos); From 8e25cee0637e55271acdd5d7756570d5558c45de Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 15:11:00 +0200 Subject: [PATCH 06/18] feat: added AstoIR build target --- compiler/compiler_main/src/cli.rs | 6 ++- compiler/compiler_main/src/cmds/build.rs | 20 ++++++++++ compiler/compiler_main/src/cmds/mod.rs | 9 +++++ compiler/compiler_main/src/main.rs | 50 ++++++++++++++++++++++-- 4 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 compiler/compiler_main/src/cmds/build.rs diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs index 1311b8cf..d1054531 100644 --- a/compiler/compiler_main/src/cli.rs +++ b/compiler/compiler_main/src/cli.rs @@ -1,3 +1,5 @@ +use std::path::{Path, PathBuf}; + use clap::{Parser, Subcommand, ValueEnum}; #[derive(Parser)] @@ -34,7 +36,7 @@ pub enum CLICommand { #[command(visible_alias = "b", about = "Builds the given file(s)")] Build { #[arg(short = 'o')] - out: String, + out: PathBuf, #[arg(long, value_enum, default_value = "llvm")] platform: Platform, @@ -46,7 +48,7 @@ pub enum CLICommand { linker: String, #[arg(required = true)] - input: Vec, + input: Vec, }, #[command(visible_alias = "ver", about = "Displays the version")] diff --git a/compiler/compiler_main/src/cmds/build.rs b/compiler/compiler_main/src/cmds/build.rs new file mode 100644 index 00000000..c6a238c3 --- /dev/null +++ b/compiler/compiler_main/src/cmds/build.rs @@ -0,0 +1,20 @@ +use std::{fs, path::PathBuf}; + +use ast_parser::parse_ast_ctx; +use astoir::run_astoir_mir; +use lexer::lexer::lexer_parse_file; + +use crate::quietlyquit_if_errors; + +pub fn build_mir(path: String, out: PathBuf) { + let lexer = lexer_parse_file(&path); + quietlyquit_if_errors!(); + + let ast = parse_ast_ctx(&lexer.unwrap()); + quietlyquit_if_errors!(); + + let mir = run_astoir_mir(ast.unwrap()); + quietlyquit_if_errors!(); + + fs::write(out, format!("{}", mir.unwrap())).unwrap(); +} diff --git a/compiler/compiler_main/src/cmds/mod.rs b/compiler/compiler_main/src/cmds/mod.rs index 65a2a0cb..63299823 100644 --- a/compiler/compiler_main/src/cmds/mod.rs +++ b/compiler/compiler_main/src/cmds/mod.rs @@ -1,3 +1,4 @@ +pub mod build; pub mod check; #[macro_export] @@ -9,3 +10,11 @@ macro_rules! quietlyquit_if_errors { } }; } + +#[macro_export] +macro_rules! soft_panic { + ($lit:literal) => { + println!($lit); + std::process::exit(445) + }; +} diff --git a/compiler/compiler_main/src/main.rs b/compiler/compiler_main/src/main.rs index 471623e6..969d31a2 100644 --- a/compiler/compiler_main/src/main.rs +++ b/compiler/compiler_main/src/main.rs @@ -1,10 +1,15 @@ -use std::time::Instant; +use std::{ + fs, + path::{Path, PathBuf}, + process::Output, + time::Instant, +}; use clap::Parser; use crate::{ - cli::{CLICommand, Cli}, - cmds::check::run_check, + cli::{CLICommand, Cli, OutputFormat, Platform}, + cmds::{build::build_mir, check::run_check}, version::{GIT_HASH, VERSION}, }; @@ -35,6 +40,45 @@ fn main() { ) } + CLICommand::Build { + out, + platform, + format, + linker, + input, + } => { + let needs_dir = input.len() > 1 && format != OutputFormat::Executable; + + if input.len() > 1 && out.extension().is_some() && format != OutputFormat::Executable { + soft_panic!( + "Output must be a directory if theres more than one input and that the target isn't an executable" + ); + } + + if needs_dir && !out.exists() { + fs::create_dir_all(out.clone()).unwrap(); + } + + if platform == Platform::AstoIR && format != OutputFormat::IR { + soft_panic!("Only IR target is supported by AstoIR platform!"); + } + + match platform { + Platform::AstoIR => { + for i in input { + let mut outfile = PathBuf::from(i.file_name().unwrap()); + outfile.add_extension("air"); + + let output_path = out.join(outfile); + + build_mir(i.to_str().unwrap().to_string(), output_path); + } + } + + _ => todo!(), + } + } + _ => todo!(), } } From 813d555194559a83131eda2bc80f97b06898ca95 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 15:13:18 +0200 Subject: [PATCH 07/18] feat: renamed platform -> bridge --- compiler/compiler_main/src/cli.rs | 6 +++--- compiler/compiler_main/src/main.rs | 11 +++++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs index d1054531..f1d358d7 100644 --- a/compiler/compiler_main/src/cli.rs +++ b/compiler/compiler_main/src/cli.rs @@ -9,7 +9,7 @@ pub struct Cli { } #[derive(Clone, Copy, PartialEq, Eq, ValueEnum, Debug)] -pub enum Platform { +pub enum Bridge { AstoIR, LLVM, } @@ -38,8 +38,8 @@ pub enum CLICommand { #[arg(short = 'o')] out: PathBuf, - #[arg(long, value_enum, default_value = "llvm")] - platform: Platform, + #[arg(long, value_enum, default_value = "llvm", short = 'b')] + bridge: Bridge, #[arg(short = 't', value_enum, long, default_value = "o")] format: OutputFormat, diff --git a/compiler/compiler_main/src/main.rs b/compiler/compiler_main/src/main.rs index 969d31a2..82f35313 100644 --- a/compiler/compiler_main/src/main.rs +++ b/compiler/compiler_main/src/main.rs @@ -1,14 +1,13 @@ use std::{ fs, path::{Path, PathBuf}, - process::Output, time::Instant, }; use clap::Parser; use crate::{ - cli::{CLICommand, Cli, OutputFormat, Platform}, + cli::{Bridge, CLICommand, Cli, OutputFormat}, cmds::{build::build_mir, check::run_check}, version::{GIT_HASH, VERSION}, }; @@ -42,7 +41,7 @@ fn main() { CLICommand::Build { out, - platform, + bridge, format, linker, input, @@ -59,12 +58,12 @@ fn main() { fs::create_dir_all(out.clone()).unwrap(); } - if platform == Platform::AstoIR && format != OutputFormat::IR { + if bridge == Bridge::AstoIR && format != OutputFormat::IR { soft_panic!("Only IR target is supported by AstoIR platform!"); } - match platform { - Platform::AstoIR => { + match bridge { + Bridge::AstoIR => { for i in input { let mut outfile = PathBuf::from(i.file_name().unwrap()); outfile.add_extension("air"); From 2c015a221c8d9a1c19366ca415ae12ca2d62860d Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 21:20:16 +0200 Subject: [PATCH 08/18] feat: added language server check --- compiler/compiler_main/src/cli.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs index f1d358d7..a6378d1f 100644 --- a/compiler/compiler_main/src/cli.rs +++ b/compiler/compiler_main/src/cli.rs @@ -62,4 +62,10 @@ pub enum CLICommand { #[arg(long, value_enum, default_value = "mir")] layer: IRLayer, }, + + #[command(about = "Runs language server analysis", visible_alias = "lscheck")] + LanguageServerCheck { + #[arg(required = true)] + input: PathBuf, + }, } From 20f8ec0b04468319989e10e94452adaea4458fed Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 22:01:03 +0200 Subject: [PATCH 09/18] chore: started working on LSP --- Cargo.lock | 767 ++++++++++++++++++++++++++++++++++++++++++++++++- Cargo.toml | 18 +- lsp/Cargo.toml | 8 + 3 files changed, 791 insertions(+), 2 deletions(-) create mode 100644 lsp/Cargo.toml diff --git a/Cargo.lock b/Cargo.lock index 12e7acde..26889b79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -138,12 +138,46 @@ dependencies = [ "diagnostics", ] +[[package]] +name = "async-trait" +version = "0.1.89" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9035ad2d096bed7955a320ee7e2230574d28fd3c3a0f186cbea1ff3c7eed5dbb" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "auto_impl" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffdcb70bdbc4d478427380519163274ac86e52916e10f0a8889adf0f96d3fee7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + [[package]] name = "bitflags" version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "843867be96c8daad0d758b57df9392b6d8d271134fce549de6ce169ff98a92af" +[[package]] +name = "bytes" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33" + [[package]] name = "cc" version = "1.2.57" @@ -249,6 +283,19 @@ dependencies = [ name = "compiler_utils" version = "0.1.0" +[[package]] +name = "dashmap" +version = "5.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856" +dependencies = [ + "cfg-if", + "hashbrown", + "lock_api", + "once_cell", + "parking_lot_core", +] + [[package]] name = "diagnostics" version = "0.1.0" @@ -257,12 +304,118 @@ dependencies = [ "compiler_utils", ] +[[package]] +name = "displaydoc" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "errno" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "39cab71617ae0d63f51a36d69f866391735b51691dbda63cf6f96d042b63efeb" +dependencies = [ + "libc", + "windows-sys", +] + [[package]] name = "find-msvc-tools" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5baebc0774151f905a1a2cc41989300b1e6fbb29aff0ceffa1064fdd3088d582" +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d" + +[[package]] +name = "futures-io" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" + +[[package]] +name = "futures-macro" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "futures-sink" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893" + +[[package]] +name = "futures-task" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393" + +[[package]] +name = "futures-util" +version = "0.3.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + [[package]] name = "getrandom" version = "0.2.17" @@ -274,18 +427,133 @@ dependencies = [ "wasi", ] +[[package]] +name = "hashbrown" +version = "0.14.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" + [[package]] name = "heck" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "icu_collections" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2984d1cd16c883d7935b9e07e44071dca8d917fd52ecc02c04d5fa0b5a3f191c" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92219b62b3e2b4d88ac5119f8904c10f8f61bf7e95b640d25ba3075e6cac2c29" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c56e5ee99d6e3d33bd91c5d85458b6005a22140021cc324cea84dd0e72cff3b4" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da3be0ae77ea334f4da67c12f149704f19f81d1adf7c51cf482943e84a2bad38" + +[[package]] +name = "icu_properties" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bee3b67d0ea5c2cca5003417989af8996f8604e34fb9ddf96208a033901e70de" +dependencies = [ + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2bbb201e0c04f7b4b3e14382af113e17ba4f63e2c9d2ee626b720cbce54a14" + +[[package]] +name = "icu_provider" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139c4cf31c8b5f33d7e199446eff9c1e02decfc2f0eec2c8d71f65befa45b421" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3acae9609540aa318d1bc588455225fb2085b9ed0c4f6bd0d9d5bcd86f1a0344" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + [[package]] name = "inkwell" version = "0.8.0" source = "git+https://github.com/TheDan64/inkwell#07fa9f2435a9ee0521b88008324f229ff51a5b3e" dependencies = [ - "bitflags", + "bitflags 2.11.0", "inkwell_internals", "libc", "llvm-sys", @@ -308,6 +576,12 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + [[package]] name = "lazy_static" version = "1.5.0" @@ -328,6 +602,12 @@ version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" +[[package]] +name = "litemap" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92daf443525c4cce67b150400bc2316076100ce0b3686209eb8cf3c31612e6f0" + [[package]] name = "llvm-sys" version = "221.0.0" @@ -352,12 +632,129 @@ dependencies = [ "rand", ] +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "lsp" +version = "0.1.0" +dependencies = [ + "tokio", + "tower-lsp", +] + +[[package]] +name = "lsp-types" +version = "0.94.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c66bfd44a06ae10647fe3f8214762e9369fd4248df1350924b4ef9e770a85ea1" +dependencies = [ + "bitflags 1.3.2", + "serde", + "serde_json", + "serde_repr", + "url", +] + +[[package]] +name = "memchr" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" + +[[package]] +name = "mio" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50b7e5b27aa02a74bac8c3f23f448f8d87ff11f92d3aac1a6ed369ee08cc56c1" +dependencies = [ + "libc", + "wasi", + "windows-sys", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + [[package]] name = "once_cell_polyfill" version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1749c7ed4bcaf4c3d0a3efc28538844fb29bcdd7d2b67b2be7e20ba861ff517" +dependencies = [ + "pin-project-internal", +] + +[[package]] +name = "pin-project-internal" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b20ed30f105399776b9c883e68e536ef602a16ae6f596d2c473591d6ad64c6" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "potential_utf" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0103b1cef7ec0cf76490e969665504990193874ea05c85ff9bab8b911d0a0564" +dependencies = [ + "zerovec", +] + [[package]] name = "ppv-lite86" version = "0.2.21" @@ -426,24 +823,131 @@ dependencies = [ "getrandom", ] +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.11.0", +] + [[package]] name = "regex-lite" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cab834c73d247e67f4fae452806d17d3c7501756d98c8808d7c9c7aa7d18f973" +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + [[package]] name = "semver" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" +[[package]] +name = "serde" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.228" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "serde_json" +version = "1.0.149" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_repr" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175ee3e80ae9982737ca543e96133087cbd9a485eecc3bc4de9c1a37b47ea59c" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "shlex" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" + +[[package]] +name = "socket2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a766e1110788c36f4fa1c2b71b387a7815aa65f88ce0229841826633d93723e" +dependencies = [ + "libc", + "windows-sys", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + [[package]] name = "strsim" version = "0.11.1" @@ -461,6 +965,17 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "synstructure" +version = "0.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "728a70f3dbaf5bab7f0c4b1ac8d7ae5ea60a4b5549c8a5914361c99147a709d2" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "thiserror" version = "2.0.18" @@ -481,12 +996,173 @@ dependencies = [ "syn", ] +[[package]] +name = "tinystr" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8323304221c2a851516f22236c5722a72eaa19749016521d6dff0824447d96d" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tokio" +version = "1.52.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67dee974fe86fd92cc45b7a95fdd2f99a36a6d7b0d431a231178d3d670bbcc6" +dependencies = [ + "bytes", + "libc", + "mio", + "parking_lot", + "pin-project-lite", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys", +] + +[[package]] +name = "tokio-macros" +version = "2.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "385a6cb71ab9ab790c5fe8d67f1645e6c450a7ce006a33de03daa956cf70a496" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tokio-util" +version = "0.7.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ae9cec805b01e8fc3fd2fe289f89149a9b66dd16786abd8b19cfa7b48cb0098" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "tower" +version = "0.4.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" +dependencies = [ + "futures-core", + "futures-util", + "pin-project", + "pin-project-lite", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-lsp" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4ba052b54a6627628d9b3c34c176e7eda8359b7da9acd497b9f20998d118508" +dependencies = [ + "async-trait", + "auto_impl", + "bytes", + "dashmap", + "futures", + "httparse", + "lsp-types", + "memchr", + "serde", + "serde_json", + "tokio", + "tokio-util", + "tower", + "tower-lsp-macros", + "tracing", +] + +[[package]] +name = "tower-lsp-macros" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "84fd902d4e0b9a4b27f2f440108dc034e1758628a9b702f8ec61ad66355422fa" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + [[package]] name = "unicode-ident" version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75" +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", + "serde_derive", +] + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -514,6 +1190,35 @@ dependencies = [ "windows-link", ] +[[package]] +name = "writeable" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ffae5123b2d3fc086436f8834ae3ab053a283cfac8fe0a0b8eaae044768a4c4" + +[[package]] +name = "yoke" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abe8c5fda708d9ca3df187cae8bfb9ceda00dd96231bed36e445a1a48e66f9ca" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de844c262c8848816172cef550288e7dc6c7b7814b4ee56b3e1553f275f1858e" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.8.42" @@ -533,3 +1238,63 @@ dependencies = [ "quote", "syn", ] + +[[package]] +name = "zerofrom" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69faa1f2a1ea75661980b013019ed6687ed0e83d069bc1114e2cc74c6c04c4df" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11532158c46691caf0f2593ea8358fed6bbf68a0315e80aae9bd41fbade684a1" +dependencies = [ + "proc-macro2", + "quote", + "syn", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f9152d31db0792fa83f70fb2f83148effb5c1f5b8c7686c3459e361d9bc20bf" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90f911cbc359ab6af17377d242225f4d75119aec87ea711a880987b18cd7b239" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "625dc425cab0dca6dc3c3319506e6593dcb08a9f387ea3b284dbd52a92c40555" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 03da646a..e2fd34c8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,18 @@ [workspace] -members = ["compiler/ast", "compiler/ast_parser", "compiler/astoir", "compiler/astoir_hir", "compiler/astoir_hir_lowering", "compiler/astoir_mir", "compiler/compiler_typing", "compiler/astoir_mir_lowering", "compiler/compiler_main", "compiler/compiler_utils", "compiler/llvm_ir_bridge", "compiler/diagnostics", "compiler/prelude", "compiler/compiler_global_scope"] +members = [ + "compiler/ast", + "compiler/ast_parser", + "compiler/astoir", + "compiler/astoir_hir", + "compiler/astoir_hir_lowering", + "compiler/astoir_mir", + "compiler/compiler_typing", + "compiler/astoir_mir_lowering", + "compiler/compiler_main", + "compiler/compiler_utils", + "compiler/llvm_ir_bridge", + "compiler/diagnostics", + "compiler/prelude", + "compiler/compiler_global_scope", + "lsp", +] diff --git a/lsp/Cargo.toml b/lsp/Cargo.toml new file mode 100644 index 00000000..b7c93155 --- /dev/null +++ b/lsp/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "lsp" +version = "0.1.0" +edition = "2024" + +[dependencies] +tower-lsp = "0.20" +tokio = { version = "1", features = ["full"] } From 0104e32aafbaf29c7740378a84c65ab613929574 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 22:05:50 +0200 Subject: [PATCH 10/18] feat: added basic LSP --- lsp/src/lsp.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ lsp/src/main.rs | 3 +++ 2 files changed, 49 insertions(+) create mode 100644 lsp/src/lsp.rs create mode 100644 lsp/src/main.rs diff --git a/lsp/src/lsp.rs b/lsp/src/lsp.rs new file mode 100644 index 00000000..cf5465e5 --- /dev/null +++ b/lsp/src/lsp.rs @@ -0,0 +1,46 @@ +use std::{ + collections::{HashMap, HashSet}, + sync::{Arc, Mutex}, +}; + +use tower_lsp::{ + Client, LanguageServer, + lsp_types::{ + CompletionOptions, HoverProviderCapability, InitializeParams, InitializeResult, + InitializedParams, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, + TextDocumentSyncKind, + }, +}; + +#[derive(Debug)] +pub struct LSPBackend { + lsp_client: Client, + documents: Arc>>, +} + +#[tower_lsp::async_trait] +impl LanguageServer for LSPBackend { + async fn initialize( + &self, + _: InitializeParams, + ) -> tower_lsp::jsonrpc::Result { + Ok(InitializeResult { + capabilities: ServerCapabilities { + hover_provider: Some(HoverProviderCapability::Simple(true)), + completion_provider: Some(CompletionOptions::default()), + text_document_sync: Some(TextDocumentSyncCapability::Kind( + TextDocumentSyncKind::FULL, + )), + ..Default::default() + }, + server_info: Some(ServerInfo { + name: "quickfall-lsp".to_string(), + version: Some("0.1".to_string()), + }), + }) + } + + async fn shutdown(&self) -> tower_lsp::jsonrpc::Result<()> { + Ok(()) + } +} diff --git a/lsp/src/main.rs b/lsp/src/main.rs new file mode 100644 index 00000000..4ad3da8e --- /dev/null +++ b/lsp/src/main.rs @@ -0,0 +1,3 @@ +pub mod lsp; + +fn main() {} From b6b5a729044ac70d1d7be967d916808bafc72872 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 22:18:01 +0200 Subject: [PATCH 11/18] =?UTF-8?q?feat:=20added=20diagnostic=20conversion?= =?UTF-8?q?=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 1 + lsp/Cargo.toml | 1 + lsp/src/diags.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ lsp/src/main.rs | 1 + 4 files changed, 50 insertions(+) create mode 100644 lsp/src/diags.rs diff --git a/Cargo.lock b/Cargo.lock index 26889b79..5b617781 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,6 +645,7 @@ dependencies = [ name = "lsp" version = "0.1.0" dependencies = [ + "diagnostics", "tokio", "tower-lsp", ] diff --git a/lsp/Cargo.toml b/lsp/Cargo.toml index b7c93155..42fb104a 100644 --- a/lsp/Cargo.toml +++ b/lsp/Cargo.toml @@ -6,3 +6,4 @@ edition = "2024" [dependencies] tower-lsp = "0.20" tokio = { version = "1", features = ["full"] } +diagnostics = { path = "../compiler/diagnostics" } diff --git a/lsp/src/diags.rs b/lsp/src/diags.rs new file mode 100644 index 00000000..9b4eee41 --- /dev/null +++ b/lsp/src/diags.rs @@ -0,0 +1,47 @@ +use diagnostics::diagnostic::Level; +use tower_lsp::lsp_types::{ + Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Location, Position, Range, Url, +}; + +pub fn to_tower_diag(diagnostic: diagnostics::diagnostic::Diagnostic) -> Diagnostic { + let severity = match diagnostic.level { + Level::Error => DiagnosticSeverity::ERROR, + Level::Warning => DiagnosticSeverity::WARNING, + Level::Note => DiagnosticSeverity::INFORMATION, + }; + + let mut related_info = vec![]; + + for span in diagnostic.spans { + related_info.push(DiagnosticRelatedInformation { + location: Location { + uri: Url::parse(&span.start.file_path).unwrap(), + range: Range { + start: Position::new(span.start.line as u32, span.start.col as u32), + end: Position::new(span.start.line as u32, span.start.end_col as u32), + }, + }, + message: span.label.unwrap().into(), + }); + } + + let main_range = Range { + start: Position::new( + diagnostic.primary_span.start.line as u32, + diagnostic.primary_span.start.col as u32, + ), + end: Position::new( + diagnostic.primary_span.start.line as u32, + diagnostic.primary_span.start.end_col as u32, + ), + }; + + Diagnostic { + range: main_range, + message: diagnostic.primary_span.label.unwrap(), + severity: Some(severity), + related_information: Some(related_info), + + ..Default::default() + } +} diff --git a/lsp/src/main.rs b/lsp/src/main.rs index 4ad3da8e..4c24f277 100644 --- a/lsp/src/main.rs +++ b/lsp/src/main.rs @@ -1,3 +1,4 @@ +pub mod diags; pub mod lsp; fn main() {} From 28ea2e9ae324536f23553b13d7c6d89841ed7111 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 22:38:43 +0200 Subject: [PATCH 12/18] feat: added basic checking --- Cargo.lock | 4 ++++ compiler/diagnostics/src/lib.rs | 4 ++++ compiler/lexer/src/lexer.rs | 2 +- lsp/Cargo.toml | 4 ++++ lsp/src/bridge.rs | 20 ++++++++++++++++++++ lsp/src/diags.rs | 20 ++++++++++++++++++-- lsp/src/lsp.rs | 33 ++++++++++++++++++++++++++++----- lsp/src/main.rs | 22 +++++++++++++++++++++- 8 files changed, 100 insertions(+), 9 deletions(-) create mode 100644 lsp/src/bridge.rs diff --git a/Cargo.lock b/Cargo.lock index 5b617781..5a1aa7f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -645,7 +645,11 @@ dependencies = [ name = "lsp" version = "0.1.0" dependencies = [ + "ast", + "ast_parser", + "astoir", "diagnostics", + "lexer", "tokio", "tower-lsp", ] diff --git a/compiler/diagnostics/src/lib.rs b/compiler/diagnostics/src/lib.rs index 90114d0d..3b3cb94b 100644 --- a/compiler/diagnostics/src/lib.rs +++ b/compiler/diagnostics/src/lib.rs @@ -74,6 +74,10 @@ pub fn has_diagnostics() -> bool { DIAGNOSTIC_CONTAINER.with_borrow(|f| return !f.diagnostics.is_empty()) } +pub fn get_diagnostics() -> Vec { + DIAGNOSTIC_CONTAINER.with_borrow(|f| return f.diagnostics.clone()) +} + pub fn move_current_diagnostic_pos(pos: SpanPosition) { CURR_DIAGNOSTIC_POS.with_borrow_mut(|f| { *f = Some(pos); diff --git a/compiler/lexer/src/lexer.rs b/compiler/lexer/src/lexer.rs index d0520bca..68d87254 100644 --- a/compiler/lexer/src/lexer.rs +++ b/compiler/lexer/src/lexer.rs @@ -42,7 +42,7 @@ const USE_KEYWORD_HASH: u64 = hash!("use"); pub fn lexer_parse_file(file_path: &String) -> DiagnosticResult> { let contents: String = match fs::read_to_string(file_path) { Ok(v) => v, - Err(_) => panic!("Couldn't read the file"), + Err(_) => panic!("Couldn't read the file {}", file_path), }; let mut tokens: Vec = Vec::new(); diff --git a/lsp/Cargo.toml b/lsp/Cargo.toml index 42fb104a..91c0b493 100644 --- a/lsp/Cargo.toml +++ b/lsp/Cargo.toml @@ -7,3 +7,7 @@ edition = "2024" tower-lsp = "0.20" tokio = { version = "1", features = ["full"] } diagnostics = { path = "../compiler/diagnostics" } +astoir = { path = "../compiler/astoir" } +ast = { path = "../compiler/ast" } +ast_parser = { path = "../compiler/ast_parser" } +lexer = { path = "../compiler/lexer" } diff --git a/lsp/src/bridge.rs b/lsp/src/bridge.rs new file mode 100644 index 00000000..fd13e4b8 --- /dev/null +++ b/lsp/src/bridge.rs @@ -0,0 +1,20 @@ +use ast_parser::parse_ast_ctx; +use astoir::run_astoir_mir; +use diagnostics::{diagnostic::Diagnostic, get_diagnostics, has_diagnostics}; +use lexer::lexer::lexer_parse_file; + +pub fn check_for_file(url: String) -> Vec { + let lexer = lexer_parse_file(&url); + if has_diagnostics() { + return get_diagnostics(); + } + + let ast = parse_ast_ctx(&lexer.unwrap()); + if has_diagnostics() { + return get_diagnostics(); + } + + run_astoir_mir(ast.unwrap()); + + return get_diagnostics(); +} diff --git a/lsp/src/diags.rs b/lsp/src/diags.rs index 9b4eee41..8c0eea83 100644 --- a/lsp/src/diags.rs +++ b/lsp/src/diags.rs @@ -3,6 +3,8 @@ use tower_lsp::lsp_types::{ Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Location, Position, Range, Url, }; +use crate::main; + pub fn to_tower_diag(diagnostic: diagnostics::diagnostic::Diagnostic) -> Diagnostic { let severity = match diagnostic.level { Level::Error => DiagnosticSeverity::ERROR, @@ -15,7 +17,7 @@ pub fn to_tower_diag(diagnostic: diagnostics::diagnostic::Diagnostic) -> Diagnos for span in diagnostic.spans { related_info.push(DiagnosticRelatedInformation { location: Location { - uri: Url::parse(&span.start.file_path).unwrap(), + uri: Url::parse(&format!("file:///{}", span.start.file_path)).unwrap(), range: Range { start: Position::new(span.start.line as u32, span.start.col as u32), end: Position::new(span.start.line as u32, span.start.end_col as u32), @@ -36,9 +38,23 @@ pub fn to_tower_diag(diagnostic: diagnostics::diagnostic::Diagnostic) -> Diagnos ), }; + if diagnostic.primary_span.label.is_some() { + related_info.push(DiagnosticRelatedInformation { + location: Location { + uri: Url::parse(&format!( + "file:///{}", + diagnostic.primary_span.start.file_path + )) + .unwrap(), + range: main_range.clone(), + }, + message: diagnostic.primary_span.label.unwrap(), + }) + } + Diagnostic { range: main_range, - message: diagnostic.primary_span.label.unwrap(), + message: diagnostic.message, severity: Some(severity), related_information: Some(related_info), diff --git a/lsp/src/lsp.rs b/lsp/src/lsp.rs index cf5465e5..7bb5fa8b 100644 --- a/lsp/src/lsp.rs +++ b/lsp/src/lsp.rs @@ -6,16 +6,18 @@ use std::{ use tower_lsp::{ Client, LanguageServer, lsp_types::{ - CompletionOptions, HoverProviderCapability, InitializeParams, InitializeResult, - InitializedParams, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, - TextDocumentSyncKind, + CompletionOptions, DidOpenTextDocumentParams, HoverProviderCapability, InitializeParams, + InitializeResult, InitializedParams, MessageType, ServerCapabilities, ServerInfo, + TextDocumentSyncCapability, TextDocumentSyncKind, }, }; +use crate::{bridge::check_for_file, diags::to_tower_diag}; + #[derive(Debug)] pub struct LSPBackend { - lsp_client: Client, - documents: Arc>>, + pub lsp_client: Client, + pub documents: Arc>>, } #[tower_lsp::async_trait] @@ -40,6 +42,27 @@ impl LanguageServer for LSPBackend { }) } + async fn did_open(&self, param: DidOpenTextDocumentParams) { + let uri = param.text_document.uri.to_string(); + let text = param.text_document.text; + + self.documents.lock().unwrap().insert(uri.clone()); + + let mut diags = vec![]; + + self.lsp_client + .log_message(MessageType::ERROR, format!("Path: {}", uri)) + .await; + + for diag in check_for_file(uri.clone().replace("file://", "")) { + diags.push(to_tower_diag(diag)) + } + + self.lsp_client + .publish_diagnostics(uri.parse().unwrap(), diags, None) + .await; + } + async fn shutdown(&self) -> tower_lsp::jsonrpc::Result<()> { Ok(()) } diff --git a/lsp/src/main.rs b/lsp/src/main.rs index 4c24f277..97fb340e 100644 --- a/lsp/src/main.rs +++ b/lsp/src/main.rs @@ -1,4 +1,24 @@ +use std::{ + collections::HashSet, + sync::{Arc, Mutex}, +}; + +use tower_lsp::{LspService, Server}; + +use crate::lsp::LSPBackend; + +pub mod bridge; pub mod diags; pub mod lsp; -fn main() {} +#[tokio::main] +async fn main() { + let stdin = tokio::io::stdin(); + let stdout = tokio::io::stdout(); + let (service, socket) = LspService::build(|client| LSPBackend { + lsp_client: client, + documents: Arc::new(Mutex::new(HashSet::new())), + }) + .finish(); + Server::new(stdin, stdout, socket).serve(service).await; +} From feb51e69c5ad22aa1511723fdec8a7664c49c7e3 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Wed, 22 Apr 2026 11:03:52 +0200 Subject: [PATCH 13/18] feat: added debug log for later --- compiler/astoir_hir_lowering/src/types.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/compiler/astoir_hir_lowering/src/types.rs b/compiler/astoir_hir_lowering/src/types.rs index 95d9b44f..f04c4b09 100644 --- a/compiler/astoir_hir_lowering/src/types.rs +++ b/compiler/astoir_hir_lowering/src/types.rs @@ -65,6 +65,10 @@ pub fn lower_ast_type( { return Ok(Type::Generic(t, vec![], vec![])); } else { + + println!("{}: {:#?}", hash, lower); + println!("{:#?}", context.global_scope.get_type(EntryKey { name_hash: hash }, origin)); + let ind = match context.global_scope.append( EntryKey { name_hash: hash }, GlobalStorageEntryType::Type(lower), From 4d555513532c1a9327794ff18f526e6ca20da523 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Wed, 22 Apr 2026 11:04:50 +0200 Subject: [PATCH 14/18] chore: fixed warns --- compiler/compiler_main/src/cli.rs | 2 +- compiler/compiler_main/src/cmds/check.rs | 4 ++-- compiler/compiler_main/src/main.rs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/compiler/compiler_main/src/cli.rs b/compiler/compiler_main/src/cli.rs index a6378d1f..9687fdd4 100644 --- a/compiler/compiler_main/src/cli.rs +++ b/compiler/compiler_main/src/cli.rs @@ -1,4 +1,4 @@ -use std::path::{Path, PathBuf}; +use std::path::PathBuf; use clap::{Parser, Subcommand, ValueEnum}; diff --git a/compiler/compiler_main/src/cmds/check.rs b/compiler/compiler_main/src/cmds/check.rs index b34aef36..cc402530 100644 --- a/compiler/compiler_main/src/cmds/check.rs +++ b/compiler/compiler_main/src/cmds/check.rs @@ -13,12 +13,12 @@ pub fn run_check(path: String, layer: IRLayer) { match layer { IRLayer::HIR => { - let hir = run_astoir_hir(ast.unwrap()); + let _hir = run_astoir_hir(ast.unwrap()); quietlyquit_if_errors!(); } IRLayer::MIR => { - let mir = run_astoir_mir(ast.unwrap()); + let _mir = run_astoir_mir(ast.unwrap()); quietlyquit_if_errors!(); } } diff --git a/compiler/compiler_main/src/main.rs b/compiler/compiler_main/src/main.rs index 82f35313..c0e5855b 100644 --- a/compiler/compiler_main/src/main.rs +++ b/compiler/compiler_main/src/main.rs @@ -1,6 +1,6 @@ use std::{ fs, - path::{Path, PathBuf}, + path::PathBuf, time::Instant, }; @@ -43,7 +43,7 @@ fn main() { out, bridge, format, - linker, + linker: _, input, } => { let needs_dir = input.len() > 1 && format != OutputFormat::Executable; From a5ab5ab83b905a590a17acd06afc54d49ea5d268 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Wed, 22 Apr 2026 11:10:52 +0200 Subject: [PATCH 15/18] chore: added README --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index fed3dc0f..668ce99b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,9 @@ # Quickfall +![GitHub Release](https://img.shields.io/github/v/release/Quickfall/quickfall?include_prereleases) +![GitHub repo size](https://img.shields.io/github/repo-size/Quickfall/quickfall) +![GitHub Issues or Pull Requests](https://img.shields.io/github/issues/Quickfall/Quickfall) + + Quickfall is a programming language focusing on allowing everyone to build fast, reliable and safe software. ## Why Quickfall From 07ffc58d5d3c0ea5f241f552760b4dc8615f87d1 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Wed, 22 Apr 2026 11:14:13 +0200 Subject: [PATCH 16/18] chore: added more detail for the CONTRIBUTING --- CONTRIBUTING.MD | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTING.MD b/CONTRIBUTING.MD index a0270a61..2ada2422 100644 --- a/CONTRIBUTING.MD +++ b/CONTRIBUTING.MD @@ -17,4 +17,11 @@ You will need the following installed in order to compile & use Quickfall: - Rust 1.94.1 - LLVM 22.1 -You can then build the project by using the `cargo` Rust tool. \ No newline at end of file +You can then build the project by using the `cargo` Rust tool. + +You can build different targets for the Quickfall project: +- `-p compiler_main`: The compiler +- `-p lsp`: The language server provider + +Additionally, for the compiler target. You can add different features to customize the build. Here's a list of features and what they change +- `diagbacktraces`: Add backtraces for inside of the compiler codebase for every Diagnostic. Automatically enables backtraces on diagnostics \ No newline at end of file From 7cefa3313cf337d9a1d65d2b9d43eb06a317ef48 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Tue, 21 Apr 2026 23:06:15 +0200 Subject: [PATCH 17/18] feat: made LSP work --- compiler/diagnostics/src/lib.rs | 4 ++++ compiler/lexer/src/lexer.rs | 10 +++++++--- lsp/src/bridge.rs | 12 +++++++----- lsp/src/diags.rs | 2 -- lsp/src/lsp.rs | 33 +++++++++++++++++++++++++-------- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/compiler/diagnostics/src/lib.rs b/compiler/diagnostics/src/lib.rs index 3b3cb94b..c0428c06 100644 --- a/compiler/diagnostics/src/lib.rs +++ b/compiler/diagnostics/src/lib.rs @@ -70,6 +70,10 @@ pub fn dump_diagnostics() { }) } +pub fn clear_diagnostics() { + DIAGNOSTIC_CONTAINER.with_borrow_mut(|f| f.diagnostics.clear()) +} + pub fn has_diagnostics() -> bool { DIAGNOSTIC_CONTAINER.with_borrow(|f| return !f.diagnostics.is_empty()) } diff --git a/compiler/lexer/src/lexer.rs b/compiler/lexer/src/lexer.rs index 68d87254..202ba992 100644 --- a/compiler/lexer/src/lexer.rs +++ b/compiler/lexer/src/lexer.rs @@ -39,12 +39,16 @@ const USE_KEYWORD_HASH: u64 = hash!("use"); /// ``` /// let result: LexerParseResult> = lexer_parse_file("test_file.qf").expect("Lexer didn't work"); /// ``` -pub fn lexer_parse_file(file_path: &String) -> DiagnosticResult> { - let contents: String = match fs::read_to_string(file_path) { +pub fn lexer_parse_file(path: &String) -> DiagnosticResult> { + let contents: String = match fs::read_to_string(path) { Ok(v) => v, - Err(_) => panic!("Couldn't read the file {}", file_path), + Err(_) => panic!("Couldn't read the file {}", path), }; + lexer_parse(contents, path) +} + +pub fn lexer_parse(contents: String, file_path: &String) -> DiagnosticResult> { let mut tokens: Vec = Vec::new(); let mut i: usize = 0; diff --git a/lsp/src/bridge.rs b/lsp/src/bridge.rs index fd13e4b8..51ce0889 100644 --- a/lsp/src/bridge.rs +++ b/lsp/src/bridge.rs @@ -1,10 +1,12 @@ use ast_parser::parse_ast_ctx; use astoir::run_astoir_mir; -use diagnostics::{diagnostic::Diagnostic, get_diagnostics, has_diagnostics}; -use lexer::lexer::lexer_parse_file; +use diagnostics::{clear_diagnostics, diagnostic::Diagnostic, get_diagnostics, has_diagnostics}; +use lexer::lexer::lexer_parse; -pub fn check_for_file(url: String) -> Vec { - let lexer = lexer_parse_file(&url); +pub fn check_for_file(url: String, text: String) -> Vec { + clear_diagnostics(); + + let lexer = lexer_parse(text, &url); if has_diagnostics() { return get_diagnostics(); } @@ -14,7 +16,7 @@ pub fn check_for_file(url: String) -> Vec { return get_diagnostics(); } - run_astoir_mir(ast.unwrap()); + let _ = run_astoir_mir(ast.unwrap()); return get_diagnostics(); } diff --git a/lsp/src/diags.rs b/lsp/src/diags.rs index 8c0eea83..c80053e8 100644 --- a/lsp/src/diags.rs +++ b/lsp/src/diags.rs @@ -3,8 +3,6 @@ use tower_lsp::lsp_types::{ Diagnostic, DiagnosticRelatedInformation, DiagnosticSeverity, Location, Position, Range, Url, }; -use crate::main; - pub fn to_tower_diag(diagnostic: diagnostics::diagnostic::Diagnostic) -> Diagnostic { let severity = match diagnostic.level { Level::Error => DiagnosticSeverity::ERROR, diff --git a/lsp/src/lsp.rs b/lsp/src/lsp.rs index 7bb5fa8b..e9fc247f 100644 --- a/lsp/src/lsp.rs +++ b/lsp/src/lsp.rs @@ -1,14 +1,14 @@ use std::{ - collections::{HashMap, HashSet}, + collections::HashSet, sync::{Arc, Mutex}, }; use tower_lsp::{ Client, LanguageServer, lsp_types::{ - CompletionOptions, DidOpenTextDocumentParams, HoverProviderCapability, InitializeParams, - InitializeResult, InitializedParams, MessageType, ServerCapabilities, ServerInfo, - TextDocumentSyncCapability, TextDocumentSyncKind, + DidChangeTextDocumentParams, DidOpenTextDocumentParams, InitializeParams, InitializeResult, + MessageType, ServerCapabilities, ServerInfo, TextDocumentSyncCapability, + TextDocumentSyncKind, }, }; @@ -28,8 +28,8 @@ impl LanguageServer for LSPBackend { ) -> tower_lsp::jsonrpc::Result { Ok(InitializeResult { capabilities: ServerCapabilities { - hover_provider: Some(HoverProviderCapability::Simple(true)), - completion_provider: Some(CompletionOptions::default()), + hover_provider: None, + completion_provider: None, text_document_sync: Some(TextDocumentSyncCapability::Kind( TextDocumentSyncKind::FULL, )), @@ -50,14 +50,31 @@ impl LanguageServer for LSPBackend { let mut diags = vec![]; + for diag in check_for_file(uri.clone().replace("file://", ""), text.clone()) { + diags.push(to_tower_diag(diag)) + } + + self.lsp_client.log_message(MessageType::ERROR, text).await; + self.lsp_client - .log_message(MessageType::ERROR, format!("Path: {}", uri)) + .publish_diagnostics(uri.parse().unwrap(), diags, None) .await; + } - for diag in check_for_file(uri.clone().replace("file://", "")) { + async fn did_change(&self, params: DidChangeTextDocumentParams) { + let uri = params.text_document.uri.to_string(); + let text = params.content_changes[0].text.clone(); + + self.documents.lock().unwrap().insert(uri.clone()); + + let mut diags = vec![]; + + for diag in check_for_file(uri.clone().replace("file://", ""), text.clone()) { diags.push(to_tower_diag(diag)) } + self.lsp_client.log_message(MessageType::ERROR, text).await; + self.lsp_client .publish_diagnostics(uri.parse().unwrap(), diags, None) .await; From 9dadf3a93460ec7a80d8a9b27e7510ae670c88e6 Mon Sep 17 00:00:00 2001 From: Zffu <103074097+Zffu@users.noreply.github.com> Date: Thu, 23 Apr 2026 22:27:09 +0200 Subject: [PATCH 18/18] chore: removed vulnerable rand crate usage --- Cargo.lock | 71 ---------------------------- compiler/llvm_ir_bridge/Cargo.toml | 1 - compiler/llvm_ir_bridge/src/utils.rs | 11 ----- 3 files changed, 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a1aa7f4..dec2b97b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,17 +416,6 @@ dependencies = [ "slab", ] -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "hashbrown" version = "0.14.5" @@ -629,7 +618,6 @@ dependencies = [ "astoir_mir", "compiler_typing", "inkwell", - "rand", ] [[package]] @@ -760,15 +748,6 @@ dependencies = [ "zerovec", ] -[[package]] -name = "ppv-lite86" -version = "0.2.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" -dependencies = [ - "zerocopy", -] - [[package]] name = "prelude" version = "0.1.0" @@ -798,36 +777,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core", -] - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "redox_syscall" version = "0.5.18" @@ -1224,26 +1173,6 @@ dependencies = [ "synstructure", ] -[[package]] -name = "zerocopy" -version = "0.8.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3" -dependencies = [ - "zerocopy-derive", -] - -[[package]] -name = "zerocopy-derive" -version = "0.8.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "zerofrom" version = "0.1.7" diff --git a/compiler/llvm_ir_bridge/Cargo.toml b/compiler/llvm_ir_bridge/Cargo.toml index 01936aa1..1c97086e 100644 --- a/compiler/llvm_ir_bridge/Cargo.toml +++ b/compiler/llvm_ir_bridge/Cargo.toml @@ -9,4 +9,3 @@ inkwell = { git = "https://github.com/TheDan64/inkwell", features = [ ] } astoir_mir = { path = "../astoir_mir" } compiler_typing = { path = "../compiler_typing" } -rand = "0.8" diff --git a/compiler/llvm_ir_bridge/src/utils.rs b/compiler/llvm_ir_bridge/src/utils.rs index 1933beaa..c770cc7e 100644 --- a/compiler/llvm_ir_bridge/src/utils.rs +++ b/compiler/llvm_ir_bridge/src/utils.rs @@ -6,7 +6,6 @@ use inkwell::{ types::{BasicMetadataTypeEnum, BasicTypeEnum, IntType, PointerType}, values::{BasicValueEnum, FunctionValue}, }; -use rand::{Rng, distributions::Alphanumeric}; pub type LLVMBlock = LLVMSiblingObject>; pub type LLVMBasicValue = LLVMSiblingObject>; @@ -84,13 +83,3 @@ impl Deref for LLVMSiblingObject { return &self.inner; } } - -pub fn get_block_name() -> String { - let s = rand::thread_rng() - .sample_iter(&Alphanumeric) - .take(24) - .map(char::from) - .collect(); - - return s; -}