From 882639c83eb782e15d3c96243acf03e459a358b0 Mon Sep 17 00:00:00 2001 From: dzaima Date: Tue, 1 Jun 2021 20:41:52 +0300 Subject: [PATCH] use nfns for file functions --- src/builtins/md1.c | 48 ------------------------------ src/builtins/sysfn.c | 69 ++++++++++++++++++++++++++++++++++++++------ src/load.c | 2 +- 3 files changed, 61 insertions(+), 58 deletions(-) diff --git a/src/builtins/md1.c b/src/builtins/md1.c index a8faa591..d8653270 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -295,54 +295,6 @@ B timed_c1(B d, B x) { B f = c(Md1D,d)->f; return m_f64((ens-sns)/1e9); } -B fchars_c1(B d, B x) { B f = c(Md1D,d)->f; - return file_chars(path_resolve(f, x)); -} -B fbytes_c1(B d, B x) { B f = c(Md1D,d)->f; - TmpFile* tf = file_bytes(path_resolve(f, x)); - usz ia = tf->ia; u8* p = (u8*)tf->a; - u32* rp; B r = m_c32arrv(&rp, ia); - for (i64 i = 0; i < ia; i++) rp[i] = p[i]; - ptr_dec(tf); - return r; -} -B flines_c1(B d, B x) { B f = c(Md1D,d)->f; - TmpFile* tf = file_bytes(path_resolve(f, x)); - usz ia = tf->ia; u8* p = (u8*)tf->a; - usz lineCount = 0; - for (usz i = 0; i < ia; i++) { - if (p[i]=='\n') lineCount++; - else if (p[i]=='\r') { - lineCount++; - if(i+1f; - return bqn_execFile(path_resolve(f, x), inc(bi_emptyHVec)); -} -B import_c2(B d, B w, B x) { B f = c(Md1D,d)->f; - return bqn_execFile(path_resolve(f, x), w); -} - - -B fchars_c2(B d, B w, B x) { B f = c(Md1D,d)->f; - file_write(path_resolve(f, w), x); - return x; -} extern B rt_cell; B cell_c1(B d, B x) { B f = c(Md1D,d)->f; diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index 217dda95..ac5dcad4 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -226,16 +226,61 @@ B makeRand_c1(B t, B x) { return r; } - +static NFnDesc* fCharsDesc; +B fchars_c1(B d, B x) { B base = nfn_objU(d); + return file_chars(path_resolve(base, x)); +} +B fchars_c2(B d, B w, B x) { B base = nfn_objU(d); + file_write(path_resolve(base, w), x); + return x; +} +static NFnDesc* fBytesDesc; +B fbytes_c1(B d, B x) { B base = nfn_objU(d); + TmpFile* tf = file_bytes(path_resolve(base, x)); + usz ia = tf->ia; u8* p = (u8*)tf->a; + u32* rp; B r = m_c32arrv(&rp, ia); + for (i64 i = 0; i < ia; i++) rp[i] = p[i]; + ptr_dec(tf); + return r; +} +static NFnDesc* fLinesDesc; +B flines_c1(B d, B x) { B base = nfn_objU(d); + TmpFile* tf = file_bytes(path_resolve(base, x)); + usz ia = tf->ia; u8* p = (u8*)tf->a; + usz lineCount = 0; + for (usz i = 0; i < ia; i++) { + if (p[i]=='\n') lineCount++; + else if (p[i]=='\r') { + lineCount++; + if(i+1