Compare commits

..

No commits in common. "c07e488f48f773a22153a33830ea6eb37ea73810" and "9a4f0dc5d867285a69e9f61e3d381577e0e736fe" have entirely different histories.

3 changed files with 13 additions and 25 deletions

View File

@ -65,7 +65,6 @@ pub struct StackValue(StackValueKind, Type);
pub enum StackValueKind {
Immutable(InstructionValue),
Mutable(InstructionValue),
Any(InstructionValue),
}
impl StackValueKind {
@ -73,7 +72,6 @@ impl StackValueKind {
match self {
StackValueKind::Immutable(val) => val,
StackValueKind::Mutable(val) => val,
StackValueKind::Any(val) => val,
}
}
@ -81,7 +79,6 @@ impl StackValueKind {
match self {
StackValueKind::Immutable(_) => StackValueKind::Immutable(instr),
StackValueKind::Mutable(_) => StackValueKind::Mutable(instr),
StackValueKind::Any(_) => StackValueKind::Any(instr),
}
}
}
@ -113,7 +110,7 @@ impl<'ctx, 'a> Scope<'ctx, 'a> {
}
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Copy)]
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Default, Clone, Copy)]
struct State {
should_load: bool,
}
@ -127,12 +124,6 @@ impl State {
}
}
impl Default for State {
fn default() -> Self {
Self { should_load: true }
}
}
impl mir::Module {
fn codegen<'ctx>(&self, context: &'ctx Context) -> ModuleCodegen<'ctx> {
let mut module = context.module(&self.name, self.is_main);
@ -222,8 +213,8 @@ impl mir::Module {
};
match &mir_function.kind {
mir::FunctionDefinitionKind::Local(block, _) => {
let state = State::default();
if let Some(ret) = block.codegen(&mut scope, &state) {
let mut state = State::default();
if let Some(ret) = block.codegen(&mut scope, &mut state) {
scope.block.terminate(Term::Ret(ret)).unwrap();
} else {
if !scope.block.delete_if_unused().unwrap() {
@ -254,7 +245,7 @@ impl mir::Block {
if let Some((kind, expr)) = &self.return_expression {
match kind {
mir::ReturnKind::Hard => {
let ret = expr.codegen(&mut scope, &state)?;
let ret = expr.codegen(&mut scope, &mut state.load(true))?;
scope.block.terminate(Term::Ret(ret)).unwrap();
None
}
@ -274,7 +265,7 @@ impl mir::Statement {
) -> Option<InstructionValue> {
match &self.0 {
mir::StmtKind::Let(NamedVariableRef(ty, name, _), mutable, expression) => {
let value = expression.codegen(scope, &state).unwrap();
let value = expression.codegen(scope, &state.load(true)).unwrap();
scope.stack_values.insert(
name.clone(),
StackValue(
@ -311,7 +302,7 @@ impl mir::Statement {
}
mir::StmtKind::Set(lhs, rhs) => {
let lhs_value = lhs
.codegen(scope, &state.load(false))
.codegen(scope, &mut state.load(false))
.expect("non-returning LHS snuck into codegen!");
let rhs_value = rhs.codegen(scope, state)?;
@ -355,7 +346,6 @@ impl mir::Expression {
val
}
}
_ => panic!("Found an unknown-mutable variable!"),
})
}
mir::ExprKind::Literal(lit) => Some(lit.as_const(&mut scope.block)),
@ -425,11 +415,12 @@ impl mir::Expression {
}
}
mir::ExprKind::Indexed(expression, val_t, idx_expr) => {
dbg!(&expression, &idx_expr);
let array = expression
.codegen(scope, &state.load(true))
.codegen(scope, state)
.expect("array returned none!");
let idx = idx_expr
.codegen(scope, &state.load(true))
.codegen(scope, state)
.expect("index returned none!");
let mut ptr = scope
@ -497,8 +488,6 @@ impl mir::Expression {
let TypeDefinitionKind::Struct(struct_ty) = scope.get_typedef(&name).unwrap();
let idx = struct_ty.find_index(field).unwrap();
dbg!(&scope.context);
dbg!(&struct_val);
let mut value = scope
.block
.build(Instr::GetStructElemPtr(struct_val, idx as u32))

View File

@ -1,14 +1,13 @@
// Arithmetic, function calls and imports!
fn array() -> [[[u16; 4];1];1] {
return [[[10, 15, 7, 9]]];
fn array() -> [u16; 4] {
return [10, 15, 7, 9];
}
fn main() -> u16 {
let mut list = array();
list[0][0][2] = 19;
let a = 1;
return list[0][0][a + 1];
return list[a + 1];
}

View File

@ -19,5 +19,5 @@ fn main() -> u32 {
let mut b = value[val1];
b.second[2] = 99;
return value[val1].second[2];
return value[0].second[2];
}