refactor: 重构前端代码并添加日志功能
- 重命名和重构了多个文件,包括 lexer、parser 和 AST 相关代码 - 添加了日志功能,使用 LOG_* 宏替代原有的 error 和 warn 函数 - 优化了错误处理和内存分配方式 - 调整了代码结构,提高了模块化和可读性
This commit is contained in:
64
lib/rt/std/rt_api_def.h
Normal file
64
lib/rt/std/rt_api_def.h
Normal file
@ -0,0 +1,64 @@
|
||||
#ifndef __SMCC_RT_API_DEF_H__
|
||||
#define __SMCC_RT_API_DEF_H__
|
||||
|
||||
#include "rt_type.h"
|
||||
|
||||
#ifndef __RT_SIZE_TYPE__
|
||||
#define __RT_SIZE_TYPE__
|
||||
typedef usz_t rt_size_t;
|
||||
#endif
|
||||
typedef void* (*rt_malloc)(rt_size_t size);
|
||||
typedef void (*rt_free)(void* ptr);
|
||||
typedef void (*rt_exit)(int code);
|
||||
|
||||
#ifndef __RT_FILE_TYPE__
|
||||
#define __RT_FILE_TYPE__
|
||||
typedef void* rt_file_t;
|
||||
#endif
|
||||
extern rt_file_t rt_stdin;
|
||||
extern rt_file_t rt_stdout;
|
||||
extern rt_file_t rt_stderr;
|
||||
typedef rt_file_t (*rt_fopen_t)(const char* file_name, const char* mode);
|
||||
typedef int (*rt_fflush_t)(rt_file_t*file);
|
||||
typedef int (*rt_fclose_t)(rt_file_t file);
|
||||
typedef int (*rt_freads_t)(void * dst_buf, rt_size_t dst_size, rt_size_t elem_size, rt_size_t count, rt_file_t file);
|
||||
typedef int (*rt_fwrite_t)(const void * buf, rt_size_t size, rt_size_t count, rt_file_t file);
|
||||
|
||||
typedef int (*rt_fprintf_t)(void * file, const char *format, ...);
|
||||
typedef int (*rt_snprintf_t)(char * stream, rt_size_t n, const char * format, ...);
|
||||
typedef void* (*rt_realloc_t)(void *memory, rt_size_t new_size);
|
||||
|
||||
typedef struct smcc_rt {
|
||||
rt_malloc _malloc;
|
||||
rt_free _free;
|
||||
rt_exit exit;
|
||||
|
||||
rt_fopen_t fopen;
|
||||
rt_fflush_t fflush;
|
||||
rt_fclose_t fclose;
|
||||
rt_freads_t freads;
|
||||
rt_fwrite_t fwrite;
|
||||
|
||||
// Optional useful runtime
|
||||
rt_fprintf_t fprintf;
|
||||
rt_snprintf_t snprintf;
|
||||
rt_realloc_t _realloc;
|
||||
} smcc_rt_t;
|
||||
|
||||
extern const smcc_rt_t rt;
|
||||
|
||||
// #ifndef NULL
|
||||
// #ifdef __cplusplus
|
||||
// #ifndef _WIN64
|
||||
// #define NULL 0
|
||||
// #else
|
||||
// #define NULL 0LL
|
||||
// #endif /* W64 */
|
||||
// #else
|
||||
// #define NULL ((void *)0)
|
||||
// #endif
|
||||
// #endif
|
||||
|
||||
#define NULL ((void *)0)
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user