better compiler warnings adn errors

This commit is contained in:
2026-02-20 12:40:49 -06:00
parent 54e5be0773
commit 8d449e6fc6
10 changed files with 679 additions and 93 deletions

View File

@@ -6,6 +6,7 @@
// cell streamline --ir <file> Human-readable IR
// cell streamline --check <file> Warnings only (e.g. high slot count)
// cell streamline --types <file> Optimized IR with type annotations
// cell streamline --diagnose <file> Run diagnostics (type errors/warnings)
var fd = use("fd")
var json = use("json")
@@ -15,8 +16,11 @@ var show_stats = false
var show_ir = false
var show_check = false
var show_types = false
var show_diagnose = false
var filename = null
var i = 0
var di = 0
var diag = null
for (i = 0; i < length(args); i++) {
if (args[i] == '--stats') {
@@ -27,8 +31,10 @@ for (i = 0; i < length(args); i++) {
show_check = true
} else if (args[i] == '--types') {
show_types = true
} else if (args[i] == '--diagnose') {
show_diagnose = true
} else if (args[i] == '--help' || args[i] == '-h') {
log.console("Usage: cell streamline [--stats] [--ir] [--check] [--types] <file>")
log.console("Usage: cell streamline [--stats] [--ir] [--check] [--types] [--diagnose] <file>")
$stop()
} else if (!starts_with(args[i], '-')) {
filename = args[i]
@@ -36,7 +42,7 @@ for (i = 0; i < length(args); i++) {
}
if (!filename) {
print("usage: cell streamline [--stats] [--ir] [--check] [--types] <file>")
print("usage: cell streamline [--stats] [--ir] [--check] [--types] [--diagnose] <file>")
$stop()
}
@@ -46,10 +52,19 @@ if (show_stats) {
before = json.decode(json.encode(shop.mcode_file(filename)))
}
var optimized = shop.compile_file(filename)
// For --diagnose, compile with _warn enabled to get diagnostics
var optimized = null
var compiled = null
if (show_diagnose) {
compiled = shop.mcode_file(filename)
compiled._warn = true
optimized = use('streamline')(compiled)
} else {
optimized = shop.compile_file(filename)
}
// If no flags, default to full JSON output
if (!show_stats && !show_ir && !show_check && !show_types) {
if (!show_stats && !show_ir && !show_check && !show_types && !show_diagnose) {
print(json.encode(optimized, true))
$stop()
}
@@ -343,4 +358,18 @@ if (show_stats) {
print('---')
}
if (show_diagnose) {
if (optimized._diagnostics != null && length(optimized._diagnostics) > 0) {
di = 0
while (di < length(optimized._diagnostics)) {
diag = optimized._diagnostics[di]
print(`${diag.file}:${text(diag.line)}:${text(diag.col)}: ${diag.severity}: ${diag.message}`)
di = di + 1
}
print(`\n${text(length(optimized._diagnostics))} diagnostic(s)`)
} else {
print("No diagnostics.")
}
}
$stop()