huge refactor, can now define structs out of order

This commit is contained in:
2025-04-11 01:57:10 -04:00
parent f6a6761262
commit 31c16a263b
24 changed files with 765 additions and 566 deletions

View File

@@ -1,25 +1,25 @@
use crate::ir::IRUProgram;
use crate::ir::UProgram;
use super::{PModule, CompilerOutput};
use super::{CompilerOutput, PModule};
impl PModule {
pub fn lower(&self, p: &mut IRUProgram, output: &mut CompilerOutput) {
pub fn lower(&self, p: &mut UProgram, output: &mut CompilerOutput) {
let mut structs = Vec::new();
for s in &self.structs {
s.lower(p, output);
structs.push(s.lower_name(p));
}
for (s, id) in self.structs.iter().zip(structs) {
if let Some(id) = id {
s.lower(id, p, output);
}
}
let mut fns = Vec::new();
for f in &self.functions {
if let Some(id) = f.lower_header(p, output) {
fns.push(Some(id));
} else {
fns.push(None)
}
fns.push(f.lower_name(p));
}
for (f, id) in self.functions.iter().zip(fns) {
if let Some(id) = id {
if let Some(res) = f.lower_body(id, p, output) {
p.write_fn(id, res);
}
f.lower(id, p, output)
}
}
}