Skip to content

Commit

Permalink
Fix Kai's issues with my code
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoFelipe3 committed Sep 28, 2024
1 parent dc220ec commit 12d5a5d
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/algorithm/invert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ fn prim_inverse(prim: Primitive, span: usize) -> Option<Instr> {
Fix => Instr::ImplPrim(UnFix, span),
Shape => Instr::ImplPrim(UnShape, span),
Map => Instr::ImplPrim(UnMap, span),
Trace => Instr::ImplPrim(TraceN(1, true, false), span),
Trace => Instr::ImplPrim(TraceN { n: 1, inverse: true, stack_sub: false }, span),
Stack => Instr::ImplPrim(UnStack, span),
Keep => Instr::ImplPrim(UnKeep, span),
GifEncode => Instr::ImplPrim(GifDecode, span),
Expand Down Expand Up @@ -215,7 +215,7 @@ fn impl_prim_inverse(prim: ImplPrimitive, span: usize) -> Option<Instr> {
GifDecode => Instr::Prim(GifEncode, span),
AudioDecode => Instr::Prim(AudioEncode, span),
UnDatetime => Instr::Prim(DateTime, span),
TraceN(n, inverse, stack_sub) => Instr::ImplPrim(TraceN(n, !inverse, stack_sub), span),
TraceN { n, inverse, stack_sub } => Instr::ImplPrim(TraceN { n, inverse: !inverse, stack_sub }, span),
UnRawMode => Instr::Prim(Sys(SysOp::RawMode), span),
_ => return None,
})
Expand Down
2 changes: 1 addition & 1 deletion src/algorithm/reduce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn trim_instrs(mut instrs: &[Instr]) -> &[Instr] {
let trim = |instr: &Instr| {
matches!(
instr,
Instr::Prim(Stack | Trace, _) | Instr::ImplPrim(UnStack | TraceN(..), _)
Instr::Prim(Stack | Trace, _) | Instr::ImplPrim(UnStack | TraceN { .. }, _)
)
};
while instrs.first().is_some_and(trim) {
Expand Down
4 changes: 2 additions & 2 deletions src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2179,7 +2179,7 @@ code:
}
Primitive::Stack => {
let span = self.add_span(span.clone());
self.push_instr(Instr::ImplPrim(ImplPrimitive::TraceN(n, false, true), span));
self.push_instr(Instr::ImplPrim(ImplPrimitive::TraceN { n, inverse: false, stack_sub: true }, span));
}
_ => {
self.add_error(
Expand Down Expand Up @@ -2330,7 +2330,7 @@ code:
for instr in instrs {
match instr {
Instr::Prim(Trace | Dump | Stack | Assert, _) => return false,
Instr::ImplPrim(UnDump | UnStack | TraceN(..), _) => return false,
Instr::ImplPrim(UnDump | UnStack | TraceN { .. }, _) => return false,
Instr::PushFunc(f)
if !self.inlinable(f.instrs(&self.asm), FunctionFlags::default()) =>
{
Expand Down
2 changes: 1 addition & 1 deletion src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ impl Compiler {
let (mut new_func, sig) = self.compile_operand_word(operand)?;
if let [Instr::Prim(Trace, span)] = new_func.instrs.as_slice() {
finish!(
eco_vec![Instr::ImplPrim(ImplPrimitive::TraceN(n, false, false), *span)],
eco_vec![Instr::ImplPrim(ImplPrimitive::TraceN { n, inverse: false, stack_sub: false }, *span)],
Signature::new(n, n)
)
} else {
Expand Down
6 changes: 3 additions & 3 deletions src/optimize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,9 @@ pub(crate) fn optimize_instrs_mut(
([.., Instr::Prim(Trace, span)], Instr::Prim(Trace, _)) => {
let span = *span;
instrs.pop();
instrs.push(Instr::ImplPrim(TraceN(2, false, false), span));
instrs.push(Instr::ImplPrim(TraceN { n: 2, inverse: false, stack_sub: false }, span));
}
([.., Instr::ImplPrim(TraceN(n, false, _), _)], Instr::Prim(Trace, _)) => {
([.., Instr::ImplPrim(TraceN { n, inverse: false, .. }, _)], Instr::Prim(Trace, _)) => {
*n += 1;
if *n == 0 {
instrs.pop();
Expand All @@ -341,7 +341,7 @@ pub(crate) fn optimize_instrs_mut(
instrs.push(Instr::Push(val));
instrs.push(Instr::ImplPrim(ValidateTypeConsume, span));
}
([.., Instr::ImplPrim(TraceN(a, inv_a, _), _)], Instr::ImplPrim(TraceN(b, inv_b, _), _))
([.., Instr::ImplPrim(TraceN { n: a, inverse: inv_a, .. }, _)], Instr::ImplPrim(TraceN { n: b, inverse: inv_b, .. }, _))
if *inv_a == inv_b =>
{
*a += b;
Expand Down
10 changes: 5 additions & 5 deletions src/primitive/defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2956,7 +2956,7 @@ primitive!(
/// ex: [1 5 2 9 11 0 7 12 8 3]
/// : ▽×⸮≥5:⸮≤10..
(1, Trace, Debug, ("trace", '⸮'), Impure),
/// Debug print all stack values after applying a function to them without popping them
/// Preprocess and print all stack values without popping them
///
/// [dump][identity] is equivalent to [stack].
/// ex: dump∘ 1 2 3
Expand Down Expand Up @@ -3335,7 +3335,7 @@ macro_rules! impl_primitive {
UndoReverse(usize),
UndoRotate(usize),
ReduceDepth(usize),
TraceN(usize, bool, bool),
TraceN { n: usize, inverse: bool, stack_sub: bool},
}

impl ImplPrimitive {
Expand All @@ -3347,7 +3347,7 @@ macro_rules! impl_primitive {
ImplPrimitive::UndoReverse(n) => *n,
ImplPrimitive::UndoRotate(n) => *n + 1,
ImplPrimitive::ReduceDepth(_) => 1,
ImplPrimitive::TraceN(n, _, _) => *n,
ImplPrimitive::TraceN { n, .. } => *n,
}
}
pub fn outputs(&self) -> usize {
Expand All @@ -3356,7 +3356,7 @@ macro_rules! impl_primitive {
ImplPrimitive::UndoTransposeN(n, _) => *n,
ImplPrimitive::UndoReverse(n) => *n,
ImplPrimitive::UndoRotate(n) => *n,
ImplPrimitive::TraceN(n, _, _) => *n,
ImplPrimitive::TraceN { n, .. } => *n,
_ => 1
}
}
Expand All @@ -3370,7 +3370,7 @@ macro_rules! impl_primitive {
pub fn purity(&self) -> Purity {
match self {
$($(ImplPrimitive::$variant => {Purity::$purity},)*)*
ImplPrimitive::TraceN(_, _, _) => Purity::Impure,
ImplPrimitive::TraceN { .. } => Purity::Impure,
_ => Purity::Pure
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/primitive/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl fmt::Display for ImplPrimitive {
}
Ok(())
}
&TraceN(n, inverse, stack_sub) => {
&TraceN { n, inverse, stack_sub } => {
if inverse {
write!(f, "{Un}")?;
}
Expand Down Expand Up @@ -1087,7 +1087,7 @@ impl ImplPrimitive {
ImplPrimitive::UnFix => env.monadic_mut_env(Value::unfix)?,
ImplPrimitive::UnShape => env.monadic_ref_env(Value::unshape)?,
ImplPrimitive::UnScan => reduce::unscan(env)?,
ImplPrimitive::TraceN(n, inverse, stack_sub) => trace_n(env, *n, *inverse, *stack_sub)?,
ImplPrimitive::TraceN { n, inverse, stack_sub } => trace_n(env, *n, *inverse, *stack_sub)?,
ImplPrimitive::UnStack => stack(env, true)?,
ImplPrimitive::UnDump => dump(env, true)?,
ImplPrimitive::Primes => env.monadic_ref_env(Value::primes)?,
Expand Down Expand Up @@ -1430,7 +1430,7 @@ fn trace_n(env: &mut Uiua, n: usize, inverse: bool, stack_sub: bool) -> UiuaResu
items.push(env.pop(i + 1)?);
}
items.reverse();
let span = format!("{} {}", ImplPrimitive::TraceN(n, inverse, stack_sub), env.span());
let span = format!("{} {}", ImplPrimitive::TraceN { n, inverse, stack_sub }, env.span());
let max_line_len = span.chars().count() + 2;
let boundaries = stack_boundaries(env);
let item_lines: Vec<Vec<String>> = items
Expand Down

0 comments on commit 12d5a5d

Please sign in to comment.