had a conversation w the code
This commit is contained in:
@@ -15,14 +15,7 @@ impl Node<PVarDef> {
|
||||
None => Type::Infer,
|
||||
};
|
||||
Some(VarInst {
|
||||
id: program.def_searchable(
|
||||
name,
|
||||
Some(UVar {
|
||||
ty,
|
||||
parent: None,
|
||||
origin: self.span,
|
||||
}),
|
||||
),
|
||||
id: program.def_searchable(name, Some(UVar { ty, parent: None }), self.span),
|
||||
span: self.span,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ impl FnLowerable for PExpr {
|
||||
format!("string \"{}\"", s.replace("\n", "\\n")),
|
||||
Some(UData {
|
||||
ty: Type::Bits(8).arr(data.len() as u32),
|
||||
origin: l.span,
|
||||
content: data,
|
||||
}),
|
||||
l.span,
|
||||
);
|
||||
ctx.push(UInstruction::LoadSlice { dest, src });
|
||||
dest
|
||||
@@ -30,9 +30,9 @@ impl FnLowerable for PExpr {
|
||||
format!("char '{c}'"),
|
||||
Some(UData {
|
||||
ty,
|
||||
origin: l.span,
|
||||
content: c.to_string().as_bytes().to_vec(),
|
||||
}),
|
||||
l.span,
|
||||
);
|
||||
ctx.push(UInstruction::LoadData { dest, src });
|
||||
dest
|
||||
@@ -45,9 +45,9 @@ impl FnLowerable for PExpr {
|
||||
format!("num {n:?}"),
|
||||
Some(UData {
|
||||
ty,
|
||||
origin: l.span,
|
||||
content: n.whole.parse::<i64>().unwrap().to_le_bytes().to_vec(),
|
||||
}),
|
||||
l.span
|
||||
);
|
||||
ctx.push(UInstruction::LoadData { dest, src });
|
||||
dest
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
use super::{CompilerMsg, CompilerOutput, FileSpan, FnLowerable, Node, PFunction};
|
||||
use crate::{
|
||||
ir::{
|
||||
FieldRef, FnID, Idents, InstrIter, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar,
|
||||
VarInst,
|
||||
},
|
||||
ir::{FieldRef, FnID, Idents, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar, VarInst},
|
||||
parser,
|
||||
};
|
||||
|
||||
@@ -22,17 +19,7 @@ impl PFunction {
|
||||
pub fn lower_name(&self, p: &mut UProgram) -> Option<FnID> {
|
||||
let header = self.header.as_ref()?;
|
||||
let name = header.name.as_ref()?;
|
||||
let id = p.def_searchable(name.to_string(), None);
|
||||
let var = p.def_searchable(
|
||||
name.to_string(),
|
||||
Some(UVar {
|
||||
parent: None,
|
||||
ty: Type::Placeholder,
|
||||
origin: self.header.span,
|
||||
}),
|
||||
);
|
||||
p.fn_map.insert(var, id);
|
||||
p.inv_fn_map.push(var);
|
||||
let id = p.def_searchable(name.to_string(), None, self.header.span);
|
||||
Some(id)
|
||||
}
|
||||
pub fn lower(&self, id: FnID, p: &mut UProgram, output: &mut CompilerOutput) {
|
||||
@@ -63,15 +50,13 @@ impl PFunction {
|
||||
span: src.span,
|
||||
});
|
||||
}
|
||||
let origin = self.header.span;
|
||||
let instructions = ctx.instructions;
|
||||
let f = UFunc {
|
||||
origin,
|
||||
args,
|
||||
ret,
|
||||
instructions,
|
||||
};
|
||||
p.expect_mut(p.inv_fn_map[id.0]).ty = f.ty(p);
|
||||
p.expect_mut(p.fn_var.var(id)).ty = f.ty(p);
|
||||
p.write(id, f)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ impl PStruct {
|
||||
let generics = self
|
||||
.generics
|
||||
.iter()
|
||||
.flat_map(|a| a.as_ref()?.lower(p))
|
||||
.flat_map(|a| a.lower(p))
|
||||
.collect();
|
||||
let fields = match &self.fields {
|
||||
PStructFields::Named(nodes) => nodes
|
||||
@@ -75,14 +75,7 @@ impl PStruct {
|
||||
.into_iter()
|
||||
.map(|(name, ty)| (name, StructField { ty }))
|
||||
.collect();
|
||||
p.write(
|
||||
id,
|
||||
UStruct {
|
||||
origin: span,
|
||||
generics,
|
||||
fields,
|
||||
},
|
||||
);
|
||||
p.write(id, UStruct { generics, fields });
|
||||
p.pop();
|
||||
Some(())
|
||||
}
|
||||
@@ -90,8 +83,9 @@ impl PStruct {
|
||||
|
||||
impl Node<PStruct> {
|
||||
pub fn lower_name(&self, p: &mut UProgram) -> Option<StructID> {
|
||||
let name = self.as_ref()?.name.as_ref()?.to_string();
|
||||
let id = p.def_searchable(name.to_string(), None);
|
||||
let s = self.as_ref()?;
|
||||
let name = s.name.as_ref()?.to_string();
|
||||
let id = p.def_searchable(name.to_string(), None, s.name.span);
|
||||
Some(id)
|
||||
}
|
||||
pub fn lower(&self, id: StructID, p: &mut UProgram, output: &mut CompilerOutput) {
|
||||
|
||||
@@ -43,11 +43,10 @@ impl PType {
|
||||
}
|
||||
}
|
||||
|
||||
impl PGenericDef {
|
||||
impl Node<PGenericDef> {
|
||||
pub fn lower(&self, p: &mut UProgram) -> Option<GenericID> {
|
||||
let Some(name) = self.name.as_ref() else {
|
||||
return None;
|
||||
};
|
||||
Some(p.def_searchable(name.to_string(), Some(UGeneric {})))
|
||||
let s = self.as_ref()?;
|
||||
let name = s.name.as_ref()?;
|
||||
Some(p.def_searchable(name.to_string(), Some(UGeneric {}), self.span))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user