moving to desktop (broken rn)

This commit is contained in:
2025-04-25 15:10:36 -04:00
parent 5adca32dd4
commit 3bf821d6b1
6 changed files with 41 additions and 8 deletions

View File

@@ -0,0 +1,3 @@
pub enum Instruction {
}

View File

@@ -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

View File

@@ -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,
}
}
}

View File

@@ -0,0 +1 @@
pub struct Import(pub String);

View File

@@ -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 {