From 98c963453bffedc6122405f85fef5e2c78c475bb Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 5 Mar 2023 14:15:05 +0200 Subject: [PATCH] =?UTF-8?q?=E2=80=A2internal.GC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/system.md | 1 + src/builtins.h | 2 +- src/builtins/internal.c | 13 +++++++++++-- src/builtins/sysfn.c | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/system.md b/docs/system.md index 1a9a1a2a..bba08bac 100644 --- a/docs/system.md +++ b/docs/system.md @@ -100,6 +100,7 @@ Namespace of various internal functions. May change at any time. | name | description | |----------------------------|-------------| +| `•internal.GC` | Run a garbage collection cycle | | `•internal.Type` | Name of the internal type for an object | | `•internal.ElType` | Element size type identifier; see `enum ElType` | | `•internal.Refc` | Reference count of the argument, if it's heap-allocated | diff --git a/src/builtins.h b/src/builtins.h index ec9ed96a..9748a0bd 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -17,7 +17,7 @@ /* sysfn.c*/M(tRawMode,"•term.RawMode") M(tFlush,"•term.Flush") M(tCharB,"•term.CharB") M(tCharN,"•term.CharN") M(tOutRaw,"•term.OutRaw") M(tErrRaw,"•term.ErrRaw") \ /* inverse.c*/M(setInvReg,"(SetInvReg)") M(setInvSwap,"(SetInvSwap)") M(nativeInvReg,"(NativeInvReg)") M(nativeInvSwap,"(NativeInvSwap)") \ /*internal.c*/M(itype,"•internal.Type") M(elType,"•internal.ElType") M(refc,"•internal.Refc") M(isPure,"•internal.IsPure") A(info,"•internal.Info") M(heapDump,"•internal.HeapDump") \ -/*internal.c*/M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") D(eequal,"•internal.EEqual") A(internalTemp,"•internal.Temp") \ +/*internal.c*/M(squeeze,"•internal.Squeeze") M(deepSqueeze,"•internal.DeepSqueeze") D(eequal,"•internal.EEqual") A(internalTemp,"•internal.Temp") M(internalGC,"•internal.GC") \ /*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare") \ /* arithm.c*/M(sin,"•math.Sin") M(cos,"•math.Cos") M(tan,"•math.Tan") M(asin,"•math.Asin") M(acos,"•math.Acos") M(atan,"•math.Atan") D(atan2,"•math.Atan2") D(hypot,"•math.Hypot") \ /* arithm.c*/M(sinh,"•math.Sinh") M(cosh,"•math.Cosh") M(tanh,"•math.Tanh") M(asinh,"•math.Asinh") M(acosh,"•math.Acosh") M(atanh,"•math.Atanh") \ diff --git a/src/builtins/internal.c b/src/builtins/internal.c index 9f3ccfd2..707bec38 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -325,6 +325,15 @@ B heapDump_c1(B t, B x) { return x; } +B internalGC_c1(B t, B x) { + #if ENABLE_GC + gc_forceGC(false); + dec(x); return m_f64(1); + #else + dec(x); return m_f64(0); + #endif +} + B unshare_c1(B t, B x) { if (!isArr(x)) thrM("•internal.Unshare: Argument must be an array"); B r = unshare(x); @@ -346,8 +355,8 @@ B getInternalNS(void) { #undef F #define F(X) incG(bi_##X), - Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info","listvariations","variation","clearrefs","unshare","deepsqueeze","heapdump","eequal","temp"); - internalNS = m_nns(d,F(itype)F(elType)F(refc)F(squeeze)F(isPure)F(info)F(listVariations)F(variation)F(clearRefs)F(unshare)F(deepSqueeze)F(heapDump)F(eequal)F(internalTemp)); + Body* d = m_nnsDesc("type","eltype","refc","squeeze","ispure","info","listvariations","variation","clearrefs","unshare","deepsqueeze","heapdump","eequal","gc","temp"); + internalNS = m_nns(d,F(itype)F(elType)F(refc)F(squeeze)F(isPure)F(info)F(listVariations)F(variation)F(clearRefs)F(unshare)F(deepSqueeze)F(heapDump)F(eequal)F(internalGC)F(internalTemp)); #undef F gc_add(internalNS); } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 754f2e45..f4430f6e 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -1651,7 +1651,7 @@ u32* 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.Remove",U"•file.Rename",U"•file.Size",U"•file.Type", - U"•internal.ClearRefs",U"•internal.DeepSqueeze",U"•internal.EEqual",U"•internal.ElType",U"•internal.HeapDump",U"•internal.Info",U"•internal.IsPure",U"•internal.ListVariations",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.HeapDump",U"•internal.Info",U"•internal.IsPure",U"•internal.ListVariations",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", U"•rand.Deal",U"•rand.Range",U"•rand.Subset",