mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 15:43:01 +00:00 
			
		
		
		
	Move ast to core. Add symbol function to stl.
This commit is contained in:
		| @@ -48,6 +48,7 @@ src/compiler/compile.h | |||||||
| set(CORE_SOURCES | set(CORE_SOURCES | ||||||
| src/core/abstract.c | src/core/abstract.c | ||||||
| src/core/array.c | src/core/array.c | ||||||
|  | src/core/ast.c | ||||||
| src/core/buffer.c | src/core/buffer.c | ||||||
| src/core/bytecode.c | src/core/bytecode.c | ||||||
| src/core/fiber.c | src/core/fiber.c | ||||||
| @@ -76,7 +77,6 @@ src/mainclient/main.c | |||||||
| ) | ) | ||||||
|  |  | ||||||
| set(PARSER_SOURCES | set(PARSER_SOURCES | ||||||
| src/parser/ast.c |  | ||||||
| src/parser/parse.c | src/parser/parse.c | ||||||
| src/parser/strtod.c | src/parser/strtod.c | ||||||
| ) | ) | ||||||
| @@ -96,18 +96,3 @@ ${PARSER_SOURCES} | |||||||
| # Build the executable | # Build the executable | ||||||
| add_executable(${TARGET_NAME} ${SOURCES}) | add_executable(${TARGET_NAME} ${SOURCES}) | ||||||
| target_link_libraries(${TARGET_NAME} m dl) | 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}) |  | ||||||
|   | |||||||
| @@ -21,7 +21,6 @@ | |||||||
| */ | */ | ||||||
| 
 | 
 | ||||||
| #include <dst/dst.h> | #include <dst/dst.h> | ||||||
| #include <dst/dstparse.h> |  | ||||||
| 
 | 
 | ||||||
| /* Mark an ast node */ | /* Mark an ast node */ | ||||||
| static int dst_ast_gcmark(void *p, size_t size) { | static int dst_ast_gcmark(void *p, size_t size) { | ||||||
| @@ -77,6 +77,21 @@ int dst_stl_string(DstArgs args) { | |||||||
|     return 0; |     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) { | int dst_stl_buffer_to_string(DstArgs args) { | ||||||
|     DstBuffer *b; |     DstBuffer *b; | ||||||
|     if (args.n != 1) return dst_throw(args, "expected 1 argument"); |     if (args.n != 1) return dst_throw(args, "expected 1 argument"); | ||||||
| @@ -252,6 +267,7 @@ static const DstReg cfuns[] = { | |||||||
|     {"print", dst_stl_print}, |     {"print", dst_stl_print}, | ||||||
|     {"describe", dst_stl_describe}, |     {"describe", dst_stl_describe}, | ||||||
|     {"string", dst_stl_string}, |     {"string", dst_stl_string}, | ||||||
|  |     {"symbol", dst_stl_symbol}, | ||||||
|     {"buffer-string", dst_stl_buffer_to_string}, |     {"buffer-string", dst_stl_buffer_to_string}, | ||||||
|     {"table", dst_cfun_table}, |     {"table", dst_cfun_table}, | ||||||
|     {"array", dst_cfun_array}, |     {"array", dst_cfun_array}, | ||||||
|   | |||||||
| @@ -203,4 +203,10 @@ DstTable *dst_env_arg(DstArgs args); | |||||||
| /* STL */ | /* STL */ | ||||||
| DstTable *dst_stl_env(); | 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 */ | #endif /* DST_H_defined */ | ||||||
|   | |||||||
| @@ -29,21 +29,6 @@ typedef enum DstParserStatus DstParserStatus; | |||||||
| typedef struct DstParseState DstParseState; | typedef struct DstParseState DstParseState; | ||||||
| typedef struct DstParser DstParser; | 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 */ | /* Number scanning */ | ||||||
| Dst dst_scan_number(const uint8_t *src, int32_t len); | 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); | int32_t dst_scan_integer(const uint8_t *str, int32_t len, int *err); | ||||||
|   | |||||||
| @@ -419,4 +419,13 @@ struct DstReg { | |||||||
|     DstCFunction cfun; |     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 */ | #endif /* DST_TYPES_H_defined */ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 bakpakin
					bakpakin