From 26c8145893fccd9c752fb76bd2acdbcf6fa8fc4f Mon Sep 17 00:00:00 2001 From: bakpakin Date: Sun, 21 Jan 2018 17:08:11 -0500 Subject: [PATCH] Move ast to core. Add symbol function to stl. --- CMakeLists.txt | 17 +---------------- src/{parser => core}/ast.c | 1 - src/core/stl.c | 16 ++++++++++++++++ src/include/dst/dst.h | 6 ++++++ src/include/dst/dstparse.h | 15 --------------- src/include/dst/dsttypes.h | 9 +++++++++ 6 files changed, 32 insertions(+), 32 deletions(-) rename src/{parser => core}/ast.c (99%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6cd5184d..235133e6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,7 @@ src/compiler/compile.h set(CORE_SOURCES src/core/abstract.c src/core/array.c +src/core/ast.c src/core/buffer.c src/core/bytecode.c src/core/fiber.c @@ -76,7 +77,6 @@ src/mainclient/main.c ) set(PARSER_SOURCES -src/parser/ast.c src/parser/parse.c src/parser/strtod.c ) @@ -96,18 +96,3 @@ ${PARSER_SOURCES} # Build the executable add_executable(${TARGET_NAME} ${SOURCES}) target_link_libraries(${TARGET_NAME} m dl) - -# Build some modules -add_library(dstvm SHARED ${CORE_SOURCES} ${ASSEMBLER_SOURCES}) -target_link_libraries(dstvm m dl) - -add_library(dstasm SHARED ${ASSEMBLER_SOURCES}) -target_link_libraries(dstasm dstvm) - -#add_library(dstparser MODULE ${PARSER_SOURCES}) -#target_link_libraries(dstparser m) - -#add_library(dstcompiler MODULE ${COMPILER_SOURCES}) -#target_link_libraries(dstvm m) - -#add_library(testlib MODULE ${TESTLIB_SOURCES}) diff --git a/src/parser/ast.c b/src/core/ast.c similarity index 99% rename from src/parser/ast.c rename to src/core/ast.c index 530ad78a..2dc2eb41 100644 --- a/src/parser/ast.c +++ b/src/core/ast.c @@ -21,7 +21,6 @@ */ #include -#include /* Mark an ast node */ static int dst_ast_gcmark(void *p, size_t size) { diff --git a/src/core/stl.c b/src/core/stl.c index 7da85649..8eb50814 100644 --- a/src/core/stl.c +++ b/src/core/stl.c @@ -77,6 +77,21 @@ int dst_stl_string(DstArgs args) { return 0; } +int dst_stl_symbol(DstArgs args) { + int32_t i; + DstBuffer b; + dst_buffer_init(&b, 0); + for (i = 0; i < args.n; ++i) { + int32_t len; + const uint8_t *str = dst_to_string(args.v[i]); + len = dst_string_length(str); + dst_buffer_push_bytes(&b, str, len); + } + *args.ret = dst_symbolv(b.data, b.count); + dst_buffer_deinit(&b); + return 0; +} + int dst_stl_buffer_to_string(DstArgs args) { DstBuffer *b; if (args.n != 1) return dst_throw(args, "expected 1 argument"); @@ -252,6 +267,7 @@ static const DstReg cfuns[] = { {"print", dst_stl_print}, {"describe", dst_stl_describe}, {"string", dst_stl_string}, + {"symbol", dst_stl_symbol}, {"buffer-string", dst_stl_buffer_to_string}, {"table", dst_cfun_table}, {"array", dst_cfun_array}, diff --git a/src/include/dst/dst.h b/src/include/dst/dst.h index d9637955..6e0ac1a1 100644 --- a/src/include/dst/dst.h +++ b/src/include/dst/dst.h @@ -203,4 +203,10 @@ DstTable *dst_env_arg(DstArgs args); /* STL */ DstTable *dst_stl_env(); +/* AST */ +Dst dst_ast_wrap(Dst x, int32_t start, int32_t end); +DstAst *dst_ast_node(Dst x); +Dst dst_ast_unwrap1(Dst x); +Dst dst_ast_unwrap(Dst x); + #endif /* DST_H_defined */ diff --git a/src/include/dst/dstparse.h b/src/include/dst/dstparse.h index a74e2563..f74987a2 100644 --- a/src/include/dst/dstparse.h +++ b/src/include/dst/dstparse.h @@ -29,21 +29,6 @@ typedef enum DstParserStatus DstParserStatus; typedef struct DstParseState DstParseState; typedef struct DstParser DstParser; -/* ASTs are simple wrappers around values. They contain information about sourcemapping - * and other meta data. Possibly types? They are used mainly during compilation and parsing */ -struct DstAst { - Dst value; - int32_t source_start; - int32_t source_end; - int flags; -}; - -/* AST */ -Dst dst_ast_wrap(Dst x, int32_t start, int32_t end); -DstAst *dst_ast_node(Dst x); -Dst dst_ast_unwrap1(Dst x); -Dst dst_ast_unwrap(Dst x); - /* Number scanning */ Dst dst_scan_number(const uint8_t *src, int32_t len); int32_t dst_scan_integer(const uint8_t *str, int32_t len, int *err); diff --git a/src/include/dst/dsttypes.h b/src/include/dst/dsttypes.h index 4bfc62b2..abc47e85 100644 --- a/src/include/dst/dsttypes.h +++ b/src/include/dst/dsttypes.h @@ -419,4 +419,13 @@ struct DstReg { DstCFunction cfun; }; +/* ASTs are simple wrappers around values. They contain information about sourcemapping + * and other meta data. Possibly types? They are used mainly during compilation and parsing */ +struct DstAst { + Dst value; + int32_t source_start; + int32_t source_end; + int flags; +}; + #endif /* DST_TYPES_H_defined */