getting closer
This commit is contained in:
@@ -3,7 +3,7 @@ use crate::{
|
||||
compiler::arch::riscv::*,
|
||||
ir::{
|
||||
arch::riscv64::{RV64Instruction, RegRef},
|
||||
VarInst,
|
||||
UIdent,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -166,7 +166,7 @@ impl RV64Instruction {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn arg_to_var(node: &Node<PAsmArg>, ctx: &mut FnLowerCtx) -> Option<VarInst> {
|
||||
pub fn arg_to_var(node: &Node<PAsmArg>, ctx: &mut FnLowerCtx) -> Option<UIdent> {
|
||||
let PAsmArg::Ref(node) = node.inner.as_ref()? else {
|
||||
ctx.err_at(
|
||||
node.origin,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
use crate::{
|
||||
compiler::arch::riscv::Reg,
|
||||
ir::{
|
||||
arch::riscv64::RV64Instruction, AsmBlockArg, AsmBlockArgType, Type, UInstruction, VarInst,
|
||||
VarInstID,
|
||||
arch::riscv64::RV64Instruction, AsmBlockArg, AsmBlockArgType, Type, UInstruction, UIdent,
|
||||
IdentID,
|
||||
},
|
||||
parser::PAsmBlockArg,
|
||||
};
|
||||
|
||||
use super::{FnLowerCtx, FnLowerable, PAsmBlock, PInstruction, PUAsmBlockArg};
|
||||
|
||||
type PLAsmBlockArg = PAsmBlockArg<Reg, VarInstID>;
|
||||
type PLAsmBlockArg = PAsmBlockArg<Reg, IdentID>;
|
||||
|
||||
impl FnLowerable for PInstruction {
|
||||
type Output = RV64Instruction;
|
||||
@@ -20,7 +20,7 @@ impl FnLowerable for PInstruction {
|
||||
}
|
||||
|
||||
impl FnLowerable for PAsmBlock {
|
||||
type Output = VarInstID;
|
||||
type Output = IdentID;
|
||||
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<Self::Output> {
|
||||
let mut args = Vec::new();
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
use crate::{
|
||||
ir::{Type, UInstruction, UVar, VarInst, VarInstID},
|
||||
ir::{Type, UInstruction, UVar, UIdent, IdentID},
|
||||
parser::{PConstStatement, PStatementLike},
|
||||
};
|
||||
|
||||
use super::{FnLowerCtx, FnLowerable, Import, PBlock, PStatement};
|
||||
|
||||
impl FnLowerable for PBlock {
|
||||
type Output = VarInstID;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarInstID> {
|
||||
type Output = IdentID;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<IdentID> {
|
||||
let mut last = None;
|
||||
let mut statements = Vec::new();
|
||||
let mut fn_nodes = Vec::new();
|
||||
@@ -74,8 +74,8 @@ impl FnLowerable for PBlock {
|
||||
}
|
||||
|
||||
impl FnLowerable for PStatement {
|
||||
type Output = VarInst;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarInst> {
|
||||
type Output = UIdent;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<UIdent> {
|
||||
match self {
|
||||
PStatement::Let(def, e) => {
|
||||
let def = def.lower(ctx.b, ctx.output)?;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::ir::{UProgram, UVar, VarID, VarInst};
|
||||
use crate::ir::{UProgram, UVar, VarID, UIdent};
|
||||
|
||||
use super::{CompilerOutput, Node, PVarDef};
|
||||
|
||||
@@ -10,7 +10,7 @@ impl Node<PVarDef> {
|
||||
Some(ty) => ty.lower(program, output),
|
||||
None => program.infer(self.origin),
|
||||
};
|
||||
Some(VarInst {
|
||||
Some(UIdent {
|
||||
id: program.def_searchable(name, Some(UVar { ty }), self.origin),
|
||||
origin: self.origin,
|
||||
})
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use super::{func::FnLowerCtx, FnLowerable, PExpr, PostfixOp};
|
||||
use crate::{
|
||||
ir::{Type, UData, UInstruction, VarInst, VarInstID},
|
||||
ir::{Type, UData, UInstruction, UIdent, IdentID},
|
||||
parser::InfixOp,
|
||||
};
|
||||
|
||||
impl FnLowerable for PExpr {
|
||||
type Output = VarInstID;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<VarInstID> {
|
||||
type Output = IdentID;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<IdentID> {
|
||||
let mut e = self;
|
||||
let mut path = Vec::new();
|
||||
while let PExpr::Member(node, ident) = e {
|
||||
|
||||
@@ -7,7 +7,7 @@ use super::{CompilerMsg, CompilerOutput, FileSpan, FnLowerable, Imports, Node, P
|
||||
use crate::{
|
||||
ir::{
|
||||
FnID, GenericID, ModPath, Origin, Typable, Type, UFunc, UInstrInst, UInstruction,
|
||||
UModuleBuilder, VarID, VarInst, VarInstID, VarStatus,
|
||||
UModuleBuilder, VarID, UIdent, IdentID, IdentStatus,
|
||||
},
|
||||
parser,
|
||||
util::NameStack,
|
||||
@@ -68,7 +68,7 @@ impl PFunction {
|
||||
let res = self.body.lower(&mut ctx);
|
||||
let mut instructions = ctx.instructions;
|
||||
if let Some(src) = res {
|
||||
let origin = b.vars_insts[src].origin;
|
||||
let origin = b.idents[src].origin;
|
||||
instructions.push(UInstrInst {
|
||||
origin,
|
||||
i: UInstruction::Ret { src },
|
||||
@@ -99,13 +99,13 @@ pub struct FnLowerCtx<'a, 'b> {
|
||||
}
|
||||
|
||||
impl<'a, 'b> FnLowerCtx<'a, 'b> {
|
||||
pub fn var(&mut self, node: &Node<parser::PIdent>) -> VarInstID {
|
||||
let inst = VarInst {
|
||||
pub fn var(&mut self, node: &Node<parser::PIdent>) -> IdentID {
|
||||
let inst = UIdent {
|
||||
status: if let Some(n) = node.as_ref() {
|
||||
if let Some(&var) = self.var_stack.search(&n.0) {
|
||||
VarStatus::Var(var)
|
||||
IdentStatus::Var(var)
|
||||
} else {
|
||||
VarStatus::Unres {
|
||||
IdentStatus::Unres {
|
||||
path: ModPath {
|
||||
id: self.b.module,
|
||||
path: Vec::new(),
|
||||
@@ -116,7 +116,7 @@ impl<'a, 'b> FnLowerCtx<'a, 'b> {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
VarStatus::Cooked
|
||||
IdentStatus::Cooked
|
||||
},
|
||||
origin: node.origin,
|
||||
};
|
||||
@@ -128,7 +128,7 @@ impl<'a, 'b> FnLowerCtx<'a, 'b> {
|
||||
pub fn err_at(&mut self, span: FileSpan, msg: String) {
|
||||
self.output.err(CompilerMsg::new(msg, span))
|
||||
}
|
||||
pub fn temp<T: Typable>(&mut self, ty: T) -> VarInstID {
|
||||
pub fn temp<T: Typable>(&mut self, ty: T) -> IdentID {
|
||||
self.b.temp_var(self.origin, ty)
|
||||
}
|
||||
pub fn push(&mut self, i: UInstruction) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{ir::VarInstID, parser::PMap};
|
||||
use crate::{ir::IdentID, parser::PMap};
|
||||
|
||||
use super::{FnLowerCtx, FnLowerable};
|
||||
|
||||
impl FnLowerable for PMap {
|
||||
type Output = HashMap<String, VarInstID>;
|
||||
type Output = HashMap<String, IdentID>;
|
||||
fn lower(&self, ctx: &mut FnLowerCtx) -> Option<Self::Output> {
|
||||
Some(
|
||||
self.0
|
||||
|
||||
Reference in New Issue
Block a user