wip typing

This commit is contained in:
Michael Sippel 2024-10-09 07:28:56 +02:00
parent c9c42d383f
commit b8535aa772
Signed by: senvas
GPG key ID: F96CF119C34B64A6
10 changed files with 749 additions and 552 deletions

View file

@ -51,23 +51,35 @@ fn main() {
match ltcore::parser::parse_expr( &mut main_scope, &mut program_tokens ) {
Ok( mut ast ) => {
let mut compiler = ProcedureCompiler::new(&main_scope);
let mut compiler = ProcedureCompiler::new(path.clone(), main_scope.clone());
match compiler.infer_type(&mut ast) {
match ast.infer_type(&main_scope) {
Ok(mut t) => {
eprintln!("Typecheck {}", "OK".green().bold());
t = t.normalize();
t = t.param_normalize();
let mut tc = compiler.symbols.clone();
eprintln!("Expr has type:\n================\n{}\n================\n", t.sugar(&mut tc).pretty(&mut tc, 0));
let mut tc = main_scope.clone();
eprintln!( "{}", t.sugar(&mut tc).pretty(&tc,0) );
}
Err(e) => {
eprintln!("{} [{:?}]", "Type Error".red(), e);
Err(type_errs) => {
for e in type_errs.iter() {
crate::diagnostic::print_diagnostic(
path.as_str(),
e.region,
e.kind.fmt(&mut main_scope.clone())
);
}
eprintln!("----------------------------------");
eprintln!("{} ({} errors)", "Typecheck failed".bright_red().bold(), type_errs.len());
return;
}
}
let (exports, diagnostics, proc_code) = compiler
.compile(&ast)
.into_asm(&path);
compiler = compiler.compile_expr(&ast);
let diagnostics = compiler.diagnostics.clone();
let (exports, proc_code) = compiler.get_bytecode(false);
for (region, message) in diagnostics {
crate::diagnostic::print_diagnostic(
@ -76,7 +88,8 @@ fn main() {
format!("{}", message)
);
}
eprintln!("{} {}", "Compiled".green(), path.bold());
for (name, def) in exports.iter() {
eprintln!("export {}:", name.yellow().bold());
@ -93,6 +106,10 @@ fn main() {
/* link assembly-program to symbols
*/
eprintln!("generated bytecode ({})", proc_code.len() );
for (i,l) in tisc::assembler::disassemble(&proc_code).iter().enumerate() {
eprintln!("{} .... {}", i,l);
}
linker.add_procedure(path.as_str(), proc_code);
}
Err( (region, parse_error) ) => {

1
ltcc/test.lt Normal file
View file

@ -0,0 +1 @@

BIN
ltcc/test.lt.o Normal file

Binary file not shown.