From 719d37cd63b06ab93502f258e802b05dbb3412f5 Mon Sep 17 00:00:00 2001 From: dzaima Date: Thu, 18 Aug 2022 11:18:34 +0300 Subject: [PATCH] reorder eachm_fn and eachd_fn args --- src/builtins/arithm.c | 2 +- src/utils/each.c | 4 ++-- src/utils/each.h | 14 +++++++------- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index a78d916a..d456f798 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -7,7 +7,7 @@ static inline B arith_recm(BB2B f, B x) { B fx = getFillQ(x); - B r = eachm_fn(f, bi_N, x); + B r = eachm_fn(bi_N, x, f); return withFill(r, fx); } diff --git a/src/utils/each.c b/src/utils/each.c index f1fe27ed..67091511 100644 --- a/src/utils/each.c +++ b/src/utils/each.c @@ -4,7 +4,7 @@ static inline B mv(B* p, usz n) { B r = p [n]; p [n] = m_f64(0); return r; } static inline B hmv(HArr_p p, usz n) { B r = p.a[n]; p.a[n] = m_f64(0); return r; } -B eachd_fn(BBB2B f, B fo, B w, B x) { +B eachd_fn(B fo, B w, B x, BBB2B f) { if (isAtm(w)) w = m_atomUnit(w); if (isAtm(x)) x = m_atomUnit(x); ur wr = rnk(w); SGet(w); @@ -51,7 +51,7 @@ B eachd_fn(BBB2B f, B fo, B w, B x) { return any_squeeze(rb); } -B eachm_fn(BB2B f, B fo, B x) { // TODO definitely rewrite this. Probably still has refcounting errors +B eachm_fn(B fo, B x, BB2B f) { // TODO definitely rewrite this. Probably still has refcounting errors usz ia = a(x)->ia; if (ia==0) return x; SGet(x); diff --git a/src/utils/each.h b/src/utils/each.h index 331f993a..3c78b2d8 100644 --- a/src/utils/each.h +++ b/src/utils/each.h @@ -1,12 +1,12 @@ #pragma once #include "mut.h" -B eachd_fn(BBB2B f, B fo, B w, B x); // consumes w,x; assumes at least one is array -B eachm_fn(BB2B f, B fo, B x); // consumes x; x must be array +B eachd_fn(B fo, B w, B x, BBB2B f); // consumes w,x; assumes at least one is array +B eachm_fn(B fo, B x, BB2B f); // consumes x; x must be array static B eachm(B f, B x) { // complete F¨ x without fills; consumes x if (isAtm(x)) return m_hunit(c1(f, x)); - if (isFun(f)) return eachm_fn(c(Fun,f)->c1, f, x); + if (isFun(f)) return eachm_fn(f, x, c(Fun,f)->c1); if (isMd(f)) if (isAtm(x) || a(x)->ia) { decR(x); thrM("Calling a modifier"); } usz ia = a(x)->ia; @@ -17,16 +17,16 @@ static B eachm(B f, B x) { // complete F¨ x without fills; consumes x static B eachd(B f, B w, B x) { // complete w F¨ x without fills; consumes w,x if (isAtm(w) & isAtm(x)) return m_hunit(c2(f, w, x)); - return eachd_fn(c2fn(f), f, w, x); + return eachd_fn(f, w, x, c2fn(f)); } #if CATCH_ERRORS static inline B arith_recd(BBB2B f, B w, B x) { B fx = getFillQ(x); - if (noFill(fx)) return eachd_fn(f, bi_N, w, x); + if (noFill(fx)) return eachd_fn(bi_N, w, x, f); B fw = getFillQ(w); - B r = eachd_fn(f, bi_N, w, x); + B r = eachd_fn(bi_N, w, x, f); if (noFill(fw)) { dec(fx); return r; } if (CATCH) { freeThrown(); return r; } B fr = f(bi_N, fw, fx); @@ -35,6 +35,6 @@ static inline B arith_recd(BBB2B f, B w, B x) { } #else static inline B arith_recd(BBB2B f, B w, B x) { - return eachd_fn(f, bi_N, w, x); + return eachd_fn(bi_N, w, x, f); } #endif