From b69f65081d128208b5c67dfab4602bfa3dcb8379 Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 4 Sep 2024 23:33:36 +0300 Subject: [PATCH] =?UTF-8?q?vector=20=E2=86=92=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/README.md | 10 +++++----- src/builtins/sysfn.c | 8 ++++---- src/utils/mut.h | 4 ++-- src/vm.h | 4 ++-- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/README.md b/src/README.md index e79fe624..4d845010 100644 --- a/src/README.md +++ b/src/README.md @@ -244,12 +244,12 @@ The shape pointer of a rank≤1 array will point to the object's own `ia` field Allocating an array: ```C -i32* rp; B r = m_i32arrv(&rp, 123); // allocate a 123-element i32 vector +i32* rp; B r = m_i32arrv(&rp, 123); // allocate a 123-element i32 list i32* rp; B r = m_i32arrc(&rp, x); // allocate an array with the same shape as x (x must be an array; x isn't consumed) i32* rp; Arr* r = m_i32arrp(&rp, 123); // allocate a 123-element i32-array without allocating shape // then at some point do one of these: -arr_shVec(r); // set shape of r to a vector +arr_shVec(r); // set shape of r to a list usz* sh = arr_shAlloc(r, 4); // allocate a rank 4 shape; write to sh the individual items; sh will be NULL for ranks 0 and 1 arr_shCopy(r, x); // copy the shape object of x (doesn't consume x) // then get the final array: @@ -262,7 +262,7 @@ u32* rp; B r = m_c32arrv(%rp, 10); // 10-char string // arbitrary object arrays: // initialized with all elements being 0.0s, which you can replace with `r.a[i]=val`, and get the result with `r.b`; simple, but may not be optimal -HArr_p r = m_harr0v(10); // new 10-item vector +HArr_p r = m_harr0v(10); // new 10-item list HArr_p r = m_harr0c(10, x); // new 10-item array with the same shape as x HArr_p r = m_harr0p(10); // new 10-item array without any set shape. Use the arr_shWhatever(r.c, …) @@ -271,7 +271,7 @@ M_HARR(r, 123) // allocate a 123-item arbitrary object array HARR_ADD(r, i, val); // write val to the next position in the array. The 'i' variable is just a hint, all calls must be consecutive either way HARR_ADDA(r, val); // the above but without needing the useless 'i' parameter // then do one of these to get the finished object: -B result = HARR_FV(r); // sets shape to a vector +B result = HARR_FV(r); // sets shape to a list B result = HARR_FC(r, x); // copies the shape of x, doesn't consume x B result = HARR_FCD(r, x); // copies the shape of x and consumes it usz* sh = HARR_FA(r, 4); // allocate shape for a rank 4 array. To get the result `B` object, do HARR_O(r).b later @@ -279,7 +279,7 @@ Arr* result = HARR_FP(r); // don't allocate/set any shape // If at any point you want to free the object before finishing it, do HARR_ABANDON(r) // If you're sure GC cannot happen (that includes no allocating) before all items in the array are set, you can use: -HArr_p r = m_harrUv(10); // 10-item vector +HArr_p r = m_harrUv(10); // 10-item list HArr_p r = m_harrUc(10, x); // 10-item array with the same shape as x HArr_p r = m_harrUp(10); // 10-item array without any set shape. Use the arr_shWhatever(r.c, …) // run `NOGC_E;` after filling in the items to resume allowing allocations (not necessary if item count is 0) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index b70bcbd8..2db3bdbb 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -283,7 +283,7 @@ NOINLINE B vfyStr(B x, char* name, char* arg) { GLOBAL B cdPath; static NOINLINE B prep_state(B w, char* name) { // consumes w, returns ⟨path,name,args⟩ - if (!isArr(w) || RNK(w)!=1 || IA(w)>3) thrF("%U: 𝕨 must be a vector with at most 3 items, but had shape %H", name, w); + if (!isArr(w) || RNK(w)!=1 || IA(w)>3) thrF("%U: 𝕨 must be a list with at most 3 items, but had shape %H", name, w); usz ia = IA(w); SGet(w) HArr_p r = m_harr0v(3); r.a[0] = ia>0? vfyStr(Get(w,0),name,"Path" ) : inc(cdPath); @@ -1038,7 +1038,7 @@ static i32 sh_core(bool raw, B x, usz xia, B inObj, u64 iLen, B* s_outp, B* s_er SGetU(x) for (u64 i = 0; i < xia; i++) { B c = GetU(x, i); - if (isAtm(c) || RNK(c)!=1) thrM("•SH: 𝕩 must be a vector of strings"); + if (isAtm(c) || RNK(c)!=1) thrM("•SH: 𝕩 must be a list of strings"); u64 len = utf8lenB(c); TALLOC(char, cstr, len+1); toUTF8(c, cstr); @@ -1162,7 +1162,7 @@ static i32 sh_core(bool raw, B x, usz xia, B inObj, u64 iLen, B* s_outp, B* s_er SGetU(x) for (u64 i = 0; i < xia; i++) { B c = GetU(x, i); - if (isAtm(c) || RNK(c)!=1) thrM("•SH: 𝕩 must be a vector of strings"); + if (isAtm(c) || RNK(c)!=1) thrM("•SH: 𝕩 must be a list of strings"); u64 len = utf8lenB(c); arglen += 1+2+2*len; // space or 0, quotes, worst-case scenario (every character needs escaping) @@ -1238,7 +1238,7 @@ static i32 sh_core(bool raw, B x, usz xia, B inObj, u64 iLen, B* s_outp, B* s_er } u64 iLen = q_N(inObj)? 0 : (raw? IA(inObj) : utf8lenB(inObj)); - if (isAtm(x) || RNK(x)>1) thrM("•SH: 𝕩 must be a vector of strings"); + if (isAtm(x) || RNK(x)>1) thrM("•SH: 𝕩 must be a list of strings"); usz xia = IA(x); if (xia==0) thrM("•SH: 𝕩 must have at least one item"); diff --git a/src/utils/mut.h b/src/utils/mut.h index b88869e8..ac603317 100644 --- a/src/utils/mut.h +++ b/src/utils/mut.h @@ -156,10 +156,10 @@ SHOULD_INLINE void bit_cpy(u64* r, usz rs, u64* x, usz xs, usz l) { typedef struct { B w2; void* rp; } JoinFillslice; JoinFillslice fillslice_getJoin(B w, usz ria); // either returns NULL in rp, or consumes w -// consume==true: consumes w,x and expects both args to be vectors +// consume==true: consumes w,x and expects both args to be lists // consume==false: doesn't consume x, and // *usedW==true: consumes w, returns w or its backing array; if RNK(w)>1, result has the same shape as w, i.e. not updated -// *usedW==false: doesn't consume w; result has vector shape +// *usedW==false: doesn't consume w; result has list shape // returns possibly incorrect fills if arguments aren't equal class typed arrays FORCE_INLINE B arr_join_inline(B w, B x, bool consume, bool* usedW) { assert(isArr(w) && isArr(x)); diff --git a/src/vm.h b/src/vm.h index 4bb96f35..236766fe 100644 --- a/src/vm.h +++ b/src/vm.h @@ -32,8 +32,8 @@ enum { POPS = 0x06, // pop object from stack RETN = 0x07, // returns top of stack RETD = 0x08, // return a namespace of exported items - LSTO = 0x0B, // N; push a vector of top N items - LSTM = 0x0C, // N; push a mutable vector of top N items + LSTO = 0x0B, // N; push a list of top N items + LSTM = 0x0C, // N; push a mutable list of top N items ARMO = 0x0D, // N; push an array whose cells are the top N items ARMM = 0x0E, // N; push a mutable array whose cells are the top N items