From 5dbd1688bc368b76c75de8fedf49c5767a702446 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 21 Aug 2021 03:52:49 +0300 Subject: [PATCH] =?UTF-8?q?=E2=80=A2MakeREPL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sysfn.c | 23 +++++++++++++++++++++++ src/main.c | 2 +- src/utils/builtins.h | 2 +- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index e1b63008..ff5a2479 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -416,6 +416,27 @@ B makeRand_c1(B t, B x) { ns_set(r, rand_subsetName, m_nfn(rand_subsetDesc, inc(r))); return r; } +extern B replPath; // defined in main.c +static NFnDesc* makeREPLDesc; +B makeREPL_c1(B t, B x) { + dec(x); + Block* initBlock = bqn_comp(m_str32(U"\"(REPL initializer)\""), inc(replPath), m_f64(0)); + Scope* sc = m_scope(initBlock->bodies[0], NULL, 0, 0, NULL); + ptr_dec(initBlock); + return m_nfn(makeREPLDesc, tag(sc, OBJ_TAG)); +} +B repl_c1(B t, B x) { + Scope* sc = c(Scope,nfn_objU(t)); + + Block* block = bqn_compSc(x, inc(replPath), emptySVec(), sc, true); + + ptr_dec(sc->body); ptr_inc(block->bodies[0]); + sc->body = block->bodies[0]; + B res = execBlockInline(block, sc); + + ptr_dec(block); + return res; +} static NFnDesc* fCharsDesc; B fchars_c1(B d, B x) { @@ -590,6 +611,7 @@ B sys_c1(B t, B x) { else if (eqStr(c, U"repr")) r.a[i] = inc(bi_repr); else if (eqStr(c, U"glyph")) r.a[i] = inc(bi_glyph); else if (eqStr(c, U"makerand")) r.a[i] = inc(bi_makeRand); + else if (eqStr(c, U"makerepl")) r.a[i] = inc(bi_makeREPL); else if (eqStr(c, U"fromutf8")) r.a[i] = inc(bi_fromUtf8); else if (eqStr(c, U"fchars")) r.a[i] = m_nfn(fCharsDesc, path_dir(inc(comp_currPath))); else if (eqStr(c, U"fbytes")) r.a[i] = m_nfn(fBytesDesc, path_dir(inc(comp_currPath))); @@ -609,6 +631,7 @@ void sysfn_init() { fLinesDesc = registerNFn(m_str32(U"•FLines"), flines_c1, c2_invalid); fBytesDesc = registerNFn(m_str32(U"•FBytes"), fbytes_c1, c2_invalid); importDesc = registerNFn(m_str32(U"•Import"), import_c1, import_c2); + makeREPLDesc = registerNFn(m_str32(U"(REPL)"), repl_c1, c2_invalid); listDesc = registerNFn(m_str32(U"•file.List"), list_c1, c2_invalid); } void sysfnPost_init() { diff --git a/src/main.c b/src/main.c index a3c07919..b5afeb40 100644 --- a/src/main.c +++ b/src/main.c @@ -3,7 +3,7 @@ #include "utils/utf.h" #include "utils/file.h" -static B replPath; +B replPath; // also used by sysfn.c static Scope* gsc; static bool init = false; diff --git a/src/utils/builtins.h b/src/utils/builtins.h index 41c73f53..a7dc941d 100644 --- a/src/utils/builtins.h +++ b/src/utils/builtins.h @@ -9,7 +9,7 @@ /* everything before the definition of •Type is defined to be pure, and everything after is not */ \ /* sysfn.c*/M(type,"•Type") M(decp,"•Decompose") M(primInd,"•PrimInd") M(glyph,"•Glyph") A(fill,"•FillFn") M(sys,"•getsys") A(grLen,"•GroupLen") D(grOrd,"•groupOrd") \ /* sysfn.c*/M(repr,"•Repr") A(asrt,"!") A(casrt,"!") M(out,"•Out") M(show,"•Show") M(bqn,"•BQN") M(sh,"•SH") M(fromUtf8,"•FromUTF8") \ -/* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(delay,"•Delay") M(makeRand,"•MakeRand") M(exit,"•Exit") M(getLine,"•GetLine") \ +/* sysfn.c*/D(cmp,"•Cmp") A(hash,"•Hash") M(delay,"•Delay") M(makeRand,"•MakeRand") M(makeREPL,"•MakeREPL") M(exit,"•Exit") M(getLine,"•GetLine") \ /*internal.c*/M(itype,"•internal.Type") M(refc,"•internal.Refc") M(squeeze,"•internal.Squeeze") M(isPure,"•internal.IsPure") A(info,"•internal.Info") \ /*internal.c*/D(variation,"•internal.Variation") A(listVariations,"•internal.ListVariations") M(clearRefs,"•internal.ClearRefs") M(unshare,"•internal.Unshare")