From 9893a8bd97d9cf95dd3a1a6e0df8738bbec728e6 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 9 May 2021 20:05:34 +0300 Subject: [PATCH] isCallable --- src/h.h | 1 + src/main.c | 9 +++++---- src/md1.c | 2 +- src/stuff.c | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/h.h b/src/h.h index 5db21f33..0cb6d324 100644 --- a/src/h.h +++ b/src/h.h @@ -289,6 +289,7 @@ bool isF64(B x) { return (x.u<<1) - ((0xFFEull<<52) + 2) >= (1ull<<52) - 2; } bool isNum(B x) { return isF64(x)|isI32(x); } bool isAtm(B x) { return !isArr(x); } +bool isCallable(B x) { return isMd(x) | isFun(x); } bool noFill(B x); // shape mess diff --git a/src/main.c b/src/main.c index 2e1e8e3f..9a745afc 100644 --- a/src/main.c +++ b/src/main.c @@ -60,14 +60,13 @@ int main() { // uncomment to self-compile and use that for the REPL // expects a copy of mlochbaum/BQN/src/c.bqn to be at the execution directory (with •args replaced with the array in glyphs.bqn) + // char* c_src = NULL; // u64 c_len; // FILE* f = fopen("c.bqn", "rb"); // if (f) { - // fseek(f, 0, SEEK_END); - // c_len = ftell(f); - // fseek(f, 0, SEEK_SET); - // c_src = malloc(c_len); + // fseek(f, 0, SEEK_END); c_len = ftell(f); + // fseek(f, 0, SEEK_SET); c_src = malloc(c_len); // if (c_src) fread(c_src, 1, c_len, f); // fclose(f); // } else { @@ -75,11 +74,13 @@ int main() { // } // if (c_src) { // bqn_setComp(bqn_exec(fromUTF8(c_src, c_len))); + // // for (i32 i = 0; i < 100; i++) { dec(bqn_exec(fromUTF8(c_src, c_len))); gc_maybeGC(); } // } else { // printf("couldn't read c.bqn\n"); // exit(1); // } + while (CATCH) { printf("caught: "); print(catchMessage); diff --git a/src/md1.c b/src/md1.c index 6f489733..38ec2409 100644 --- a/src/md1.c +++ b/src/md1.c @@ -2,7 +2,7 @@ bool isPureFn(B x) { // doesn't consume - if (!isFun(x) && !isMd(x)) return true; + if (!isCallable(x)) return true; if (v(x)->flags) return true; B2B dcf = TI(x).decompose; B xd = dcf(inc(x)); diff --git a/src/stuff.c b/src/stuff.c index 6d34ab4e..978f77f0 100644 --- a/src/stuff.c +++ b/src/stuff.c @@ -95,7 +95,7 @@ void printRaw(B x) { } } -B def_decompose(B x) { return m_v2(m_i32((isFun(x)|isMd(x))? 0 : -1),x); } +B def_decompose(B x) { return m_v2(m_i32(isCallable(x)? 0 : -1),x); } bool atomEqual(B w, B x) { // doesn't consume (not that that matters really currently) if(isF64(w)&isF64(x)) return w.f==x.f; if (w.u==x.u) return true;