add framework for subprocess

This commit is contained in:
ValKmjolnir 2024-06-09 00:21:11 +08:00
parent 1205c6d788
commit 7e3c6d06b2
7 changed files with 46 additions and 1 deletions

View File

@ -30,6 +30,7 @@ set(NASAL_OBJECT_SOURCE_FILE
${CMAKE_SOURCE_DIR}/src/natives/math_lib.cpp
${CMAKE_SOURCE_DIR}/src/natives/dylib_lib.cpp
${CMAKE_SOURCE_DIR}/src/natives/regex_lib.cpp
${CMAKE_SOURCE_DIR}/src/natives/subprocess.cpp
${CMAKE_SOURCE_DIR}/src/natives/unix_lib.cpp
${CMAKE_SOURCE_DIR}/src/repl/repl.cpp
${CMAKE_SOURCE_DIR}/src/util/fs.cpp

View File

@ -37,6 +37,7 @@ NASAL_HEADER = \
src/natives/unix_lib.h\
src/natives/coroutine.h\
src/natives/regex_lib.h\
src/natives/subprocess.h\
src/repl/repl.h\
src/util/fs.h\
src/util/util.h
@ -61,6 +62,7 @@ NASAL_OBJECT = \
build/math_lib.o\
build/unix_lib.o\
build/dylib_lib.o\
build/subprocess.o\
build/json_lib.o\
build/coroutine.o\
build/nasal_type.o\
@ -212,6 +214,14 @@ build/regex_lib.o: \
src/natives/regex_lib.h src/natives/regex_lib.cpp | build
$(CXX) $(CXXFLAGS) src/natives/regex_lib.cpp -o build/regex_lib.o
build/subprocess.o: \
src/nasal.h\
src/nasal_type.h\
src/nasal_gc.h\
src/natives/subprocess.h src/natives/subprocess.cpp | build
$(CXX) $(CXXFLAGS) src/natives/subprocess.cpp -o build/subprocess.o
build/fg_props.o: \
src/nasal.h\
src/nasal_type.h\

View File

@ -39,6 +39,7 @@ void codegen::init_native_function() {
load_native_function_table(unix_lib_native);
load_native_function_table(json_lib_native);
load_native_function_table(regex_lib_native);
load_native_function_table(subprocess_native);
}
void codegen::check_id_exist(identifier* node) {

View File

@ -18,6 +18,7 @@
#include "natives/dylib_lib.h"
#include "natives/regex_lib.h"
#include "natives/unix_lib.h"
#include "natives/subprocess.h"
#include <iomanip>
#include <list>
@ -57,7 +58,9 @@ private:
"__dlopen", "__dlclose", "__dlcallv", "__dlcall",
// unix
"__pipe", "__fork", "__waitpid", "__chdir",
"__environ", "__getcwd", "__getenv"
"__environ", "__getcwd", "__getenv",
// subprocess
"__subprocess_run"
};
// file mapper for file -> index

View File

@ -0,0 +1,14 @@
#include "natives/subprocess.h"
namespace nasal {
var builtin_subprocess_run(context* ctx, gc* ngc) {
return nil;
}
nasal_builtin_table subprocess_native[] = {
{"__subprocess_run", builtin_subprocess_run},
{nullptr, nullptr}
};
}

13
src/natives/subprocess.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "nasal.h"
#include "nasal_gc.h"
#include "natives/builtin.h"
namespace nasal {
var builtin_subprocess_run(context*, gc*);
extern nasal_builtin_table subprocess_native[];
}

3
std/subprocess.nas Normal file
View File

@ -0,0 +1,3 @@
var run = func() {
return __subprocess_run();
}