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},
|
parser::{PConstStatement, PStatementLike},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{FnLowerCtx, FnLowerable, PBlock, PStatement};
|
use super::{import::Import, FnLowerCtx, FnLowerable, PBlock, PStatement};
|
||||||
|
|
||||||
impl FnLowerable for PBlock {
|
impl FnLowerable for PBlock {
|
||||||
type Output = VarInst;
|
type Output = VarInst;
|
||||||
@@ -13,7 +13,7 @@ impl FnLowerable for PBlock {
|
|||||||
let mut statements = Vec::new();
|
let mut statements = Vec::new();
|
||||||
let mut fn_nodes = Vec::new();
|
let mut fn_nodes = Vec::new();
|
||||||
let mut struct_nodes = Vec::new();
|
let mut struct_nodes = Vec::new();
|
||||||
let mut imports = Vec::new();
|
let mut import_nodes = Vec::new();
|
||||||
// first sort statements
|
// first sort statements
|
||||||
for s in &self.statements {
|
for s in &self.statements {
|
||||||
let Some(s) = s.as_ref() else {
|
let Some(s) = s.as_ref() else {
|
||||||
@@ -24,10 +24,17 @@ impl FnLowerable for PBlock {
|
|||||||
PStatementLike::Const(pconst_statement) => match pconst_statement {
|
PStatementLike::Const(pconst_statement) => match pconst_statement {
|
||||||
PConstStatement::Fn(f) => fn_nodes.push(f),
|
PConstStatement::Fn(f) => fn_nodes.push(f),
|
||||||
PConstStatement::Struct(s) => struct_nodes.push(s),
|
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
|
// then lower const things
|
||||||
let mut structs = Vec::new();
|
let mut structs = Vec::new();
|
||||||
for s in &struct_nodes {
|
for s in &struct_nodes {
|
||||||
@@ -44,7 +51,7 @@ impl FnLowerable for PBlock {
|
|||||||
}
|
}
|
||||||
for (f, id) in fn_nodes.iter().zip(fns) {
|
for (f, id) in fn_nodes.iter().zip(fns) {
|
||||||
if let Some(id) = id {
|
if let Some(id) = id {
|
||||||
f.lower(id, ctx.program, ctx.output)
|
f.lower(id, ctx.program, ctx.imports, ctx.output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// then lower statements
|
// 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::{
|
use crate::{
|
||||||
ir::{FieldRef, FnID, Idents, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar, VarInst},
|
ir::{FieldRef, FnID, Idents, Type, UFunc, UInstrInst, UInstruction, UProgram, UVar, VarInst},
|
||||||
parser,
|
parser,
|
||||||
@@ -8,9 +8,9 @@ impl Node<PFunction> {
|
|||||||
pub fn lower_name(&self, p: &mut UProgram) -> Option<FnID> {
|
pub fn lower_name(&self, p: &mut UProgram) -> Option<FnID> {
|
||||||
self.as_ref()?.lower_name(p)
|
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() {
|
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);
|
let id = p.def_searchable(name.to_string(), None, self.header.origin);
|
||||||
Some(id)
|
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();
|
let name = p.names.name(id).to_string();
|
||||||
p.push_name(&name);
|
p.push_name(&name);
|
||||||
let (args, ret) = if let Some(header) = self.header.as_ref() {
|
let (args, ret) = if let Some(header) = self.header.as_ref() {
|
||||||
@@ -45,6 +45,7 @@ impl PFunction {
|
|||||||
program: p,
|
program: p,
|
||||||
output,
|
output,
|
||||||
origin: self.body.origin,
|
origin: self.body.origin,
|
||||||
|
imports,
|
||||||
};
|
};
|
||||||
if let Some(src) = self.body.lower(&mut ctx) {
|
if let Some(src) = self.body.lower(&mut ctx) {
|
||||||
ctx.instructions.push(UInstrInst {
|
ctx.instructions.push(UInstrInst {
|
||||||
@@ -68,6 +69,7 @@ pub struct FnLowerCtx<'a> {
|
|||||||
pub instructions: Vec<UInstrInst>,
|
pub instructions: Vec<UInstrInst>,
|
||||||
pub output: &'a mut CompilerOutput,
|
pub output: &'a mut CompilerOutput,
|
||||||
pub origin: FileSpan,
|
pub origin: FileSpan,
|
||||||
|
pub imports: &'a mut Vec<Import>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FnLowerCtx<'_> {
|
impl FnLowerCtx<'_> {
|
||||||
@@ -116,6 +118,7 @@ impl FnLowerCtx<'_> {
|
|||||||
instructions: Vec::new(),
|
instructions: Vec::new(),
|
||||||
output: self.output,
|
output: self.output,
|
||||||
origin: self.origin,
|
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 func;
|
||||||
mod struc;
|
mod struc;
|
||||||
mod ty;
|
mod ty;
|
||||||
|
mod import;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::ir::{Type, UFunc, UProgram};
|
use crate::ir::{Type, UFunc, UProgram};
|
||||||
@@ -19,6 +20,7 @@ impl PModule {
|
|||||||
instructions: Vec::new(),
|
instructions: Vec::new(),
|
||||||
output,
|
output,
|
||||||
origin: self.block.origin,
|
origin: self.block.origin,
|
||||||
|
imports: Vec::new(),
|
||||||
};
|
};
|
||||||
self.block.lower(&mut fctx);
|
self.block.lower(&mut fctx);
|
||||||
let f = UFunc {
|
let f = UFunc {
|
||||||
|
|||||||
Reference in New Issue
Block a user