Compare commits
No commits in common. "9a4f0dc5d867285a69e9f61e3d381577e0e736fe" and "d2cf97af66cf5dcba1230aaeac0948e5bf8e0685" have entirely different histories.
9a4f0dc5d8
...
d2cf97af66
@ -265,7 +265,7 @@ impl mir::Statement {
|
|||||||
) -> Option<InstructionValue> {
|
) -> Option<InstructionValue> {
|
||||||
match &self.0 {
|
match &self.0 {
|
||||||
mir::StmtKind::Let(NamedVariableRef(ty, name, _), mutable, expression) => {
|
mir::StmtKind::Let(NamedVariableRef(ty, name, _), mutable, expression) => {
|
||||||
let value = expression.codegen(scope, &state.load(true)).unwrap();
|
let value = expression.codegen(scope, state).unwrap();
|
||||||
scope.stack_values.insert(
|
scope.stack_values.insert(
|
||||||
name.clone(),
|
name.clone(),
|
||||||
StackValue(
|
StackValue(
|
||||||
@ -415,14 +415,8 @@ impl mir::Expression {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mir::ExprKind::Indexed(expression, val_t, idx_expr) => {
|
mir::ExprKind::Indexed(expression, val_t, idx_expr) => {
|
||||||
dbg!(&expression, &idx_expr);
|
let array = expression.codegen(scope, state)?;
|
||||||
let array = expression
|
let idx = idx_expr.codegen(scope, state)?;
|
||||||
.codegen(scope, state)
|
|
||||||
.expect("array returned none!");
|
|
||||||
let idx = idx_expr
|
|
||||||
.codegen(scope, state)
|
|
||||||
.expect("index returned none!");
|
|
||||||
|
|
||||||
let mut ptr = scope
|
let mut ptr = scope
|
||||||
.block
|
.block
|
||||||
.build(Instr::GetElemPtr(array, vec![idx]))
|
.build(Instr::GetElemPtr(array, vec![idx]))
|
||||||
@ -474,19 +468,14 @@ impl mir::Expression {
|
|||||||
Some(array)
|
Some(array)
|
||||||
}
|
}
|
||||||
mir::ExprKind::Accessed(expression, type_kind, field) => {
|
mir::ExprKind::Accessed(expression, type_kind, field) => {
|
||||||
let struct_val = expression.codegen(scope, &mut state.load(true)).unwrap();
|
let struct_val = expression.codegen(scope, &mut state.load(true))?;
|
||||||
|
|
||||||
let struct_ty = expression
|
let struct_ty = expression.return_type().ok()?.1.known().ok()?;
|
||||||
.return_type()
|
let TypeKind::CustomType(name) = struct_ty else {
|
||||||
.map(|r| r.1.known())
|
return None;
|
||||||
.unwrap()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let TypeKind::CustomType(name) = struct_ty.deref_borrow() else {
|
|
||||||
panic!("tried accessing non-custom-type");
|
|
||||||
};
|
};
|
||||||
let TypeDefinitionKind::Struct(struct_ty) = scope.get_typedef(&name).unwrap();
|
let TypeDefinitionKind::Struct(struct_ty) = scope.get_typedef(&name)?;
|
||||||
let idx = struct_ty.find_index(field).unwrap();
|
let idx = struct_ty.find_index(field)?;
|
||||||
|
|
||||||
let mut value = scope
|
let mut value = scope
|
||||||
.block
|
.block
|
||||||
@ -655,9 +644,6 @@ impl TypeKind {
|
|||||||
TypeDefinitionKind::Struct(_) => Type::Ptr(Box::new(custom_t)),
|
TypeDefinitionKind::Struct(_) => Type::Ptr(Box::new(custom_t)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeKind::Borrow(type_kind) => {
|
|
||||||
Type::Ptr(Box::new(type_kind.get_type(type_vals, typedefs)))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ impl Expression {
|
|||||||
Indexed(expression, _, _) => {
|
Indexed(expression, _, _) => {
|
||||||
let expr_type = expression.return_type()?;
|
let expr_type = expression.return_type()?;
|
||||||
if let (_, TypeKind::Array(elem_ty, _)) = expr_type {
|
if let (_, TypeKind::Array(elem_ty, _)) = expr_type {
|
||||||
Ok((ReturnKind::Soft, TypeKind::Borrow(Box::new(*elem_ty))))
|
Ok((ReturnKind::Soft, *elem_ty))
|
||||||
} else {
|
} else {
|
||||||
Err(ReturnTypeOther::IndexingNonArray(expression.1))
|
Err(ReturnTypeOther::IndexingNonArray(expression.1))
|
||||||
}
|
}
|
||||||
@ -165,10 +165,7 @@ impl Expression {
|
|||||||
TypeKind::Array(Box::new(first.1), expressions.len() as u64),
|
TypeKind::Array(Box::new(first.1), expressions.len() as u64),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
Accessed(_, type_kind, _) => Ok((
|
Accessed(_, type_kind, _) => Ok((ReturnKind::Soft, type_kind.clone())),
|
||||||
ReturnKind::Soft,
|
|
||||||
TypeKind::Borrow(Box::new(type_kind.clone())),
|
|
||||||
)),
|
|
||||||
Struct(name, _) => Ok((ReturnKind::Soft, TypeKind::CustomType(name.clone()))),
|
Struct(name, _) => Ok((ReturnKind::Soft, TypeKind::CustomType(name.clone()))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -270,13 +267,6 @@ impl TypeKind {
|
|||||||
_ => resolved,
|
_ => resolved,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn deref_borrow(&self) -> TypeKind {
|
|
||||||
match self {
|
|
||||||
TypeKind::Borrow(type_kind) => *type_kind.clone(),
|
|
||||||
_ => self.clone(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, thiserror::Error)]
|
#[derive(Debug, Clone, thiserror::Error)]
|
||||||
|
@ -65,8 +65,6 @@ pub enum TypeKind {
|
|||||||
StringPtr,
|
StringPtr,
|
||||||
#[error("[{0}; {1}]")]
|
#[error("[{0}; {1}]")]
|
||||||
Array(Box<TypeKind>, u64),
|
Array(Box<TypeKind>, u64),
|
||||||
#[error("Borrow({0})")]
|
|
||||||
Borrow(Box<TypeKind>),
|
|
||||||
#[error("{0}")]
|
#[error("{0}")]
|
||||||
CustomType(String),
|
CustomType(String),
|
||||||
#[error(transparent)]
|
#[error(transparent)]
|
||||||
|
@ -503,17 +503,13 @@ impl Expression {
|
|||||||
Ok((_, ty)) => Ok(ty),
|
Ok((_, ty)) => Ok(ty),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
},
|
},
|
||||||
ExprKind::Indexed(expression, elem_ty, idx_expr) => {
|
ExprKind::Indexed(expression, elem_ty, _) => {
|
||||||
// Try to unwrap hint type from array if possible
|
// Try to unwrap hint type from array if possible
|
||||||
let hint_t = hint_t.map(|t| match t {
|
let hint_t = hint_t.map(|t| match t {
|
||||||
TypeKind::Array(type_kind, _) => &type_kind,
|
TypeKind::Array(type_kind, _) => &type_kind,
|
||||||
_ => t,
|
_ => t,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Typecheck and narrow index-expression
|
|
||||||
let idx_expr_res = idx_expr.typecheck(state, typerefs, Some(&TypeKind::U32));
|
|
||||||
state.ok(idx_expr_res, idx_expr.1);
|
|
||||||
|
|
||||||
// TODO it could be possible to check length against constants..
|
// TODO it could be possible to check length against constants..
|
||||||
|
|
||||||
let expr_t = expression.typecheck(state, typerefs, hint_t)?;
|
let expr_t = expression.typecheck(state, typerefs, hint_t)?;
|
||||||
|
@ -105,7 +105,6 @@ impl Block {
|
|||||||
(var_ref.as_mut(), expr_ty_ref.as_mut())
|
(var_ref.as_mut(), expr_ty_ref.as_mut())
|
||||||
{
|
{
|
||||||
var_ref.narrow(&expr_ty_ref);
|
var_ref.narrow(&expr_ty_ref);
|
||||||
dbg!(var_ref);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StmtKind::Set(lhs, rhs) => {
|
StmtKind::Set(lhs, rhs) => {
|
||||||
@ -253,13 +252,9 @@ impl Expression {
|
|||||||
ReturnKind::Soft => Ok(block_ref.1),
|
ReturnKind::Soft => Ok(block_ref.1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ExprKind::Indexed(expression, index_ty, idx_expr) => {
|
ExprKind::Indexed(expression, index_ty, _) => {
|
||||||
let expr_ty = expression.infer_types(state, type_refs)?;
|
let expr_ty = expression.infer_types(state, type_refs)?;
|
||||||
|
|
||||||
// Infer and narrow types used for indexing
|
|
||||||
let mut idx_ty = idx_expr.infer_types(state, type_refs)?;
|
|
||||||
idx_ty.narrow(&type_refs.from_type(&U32).unwrap());
|
|
||||||
|
|
||||||
// Check that the resolved type is at least an array, no
|
// Check that the resolved type is at least an array, no
|
||||||
// need for further resolution.
|
// need for further resolution.
|
||||||
let kind = expr_ty.resolve_weak().unwrap();
|
let kind = expr_ty.resolve_weak().unwrap();
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
// Arithmetic, function calls and imports!
|
// Arithmetic, function calls and imports!
|
||||||
|
|
||||||
fn array() -> [u16; 4] {
|
fn array() -> [[[u16; 4]; 1]; 1] {
|
||||||
return [10, 15, 7, 9];
|
return [[[10, 15, 7, 9]]];
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() -> u16 {
|
fn main() -> u16 {
|
||||||
let mut list = array();
|
let mut list = array();
|
||||||
|
|
||||||
let a = 1;
|
list[0][0][3] = 5;
|
||||||
|
|
||||||
return list[a + 1];
|
return list[0][0][3];
|
||||||
}
|
}
|
||||||
|
@ -11,13 +11,7 @@ fn main() -> u32 {
|
|||||||
second: [6, 3, 17, 8],
|
second: [6, 3, 17, 8],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
let val1 = 0;
|
value[0].second[2] = 99;
|
||||||
let val2 = 1;
|
|
||||||
|
|
||||||
// value[val1].second[val2 + 1] = 99;
|
|
||||||
|
|
||||||
let mut b = value[val1];
|
|
||||||
b.second[2] = 99;
|
|
||||||
|
|
||||||
return value[0].second[2];
|
return value[0].second[2];
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user