moving to desktop (broken rn)
This commit is contained in:
17
ideas
Normal file
17
ideas
Normal file
@@ -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?
|
||||
3
src/compiler/instruction.rs
Normal file
3
src/compiler/instruction.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
pub enum Instruction {
|
||||
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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<PFunction> {
|
||||
pub fn lower_name(&self, p: &mut UProgram) -> Option<FnID> {
|
||||
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<Import>, 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<Import>, 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<UInstrInst>,
|
||||
pub output: &'a mut CompilerOutput,
|
||||
pub origin: FileSpan,
|
||||
pub imports: &'a mut Vec<Import>
|
||||
}
|
||||
|
||||
impl FnLowerCtx<'_> {
|
||||
@@ -116,6 +118,7 @@ impl FnLowerCtx<'_> {
|
||||
instructions: Vec::new(),
|
||||
output: self.output,
|
||||
origin: self.origin,
|
||||
imports: self.imports,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
src/parser/v3/lower/import.rs
Normal file
1
src/parser/v3/lower/import.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub struct Import(pub String);
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user