Feat: add -c flag to skip entry-point check
`fluxc -c <file>` compiles a source file without requiring a `main` function, matching the convention of C compilers. Pass 4 (entry-point validation) is skipped when `no_main` is set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -166,7 +166,7 @@ fn value_struct_name(ty: &Ty) -> Option<&str> {
|
||||
|
||||
// ── Entry point ────────────────────────────────────────────────────────────────
|
||||
|
||||
pub fn check(program: &ast::Program<Parsed>) -> Vec<Diagnostic> {
|
||||
pub fn check(program: &ast::Program<Parsed>, no_main: bool) -> Vec<Diagnostic> {
|
||||
let mut checker = Checker::new();
|
||||
|
||||
// ── Pass 1: collect struct names + function signatures ────────────────────
|
||||
@@ -259,6 +259,7 @@ pub fn check(program: &ast::Program<Parsed>) -> Vec<Diagnostic> {
|
||||
}
|
||||
|
||||
// ── Pass 4: verify entry point ────────────────────────────────────────────
|
||||
if !no_main {
|
||||
let main_info = checker
|
||||
.phi
|
||||
.get("main")
|
||||
@@ -285,6 +286,7 @@ pub fn check(program: &ast::Program<Parsed>) -> Vec<Diagnostic> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
checker.errors
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ mod tests {
|
||||
"parse errors: {:?}",
|
||||
parser.errors
|
||||
);
|
||||
checker::check(&program)
|
||||
checker::check(&program, false)
|
||||
.into_iter()
|
||||
.map(|d| d.message)
|
||||
.collect()
|
||||
|
||||
@@ -23,6 +23,10 @@ pub fn print_help() {
|
||||
"-V".bold(),
|
||||
"--version".bold(),
|
||||
);
|
||||
println!(
|
||||
" {} Compile without requiring a `main` entry point",
|
||||
"-c".bold(),
|
||||
);
|
||||
println!();
|
||||
println!("{}", "ARGS:".bold().yellow());
|
||||
println!(
|
||||
@@ -57,10 +61,13 @@ pub fn io_error(path: &str, err: std::io::Error) -> ! {
|
||||
|
||||
pub struct Opts {
|
||||
pub files: Vec<String>,
|
||||
/// `-c`: compile without requiring a `main` entry point.
|
||||
pub no_main: bool,
|
||||
}
|
||||
|
||||
pub fn parse_args() -> Opts {
|
||||
let mut files = Vec::new();
|
||||
let mut no_main = false;
|
||||
|
||||
for arg in std::env::args().skip(1) {
|
||||
match arg.as_str() {
|
||||
@@ -72,6 +79,7 @@ pub fn parse_args() -> Opts {
|
||||
print_version();
|
||||
process::exit(0);
|
||||
}
|
||||
"-c" => no_main = true,
|
||||
flag if flag.starts_with('-') => {
|
||||
fatal(&format!("unknown option `{flag}`"));
|
||||
}
|
||||
@@ -83,5 +91,5 @@ pub fn parse_args() -> Opts {
|
||||
fatal("no input files — at least one source file is required");
|
||||
}
|
||||
|
||||
Opts { files }
|
||||
Opts { files, no_main }
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ fn main() {
|
||||
}
|
||||
|
||||
if parser.errors.is_empty() {
|
||||
let sema_errors = checker::check(&program);
|
||||
let sema_errors = checker::check(&program, opts.no_main);
|
||||
for diag in &sema_errors {
|
||||
eprint!("{}", diag.render(&content, path));
|
||||
had_errors = true;
|
||||
|
||||
Reference in New Issue
Block a user