From 3bf821d6b187f689aec00cef626e1884551d6211 Mon Sep 17 00:00:00 2001 From: Shadow Cat Date: Fri, 25 Apr 2025 15:10:36 -0400 Subject: [PATCH] moving to desktop (broken rn) --- ideas | 17 +++++++++++++++++ src/compiler/instruction.rs | 3 +++ src/parser/v3/lower/block.rs | 15 +++++++++++---- src/parser/v3/lower/func.rs | 11 +++++++---- src/parser/v3/lower/import.rs | 1 + src/parser/v3/lower/mod.rs | 2 ++ 6 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 ideas create mode 100644 src/compiler/instruction.rs create mode 100644 src/parser/v3/lower/import.rs diff --git a/ideas b/ideas new file mode 100644 index 0000000..e354e14 --- /dev/null +++ b/ideas @@ -0,0 +1,17 @@ +struct + +Type + structinst + bits + +but type is already typeinst? + +for each var, create list of constraints on type + then just need to iterate through constraints to determine type + keep doing passes for vars that depend on the type of other vars + really need to make subvar for each field of struct var so 2 different "a.b" refer to same thing + makes borrow checking easier + do dependency cycles exist? + for global vars yes, in functions no + but if function returns are inferrable (even if just "impl Trait"), then needed in functions? +every kind has an origin, should make separate like names? diff --git a/src/compiler/instruction.rs b/src/compiler/instruction.rs new file mode 100644 index 0000000..053701f --- /dev/null +++ b/src/compiler/instruction.rs @@ -0,0 +1,3 @@ +pub enum Instruction { + +} diff --git a/src/parser/v3/lower/block.rs b/src/parser/v3/lower/block.rs index 14b6e74..916efd0 100644 --- a/src/parser/v3/lower/block.rs +++ b/src/parser/v3/lower/block.rs @@ -3,7 +3,7 @@ use crate::{ parser::{PConstStatement, PStatementLike}, }; -use super::{FnLowerCtx, FnLowerable, PBlock, PStatement}; +use super::{import::Import, FnLowerCtx, FnLowerable, PBlock, PStatement}; impl FnLowerable for PBlock { type Output = VarInst; @@ -13,7 +13,7 @@ impl FnLowerable for PBlock { let mut statements = Vec::new(); let mut fn_nodes = Vec::new(); let mut struct_nodes = Vec::new(); - let mut imports = Vec::new(); + let mut import_nodes = Vec::new(); // first sort statements for s in &self.statements { let Some(s) = s.as_ref() else { @@ -24,10 +24,17 @@ impl FnLowerable for PBlock { PStatementLike::Const(pconst_statement) => match pconst_statement { PConstStatement::Fn(f) => fn_nodes.push(f), PConstStatement::Struct(s) => struct_nodes.push(s), - PConstStatement::Import(i) => imports.push(i), + PConstStatement::Import(i) => import_nodes.push(i), }, } } + // then lower imports + for i in &import_nodes { + if let Some(i) = i.as_ref() { + let import = Import(i.0.clone()); + ctx.imports.push(import); + } + } // then lower const things let mut structs = Vec::new(); for s in &struct_nodes { @@ -44,7 +51,7 @@ impl FnLowerable for PBlock { } for (f, id) in fn_nodes.iter().zip(fns) { if let Some(id) = id { - f.lower(id, ctx.program, ctx.output) + f.lower(id, ctx.program, ctx.imports, ctx.output) } } // then lower statements diff --git a/src/parser/v3/lower/func.rs b/src/parser/v3/lower/func.rs index 1828507..cbb4206 100644 --- a/src/parser/v3/lower/func.rs +++ b/src/parser/v3/lower/func.rs @@ -1,4 +1,4 @@ -use super::{CompilerMsg, CompilerOutput, FileSpan, FnLowerable, Node, PFunction}; +use super::{import::Import, CompilerMsg, CompilerOutput, FileSpan, FnLowerable, Node, PFunction}; use crate::{ ir::{FieldRef, FnID, Idents, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar, VarInst}, parser, @@ -8,9 +8,9 @@ impl Node { pub fn lower_name(&self, p: &mut UProgram) -> Option { self.as_ref()?.lower_name(p) } - pub fn lower(&self, id: FnID, p: &mut UProgram, output: &mut CompilerOutput) { + pub fn lower(&self, id: FnID, p: &mut UProgram, imports: &mut Vec, output: &mut CompilerOutput) { if let Some(s) = self.as_ref() { - s.lower(id, p, output) + s.lower(id, p, imports, output) } } } @@ -22,7 +22,7 @@ impl PFunction { let id = p.def_searchable(name.to_string(), None, self.header.origin); Some(id) } - pub fn lower(&self, id: FnID, p: &mut UProgram, output: &mut CompilerOutput) { + pub fn lower(&self, id: FnID, p: &mut UProgram, imports: &mut Vec, output: &mut CompilerOutput) { let name = p.names.name(id).to_string(); p.push_name(&name); let (args, ret) = if let Some(header) = self.header.as_ref() { @@ -45,6 +45,7 @@ impl PFunction { program: p, output, origin: self.body.origin, + imports, }; if let Some(src) = self.body.lower(&mut ctx) { ctx.instructions.push(UInstrInst { @@ -68,6 +69,7 @@ pub struct FnLowerCtx<'a> { pub instructions: Vec, pub output: &'a mut CompilerOutput, pub origin: FileSpan, + pub imports: &'a mut Vec } impl FnLowerCtx<'_> { @@ -116,6 +118,7 @@ impl FnLowerCtx<'_> { instructions: Vec::new(), output: self.output, origin: self.origin, + imports: self.imports, } } } diff --git a/src/parser/v3/lower/import.rs b/src/parser/v3/lower/import.rs new file mode 100644 index 0000000..11bcddc --- /dev/null +++ b/src/parser/v3/lower/import.rs @@ -0,0 +1 @@ +pub struct Import(pub String); diff --git a/src/parser/v3/lower/mod.rs b/src/parser/v3/lower/mod.rs index f35c996..b749218 100644 --- a/src/parser/v3/lower/mod.rs +++ b/src/parser/v3/lower/mod.rs @@ -6,6 +6,7 @@ mod expr; mod func; mod struc; mod ty; +mod import; use super::*; use crate::ir::{Type, UFunc, UProgram}; @@ -19,6 +20,7 @@ impl PModule { instructions: Vec::new(), output, origin: self.block.origin, + imports: Vec::new(), }; self.block.lower(&mut fctx); let f = UFunc {