nac3core: style

This commit is contained in:
ychenfo 2022-02-07 02:18:56 +08:00
parent 6f9f455152
commit d6ab73afb0

View File

@ -90,65 +90,64 @@ pub fn gen_assign<'ctx, 'a, G: CodeGenerator>(
target: &Expr<Option<Type>>, target: &Expr<Option<Type>>,
value: ValueEnum<'ctx>, value: ValueEnum<'ctx>,
) { ) {
if let ExprKind::Tuple { elts, .. } = &target.node { match &target.node {
if let BasicValueEnum::StructValue(v) = value.to_basic_value_enum(ctx, generator) { ExprKind::Tuple { elts, .. } => {
for (i, elt) in elts.iter().enumerate() { if let BasicValueEnum::StructValue(v) = value.to_basic_value_enum(ctx, generator) {
let v = ctx for (i, elt) in elts.iter().enumerate() {
.builder let v = ctx
.build_extract_value(v, u32::try_from(i).unwrap(), "struct_elem") .builder
.unwrap(); .build_extract_value(v, u32::try_from(i).unwrap(), "struct_elem")
generator.gen_assign(ctx, elt, v.into()); .unwrap();
generator.gen_assign(ctx, elt, v.into());
}
} else {
unreachable!()
} }
} else {
unreachable!()
} }
} else { ExprKind::Subscript { value: ls, slice, .. }
match &target.node { if matches!(&slice.node, ExprKind::Slice { .. }) =>
ExprKind::Subscript { value: ls, slice, .. } {
if matches!(&slice.node, ExprKind::Slice { .. }) => if let ExprKind::Slice { lower, upper, step } = &slice.node {
{ let ls = generator
if let ExprKind::Slice { lower, upper, step } = &slice.node { .gen_expr(ctx, ls)
let ls = generator .unwrap()
.gen_expr(ctx, ls) .to_basic_value_enum(ctx, generator)
.unwrap() .into_pointer_value();
.to_basic_value_enum(ctx, generator) let (start, end, step) =
.into_pointer_value(); handle_slice_indices(lower, upper, step, ctx, generator, ls);
let (start, end, step) = let value = value.to_basic_value_enum(ctx, generator).into_pointer_value();
handle_slice_indices(lower, upper, step, ctx, generator, ls); let ty = if let TypeEnum::TList { ty } =
let value = value.to_basic_value_enum(ctx, generator).into_pointer_value(); &*ctx.unifier.get_ty(target.custom.unwrap())
let ty = if let TypeEnum::TList { ty } = {
&*ctx.unifier.get_ty(target.custom.unwrap()) ctx.get_llvm_type(generator, *ty)
{
ctx.get_llvm_type(generator, *ty)
} else {
unreachable!()
};
let src_ind = handle_slice_indices(&None, &None, &None, ctx, generator, value);
list_slice_assignment(
ctx,
generator.get_size_type(ctx.ctx),
ty,
ls,
(start, end, step),
value,
src_ind,
)
} else { } else {
unreachable!() unreachable!()
};
let src_ind = handle_slice_indices(&None, &None, &None, ctx, generator, value);
list_slice_assignment(
ctx,
generator.get_size_type(ctx.ctx),
ty,
ls,
(start, end, step),
value,
src_ind,
)
} else {
unreachable!()
}
}
_ => {
let ptr = generator.gen_store_target(ctx, target);
if let ExprKind::Name { id, .. } = &target.node {
let (_, static_value, counter) = ctx.var_assignment.get_mut(id).unwrap();
*counter += 1;
if let ValueEnum::Static(s) = &value {
*static_value = Some(s.clone());
} }
} }
_ => { let val = value.to_basic_value_enum(ctx, generator);
let ptr = generator.gen_store_target(ctx, target); ctx.builder.build_store(ptr, val);
if let ExprKind::Name { id, .. } = &target.node {
let (_, static_value, counter) = ctx.var_assignment.get_mut(id).unwrap();
*counter += 1;
if let ValueEnum::Static(s) = &value {
*static_value = Some(s.clone());
}
}
let val = value.to_basic_value_enum(ctx, generator);
ctx.builder.build_store(ptr, val);
}
} }
} }
} }