remove need of libffi from make forbuild
This commit is contained in:
parent
48c2425e8b
commit
c818bf54b1
2
makefile
2
makefile
@ -38,7 +38,7 @@ shared-o3:
|
|||||||
shared-c:
|
shared-c:
|
||||||
@${MAKE} i_OUTPUT=libcbqn.so i_SHARED=1 custom=1 run_incremental_0
|
@${MAKE} i_OUTPUT=libcbqn.so i_SHARED=1 custom=1 run_incremental_0
|
||||||
forbuild:
|
forbuild:
|
||||||
@${MAKE} i_singeli=0 i_t=forbuild i_f="-O2 -DFOR_BUILD" i_FFI=2 i_OUTPUT=build/obj2/for_build run_incremental_0
|
@${MAKE} i_singeli=0 i_t=forbuild i_f="-O2 -DFOR_BUILD" i_FFI=0 i_OUTPUT=build/obj2/for_build run_incremental_0
|
||||||
c:
|
c:
|
||||||
@${MAKE} custom=1 run_incremental_0
|
@${MAKE} custom=1 run_incremental_0
|
||||||
|
|
||||||
|
|||||||
@ -1380,9 +1380,14 @@ void getSysvals(B* res);
|
|||||||
|
|
||||||
static Body* file_nsGen;
|
static Body* file_nsGen;
|
||||||
|
|
||||||
|
#if FFI || FOR_BUILD
|
||||||
|
#define FFIOPT 1
|
||||||
|
#else
|
||||||
|
#define FFIOPT 0
|
||||||
|
#endif
|
||||||
|
|
||||||
#define OPTSYS_0(X)
|
#define OPTSYS_0(X)
|
||||||
#define OPTSYS_1(X) X
|
#define OPTSYS_1(X) X
|
||||||
#define OPTSYS_2(X) X
|
|
||||||
#define OPTSYS_B(COND) OPTSYS_##COND
|
#define OPTSYS_B(COND) OPTSYS_##COND
|
||||||
#define OPTSYS(COND) OPTSYS_B(COND)
|
#define OPTSYS(COND) OPTSYS_B(COND)
|
||||||
|
|
||||||
@ -1420,7 +1425,7 @@ static Body* file_nsGen;
|
|||||||
F("fbytes", U"•FBytes", tag(7,VAR_TAG)) \
|
F("fbytes", U"•FBytes", tag(7,VAR_TAG)) \
|
||||||
F("flines", U"•FLines", tag(8,VAR_TAG)) \
|
F("flines", U"•FLines", tag(8,VAR_TAG)) \
|
||||||
F("import", U"•Import", tag(9,VAR_TAG)) \
|
F("import", U"•Import", tag(9,VAR_TAG)) \
|
||||||
OPTSYS(FFI)(F("ffi", U"•FFI", tag(10,VAR_TAG))) \
|
OPTSYS(FFIOPT)(F("ffi", U"•FFI", tag(10,VAR_TAG))) \
|
||||||
F("name", U"•name", tag(11,VAR_TAG)) \
|
F("name", U"•name", tag(11,VAR_TAG)) \
|
||||||
F("path", U"•path", tag(12,VAR_TAG)) \
|
F("path", U"•path", tag(12,VAR_TAG)) \
|
||||||
F("wdpath", U"•wdpath", tag(13,VAR_TAG)) \
|
F("wdpath", U"•wdpath", tag(13,VAR_TAG)) \
|
||||||
|
|||||||
90
src/ffi.c
90
src/ffi.c
@ -924,6 +924,92 @@ void ffi_init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#else // i.e. FFI==0
|
#else // i.e. FFI==0
|
||||||
void ffi_init() { }
|
#if !FOR_BUILD
|
||||||
B ffiload_c2(B t, B w, B x) { thrM("CBQN was compiled without FFI"); }
|
void ffi_init() { }
|
||||||
|
B ffiload_c2(B t, B w, B x) { err("•FFI called"); }
|
||||||
|
#else // whatever build.bqn uses from •FFI
|
||||||
|
#include "nfns.h"
|
||||||
|
#include "utils/cstr.h"
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <poll.h>
|
||||||
|
typedef struct pollfd pollfd;
|
||||||
|
NFnDesc* forbuildDesc;
|
||||||
|
B forbuild_c1(B t, B x) {
|
||||||
|
i32 id = o2i(nfn_objU(t));
|
||||||
|
switch (id) { default: err("bad id");
|
||||||
|
case 0: {
|
||||||
|
char* s = toCStr(x);
|
||||||
|
chdir(s);
|
||||||
|
freeCStr(s);
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
dec(x);
|
||||||
|
return m_f64(fork());
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
decG(x);
|
||||||
|
int vs[2];
|
||||||
|
int r = pipe(vs);
|
||||||
|
return m_vec2(m_f64(r), m_vec2(m_f64(vs[0]), m_f64(vs[1])));
|
||||||
|
}
|
||||||
|
case 3: {
|
||||||
|
SGetU(x)
|
||||||
|
int fd = o2i(GetU(x,0));
|
||||||
|
I8Arr* buf = cpyI8Arr(GetU(x,1));
|
||||||
|
usz maxlen = o2s(GetU(x,2));
|
||||||
|
assert(PIA(buf)==maxlen);
|
||||||
|
int res = read(fd, buf->a, maxlen);
|
||||||
|
return m_vec2(m_f64(res), taga(buf));
|
||||||
|
}
|
||||||
|
case 4: {
|
||||||
|
SGetU(x)
|
||||||
|
int fd = o2i(GetU(x,0));
|
||||||
|
I8Arr* buf = cpyI8Arr(GetU(x,1));
|
||||||
|
usz maxlen = o2s(GetU(x,2));
|
||||||
|
int res = write(fd, buf->a, maxlen);
|
||||||
|
return m_f64(res);
|
||||||
|
}
|
||||||
|
case 5: {
|
||||||
|
return m_f64(close(o2i(x)));
|
||||||
|
}
|
||||||
|
case 6: {
|
||||||
|
SGetU(x)
|
||||||
|
I16Arr* buf = cpyI16Arr(GetU(x,0)); i16* a = (i16*)buf->a;
|
||||||
|
int nfds = o2i(GetU(x,1));
|
||||||
|
int timeout = o2s(GetU(x,2));
|
||||||
|
|
||||||
|
TALLOC(pollfd, ps, nfds)
|
||||||
|
for (i32 i = 0; i < nfds; i++) ps[i] = (pollfd){.fd = a[i*4+0]|a[i*4+1]<<16, .events=a[i*4+2]};
|
||||||
|
int res = poll(&ps[0], nfds, timeout);
|
||||||
|
for (i32 i = 0; i < nfds; i++) a[i*4+3] = ps[i].revents;
|
||||||
|
TFREE(ps);
|
||||||
|
|
||||||
|
return m_vec2(m_f64(res), taga(buf));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
B names;
|
||||||
|
B ffiload_c2(B t, B w, B x) {
|
||||||
|
B name = IGetU(x, 1);
|
||||||
|
i32 id = 0;
|
||||||
|
while (id<IA(names) && !equal(IGetU(names, id), name)) id++;
|
||||||
|
B r = m_nfn(forbuildDesc, m_f64(id));
|
||||||
|
decG(x);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ffi_init() {
|
||||||
|
HArr_p a = m_harrUv(7);
|
||||||
|
a.a[0] = m_c8vec_0("chdir");
|
||||||
|
a.a[1] = m_c8vec_0("fork");
|
||||||
|
a.a[2] = m_c8vec_0("pipe");
|
||||||
|
a.a[3] = m_c8vec_0("read");
|
||||||
|
a.a[4] = m_c8vec_0("write");
|
||||||
|
a.a[5] = m_c8vec_0("close");
|
||||||
|
a.a[6] = m_c8vec_0("poll");
|
||||||
|
names = a.b; gc_add(names);
|
||||||
|
forbuildDesc = registerNFn(m_c8vec_0("(function for build)"), forbuild_c1, c2_bad);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user