-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompiler.bl
More file actions
34 lines (30 loc) · 1.04 KB
/
Copy pathcompiler.bl
File metadata and controls
34 lines (30 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// compiler.bl — Example compiler driver
//
// Demonstrates the pattern used by the Blink compiler to read a source
// file, process it, and write output. The real compiler entry point is
// src/blinkc_main.bl, which uses the compiler module's public API:
//
// let program = compile_to_program(source_path, 1)
// let _errs = check_types(program)
// let c_output = generate(program)
// write_file(out_path, c_output)
//
// This standalone example shows the arg parsing and file I/O pattern
// without depending on the compiler internals.
fn main() {
if arg_count() < 2 {
io.println("Usage: compiler <source.bl> [output.c]")
io.println(" Compiles a Blink source file to C.")
return
}
let source_path = get_arg(1)
let source = read_file(source_path)
io.println("Read {source.len()} bytes from {source_path}")
if arg_count() >= 3 {
let out_path = get_arg(2)
write_file(out_path, source)
io.println("Wrote output to {out_path}")
} else {
io.println(source)
}
}