🔥 delete useless native functions
This commit is contained in:
parent
671b1ef212
commit
7cc9a9f5c9
|
@ -57,8 +57,7 @@ private:
|
|||
// dylib
|
||||
"__dlopen", "__dlclose", "__dlcallv", "__dlcall",
|
||||
// unix
|
||||
"__pipe", "__fork", "__waitpid", "__chdir",
|
||||
"__environ", "__getcwd", "__getenv",
|
||||
"__chdir", "__environ", "__getcwd", "__getenv",
|
||||
// subprocess
|
||||
"__subprocess_create",
|
||||
"__subprocess_terminate"
|
||||
|
|
|
@ -12,48 +12,6 @@ void dir_entry_destructor(void* ptr) {
|
|||
#endif
|
||||
}
|
||||
|
||||
var builtin_pipe(context* ctx, gc* ngc) {
|
||||
#ifndef _WIN32
|
||||
i32 fd[2];
|
||||
var res = ngc->alloc(vm_type::vm_vec);
|
||||
if (pipe(fd)==-1) {
|
||||
return nas_err("unix::pipe", "failed to create pipe");
|
||||
}
|
||||
res.vec().elems.push_back(var::num(static_cast<f64>(fd[0])));
|
||||
res.vec().elems.push_back(var::num(static_cast<f64>(fd[1])));
|
||||
return res;
|
||||
#endif
|
||||
return nas_err("unix::pipe", "not supported on windows");
|
||||
}
|
||||
|
||||
var builtin_fork(context* ctx, gc* ngc) {
|
||||
#ifndef _WIN32
|
||||
f64 res = fork();
|
||||
if (res<0) {
|
||||
return nas_err("unix::fork", "failed to fork a process");
|
||||
}
|
||||
return var::num(static_cast<f64>(res));
|
||||
#endif
|
||||
return nas_err("unix::fork", "not supported on windows");
|
||||
}
|
||||
|
||||
var builtin_waitpid(context* ctx, gc* ngc) {
|
||||
auto pid = ctx->localr[1];
|
||||
auto nohang = ctx->localr[2];
|
||||
if (!pid.is_num() || !nohang.is_num()) {
|
||||
return nas_err("unix::waitpid", "pid and nohang must be number");
|
||||
}
|
||||
#ifndef _WIN32
|
||||
i32 ret_pid, status;
|
||||
ret_pid = waitpid(pid.num(), &status, nohang.num()==0? 0:WNOHANG);
|
||||
var vec = ngc->alloc(vm_type::vm_vec);
|
||||
vec.vec().elems.push_back(var::num(static_cast<f64>(ret_pid)));
|
||||
vec.vec().elems.push_back(var::num(static_cast<f64>(status)));
|
||||
return vec;
|
||||
#endif
|
||||
return nas_err("unix::waitpid", "not supported on windows");
|
||||
}
|
||||
|
||||
var builtin_opendir(context* ctx, gc* ngc) {
|
||||
auto path = ctx->localr[1];
|
||||
if (!path.is_str()) {
|
||||
|
@ -139,9 +97,6 @@ var builtin_getenv(context* ctx, gc* ngc) {
|
|||
}
|
||||
|
||||
nasal_builtin_table unix_lib_native[] = {
|
||||
{"__pipe", builtin_pipe},
|
||||
{"__fork", builtin_fork},
|
||||
{"__waitpid", builtin_waitpid},
|
||||
{"__opendir", builtin_opendir},
|
||||
{"__readdir", builtin_readdir},
|
||||
{"__closedir", builtin_closedir},
|
||||
|
|
|
@ -24,9 +24,6 @@ namespace nasal {
|
|||
|
||||
void dir_entry_destructor(void*);
|
||||
|
||||
var builtin_pipe(context*, gc*);
|
||||
var builtin_fork(context*, gc*);
|
||||
var builtin_waitpid(context*, gc*);
|
||||
var builtin_opendir(context*, gc*);
|
||||
var builtin_readdir(context*, gc*);
|
||||
var builtin_closedir(context*, gc*);
|
||||
|
|
20
std/unix.nas
20
std/unix.nas
|
@ -7,26 +7,6 @@ use std.io;
|
|||
var _S_IFDIR = 0x4000;
|
||||
var _S_IFREG = 0x8000;
|
||||
|
||||
var pipe = func() {
|
||||
return __pipe;
|
||||
}
|
||||
|
||||
var fork = func() {
|
||||
return __fork;
|
||||
}
|
||||
|
||||
var dup2 = func(fd0, fd1) {
|
||||
die("not supported yet");
|
||||
}
|
||||
|
||||
var exec = func(filename, argv, envp) {
|
||||
die("not supported yet");
|
||||
}
|
||||
|
||||
var waitpid = func(pid, nohang = 0) {
|
||||
return __waitpid;
|
||||
}
|
||||
|
||||
var isdir = func(path) {
|
||||
return !!bits.u32_and(io.stat(path)[2], _S_IFDIR);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue