uh oh, I need to actually switch to struct subvars and resolve pointer variables
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
compiler::arch::riscv::Reg,
|
||||
ir::{
|
||||
arch::riscv64::RV64Instruction, AsmBlockArg, AsmBlockArgType, UInstruction, Type, VarInst,
|
||||
arch::riscv64::RV64Instruction, AsmBlockArg, AsmBlockArgType, Type, UInstruction, VarInst
|
||||
},
|
||||
parser::PAsmBlockArg,
|
||||
};
|
||||
|
||||
@@ -27,27 +27,24 @@ impl FnLowerable for PBlock {
|
||||
},
|
||||
}
|
||||
}
|
||||
ctx.program.push();
|
||||
// then lower imports
|
||||
for i_n in &import_nodes {
|
||||
if let Some(i) = i_n.as_ref() {
|
||||
let name = &i.0;
|
||||
let import = Import(ctx.program.path_for(name));
|
||||
ctx
|
||||
.imports
|
||||
.entry(import)
|
||||
.or_insert(ctx.program.def(name, None, i_n.origin));
|
||||
// I could prevent this if someone imports something twice,
|
||||
// but that doesn't seem worth it at all
|
||||
ctx.program.def_searchable::<UVar>(
|
||||
name.clone(),
|
||||
Some(UVar {
|
||||
ty: Type::Module,
|
||||
}),
|
||||
i_n.origin,
|
||||
);
|
||||
let path = ctx.program.path_for(name);
|
||||
let import = Import(path.clone());
|
||||
if ctx.imports.insert(import) {
|
||||
ctx.program.def_searchable::<UVar>(
|
||||
name,
|
||||
Some(UVar {
|
||||
ty: Type::Module(path),
|
||||
}),
|
||||
i_n.origin,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx.program.push();
|
||||
// then lower const things
|
||||
let mut structs = Vec::new();
|
||||
for s in &struct_nodes {
|
||||
|
||||
@@ -8,8 +8,7 @@ impl Node<PVarDef> {
|
||||
let name = s
|
||||
.name
|
||||
.as_ref()
|
||||
.map(|n| n.to_string())
|
||||
.unwrap_or("{error}".to_string());
|
||||
.map_or("{error}", |v| v);
|
||||
let ty = match &s.ty {
|
||||
Some(ty) => ty.lower(program, output),
|
||||
None => Type::Infer,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{func::FnLowerCtx, FnLowerable, PExpr, UnaryOp};
|
||||
use crate::{
|
||||
ir::{MemberRef, Type, UData, UInstruction, VarInst},
|
||||
ir::{FieldRef, Type, UData, UInstruction, VarInst},
|
||||
parser::PInfixOp,
|
||||
};
|
||||
|
||||
@@ -40,7 +40,7 @@ impl FnLowerable for PExpr {
|
||||
super::PLiteral::Number(n) => {
|
||||
// TODO: temp
|
||||
let ty = Type::Bits(64);
|
||||
let dest = ctx.program.temp_var(l.origin, Type::Bits(64));
|
||||
let dest = ctx.program.temp_var(l.origin, ty.clone());
|
||||
let src = ctx.program.def(
|
||||
&format!("num {n:?}"),
|
||||
Some(UData {
|
||||
@@ -69,7 +69,7 @@ impl FnLowerable for PExpr {
|
||||
return None;
|
||||
};
|
||||
let fname = ident.as_ref()?.0.clone();
|
||||
ctx.temp(Type::Member(MemberRef {
|
||||
ctx.temp(Type::Field(FieldRef {
|
||||
parent: res1.id,
|
||||
name: fname,
|
||||
}))
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::{Imports, CompilerMsg, CompilerOutput, FileSpan, FnLowerable, Node, PFunction};
|
||||
use super::{CompilerMsg, CompilerOutput, FileSpan, FnLowerable, Imports, Node, PFunction};
|
||||
use crate::{
|
||||
ir::{MemberRef, FnID, Idents, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar, VarInst},
|
||||
ir::{FnID, Idents, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar, VarInst},
|
||||
parser,
|
||||
};
|
||||
|
||||
@@ -25,7 +25,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, self.header.origin);
|
||||
let id = p.def_searchable(name, None, self.header.origin);
|
||||
Some(id)
|
||||
}
|
||||
pub fn lower(
|
||||
@@ -112,7 +112,7 @@ impl FnLowerCtx<'_> {
|
||||
pub fn err_at(&mut self, span: FileSpan, msg: String) {
|
||||
self.output.err(CompilerMsg::from_span(span, msg))
|
||||
}
|
||||
pub fn temp(&mut self, ty: Type) -> VarInst {
|
||||
pub fn temp(&mut self, ty: impl Into<Type>) -> VarInst {
|
||||
self.program.temp_var(self.origin, ty)
|
||||
}
|
||||
pub fn push(&mut self, i: UInstruction) {
|
||||
|
||||
@@ -13,12 +13,14 @@ use crate::ir::{Type, UFunc, UProgram};
|
||||
impl PModule {
|
||||
pub fn lower(
|
||||
&self,
|
||||
name: String,
|
||||
path: Vec<String>,
|
||||
p: &mut UProgram,
|
||||
imports: &mut Imports,
|
||||
output: &mut CompilerOutput,
|
||||
) {
|
||||
let fid = p.def_searchable(name.clone(), None, self.block.origin);
|
||||
let name = path.last().unwrap().clone();
|
||||
p.set_module(path);
|
||||
let fid = p.def_searchable(&name, None, self.block.origin);
|
||||
p.push_name(&name);
|
||||
let mut fctx = FnLowerCtx {
|
||||
program: p,
|
||||
|
||||
@@ -46,11 +46,7 @@ impl PStruct {
|
||||
span: FileSpan,
|
||||
) -> Option<()> {
|
||||
p.push();
|
||||
let generics = self
|
||||
.generics
|
||||
.iter()
|
||||
.flat_map(|a| a.lower(p))
|
||||
.collect();
|
||||
let generics = self.generics.iter().flat_map(|a| a.lower(p)).collect();
|
||||
let fields = match &self.fields {
|
||||
PStructFields::Named(nodes) => nodes
|
||||
.iter()
|
||||
@@ -84,8 +80,8 @@ impl PStruct {
|
||||
impl Node<PStruct> {
|
||||
pub fn lower_name(&self, p: &mut UProgram) -> Option<StructID> {
|
||||
let s = self.as_ref()?;
|
||||
let name = s.name.as_ref()?.to_string();
|
||||
let id = p.def_searchable(name.to_string(), None, s.name.origin);
|
||||
let name = s.name.as_ref()?;
|
||||
let id = p.def_searchable(name, None, s.name.origin);
|
||||
Some(id)
|
||||
}
|
||||
pub fn lower(&self, id: StructID, p: &mut UProgram, output: &mut CompilerOutput) {
|
||||
|
||||
@@ -47,6 +47,6 @@ impl Node<PGenericDef> {
|
||||
pub fn lower(&self, p: &mut UProgram) -> Option<GenericID> {
|
||||
let s = self.as_ref()?;
|
||||
let name = s.name.as_ref()?;
|
||||
Some(p.def_searchable(name.to_string(), Some(UGeneric {}), self.origin))
|
||||
Some(p.def_searchable(name, Some(UGeneric {}), self.origin))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user