1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-25 07:50:27 +00:00

Move ast to core. Add symbol function to stl.

This commit is contained in:
bakpakin 2018-01-21 17:08:11 -05:00
parent 42a88de9e7
commit 26c8145893
6 changed files with 32 additions and 32 deletions

View File

@ -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})

View File

@ -21,7 +21,6 @@
*/
#include <dst/dst.h>
#include <dst/dstparse.h>
/* Mark an ast node */
static int dst_ast_gcmark(void *p, size_t size) {

View File

@ -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},

View File

@ -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 */

View File

@ -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);

View File

@ -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 */