From a8af920dc910f390d0124f3613fdebc501a4c853 Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 9 Jul 2024 02:00:19 +0300 Subject: [PATCH] =?UTF-8?q?=E2=80=A2internal.PureKeep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/system.md | 1 + src/builtins.h | 1 + src/builtins/internal.c | 9 ++++----- src/builtins/sysfn.c | 2 +- test/cases/system.bqn | 2 ++ 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/docs/system.md b/docs/system.md index 9b25585f..ca13e530 100644 --- a/docs/system.md +++ b/docs/system.md @@ -95,6 +95,7 @@ Namespace of various internal functions. May change at any time. | `•internal.ObjFlags` | Monadically, get the flags of `𝕩`. Dyadically, set the flags of `𝕩` to `𝕨`. | | `•internal.ElType` | Element size type identifier; see `enum ElType` | | `•internal.Keep` | Require the argument to stay alive up to this point in the program. Returns the argument, but without signaling to possible optimizations that the input and output will be equal | +| `•internal.PureKeep` | `•internal.Keep` but marked as a pure function | | `•internal.Refc` | Reference count of the argument, if it's heap-allocated | | `•internal.IsPure` | Whether the vm considers the argument pure (i.e. it can execute it safely for computing fills) | | `•internal.Info` | General internal info about the object; a left argument of `1` gives more details | diff --git a/src/builtins.h b/src/builtins.h index eb7023ee..093fbbde 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -7,6 +7,7 @@ /* sfns.c*/A(shape,"⥊") A(pick,"⊑") A(pair,"⋈") A(select,"⊏") A(slash,"/") A(join,"∾") A(couple,"≍") A(shiftb,"»") \ /* sfns.c*/A(shifta,"«") A(take,"↑") A(drop,"↓") A(group,"⊔") A(reverse,"⌽") A(transp,"⍉") \ /* sort.c*/A(gradeUp,"⍋") A(gradeDown,"⍒") \ +/* sysfn.c*/M(iPureKeep,"•internal.PureKeep") \ /* everything before the definition of •Type is defined to be pure, and everything after is not */ \ /* sysfn.c*/A(invalidFn, "(invalid fn)") A(grLen,"•GroupLen") D(grOrd,"•GroupOrd") A(compObj, "•CompObj") A(fill,"•FillFn") M(sys,"•getsys") M(primInd,"•PrimInd") M(glyph,"•Glyph") \ /* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(repr,"•Repr") M(parseFloat,"•ParseFloat") M(fmt,"•Fmt") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") \ diff --git a/src/builtins/internal.c b/src/builtins/internal.c index 08b24e75..71e96a56 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -380,9 +380,8 @@ B iHasFill_c1(B t, B x) { return m_f64(1); } -B iKeep_c1(B t, B x) { - return x; -} +B iPureKeep_c1(B t, B x) { return x; } +B iKeep_c1(B t, B x) { return x; } B unshare_c1(B t, B x) { if (!isArr(x)) thrM("•internal.Unshare: Argument must be an array"); @@ -405,8 +404,8 @@ B getInternalNS(void) { #undef F #define F(X) incG(bi_##X), - Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info", "keep","listvariations","variation","clearrefs", "hasfill","unshare","deepsqueeze","heapdump","eequal", "gc", "temp","heapstats", "objflags"); - internalNS = m_nns(d,F(itype)F(elType)F(refc)F(squeeze)F(isPure)F(info)F(iKeep)F(listVariations)F(variation)F(clearRefs)F(iHasFill)F(unshare)F(deepSqueeze)F(heapDump)F(eequal)F(internalGC)F(internalTemp)F(heapStats)F(iObjFlags)); + Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info", "keep", "purekeep","listvariations","variation","clearrefs", "hasfill","unshare","deepsqueeze","heapdump","eequal", "gc", "temp","heapstats", "objflags"); + internalNS = m_nns(d,F(itype)F(elType)F(refc)F(squeeze)F(isPure)F(info)F(iKeep)F(iPureKeep)F(listVariations)F(variation)F(clearRefs)F(iHasFill)F(unshare)F(deepSqueeze)F(heapDump)F(eequal)F(internalGC)F(internalTemp)F(heapStats)F(iObjFlags)); #undef F gc_add(internalNS); } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index affad2c0..e8797daa 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -1967,7 +1967,7 @@ u32* const dsv_text[] = { U"•file.Accessed",U"•file.At",U"•file.Bytes",U"•file.Chars",U"•file.Created",U"•file.CreateDir",U"•file.Exists",U"•file.Lines",U"•file.List", U"•file.MapBytes",U"•file.Modified",U"•file.Name",U"•file.Parent",U"•file.path",U"•file.RealPath",U"•file.Remove",U"•file.Rename",U"•file.Size",U"•file.Type", - U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.GC",U"•internal.HasFill",U"•internal.HeapDump",U"•internal.HeapStats",U"•internal.Info",U"•internal.IsPure",U"•internal.Keep",U"•internal.ListVariations",U"•internal.ObjFlags",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Variation", + U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.GC",U"•internal.HasFill",U"•internal.HeapDump",U"•internal.HeapStats",U"•internal.Info",U"•internal.IsPure",U"•internal.Keep",U"•internal.ListVariations",U"•internal.ObjFlags",U"•internal.PureKeep",U"•internal.Refc",U"•internal.Squeeze",U"•internal.Temp",U"•internal.Type",U"•internal.Unshare",U"•internal.Variation", U"•math.Acos",U"•math.Acosh",U"•math.Asin",U"•math.Asinh",U"•math.Atan",U"•math.Atan2",U"•math.Atanh",U"•math.Cbrt",U"•math.Comb",U"•math.Cos",U"•math.Cosh",U"•math.Erf",U"•math.ErfC",U"•math.Expm1",U"•math.Fact",U"•math.GCD",U"•math.Hypot",U"•math.LCM",U"•math.Log10",U"•math.Log1p",U"•math.Log2",U"•math.LogFact",U"•math.Sin",U"•math.Sinh",U"•math.Sum",U"•math.Tan",U"•math.Tanh", U"•ns.Get",U"•ns.Has",U"•ns.Keys", diff --git a/test/cases/system.bqn b/test/cases/system.bqn index ee2cc756..a08d6ff4 100644 --- a/test/cases/system.bqn +++ b/test/cases/system.bqn @@ -361,6 +361,8 @@ a←•internal.Unshare ↕10 ⋄ b←10⥊