78 #define WS_CHECK_COMPILE_ERROR() \ 80 if (compiler->errors != 0) { \ 81 if (compiler->errors & WS_ERROR_B_MEMORY) \ 82 result = WS_ERROR_OUT_OF_MEMORY; \ 83 else if (compiler->errors & WS_ERROR_B_SYNTAX) \ 84 result = WS_ERROR_SYNTAX; \ 85 else if (compiler->errors & WS_ERROR_B_SEMANTIC) \ 86 result = WS_ERROR_SEMANTIC; \ 102 {
WS_OK,
"success" },
119 const char *input_name,
WsStream *input,
120 unsigned char **output_return,
121 size_t *output_len_return);
126 static void std_io(
const char *data,
size_t len,
void *
context);
139 if (compiler == NULL)
144 compiler->
params = *params;
165 if (compiler == NULL)
178 FILE *input, FILE *output)
190 result =
compile_stream(compiler, input_name, stream, &bc, &bc_len);
194 if (result ==
WS_OK) {
196 if (fwrite(bc, 1, bc_len, output) != bc_len)
207 const unsigned char *input,
size_t input_len,
208 unsigned char **output_return,
209 size_t *output_len_return)
219 result =
compile_stream(compiler, input_name, stream, output_return,
243 return "unknown result code";
300 ws_fatal(
"ws_lexer_free_block(): unknown block 0x%lx",
301 (
unsigned long) ptr);
317 WsStream *input,
unsigned char **output_return,
318 size_t *output_len_return)
367 if (compiler->
bc == NULL) {
373 compiler->
input = input;
377 global_compiler = compiler;
401 ws_info(compiler,
"optimize: sorting functions");
427 ws_info(compiler,
"linearizing function `%s'...", func->
name);
509 if (!
ws_bc_encode(compiler->
bc, output_return, output_len_return))
533 compiler->
input = NULL;
550 fwrite(data, 1, len, (FILE *)
context);
static struct @111 result_codes[]
void ws_fatal(char *fmt,...)
void * ws_calloc(size_t num, size_t size)
size_t lexer_active_list_size
WsHashPtr pragma_use_hash
struct WsListItemRec * next
WsFastMalloc * ws_f_create(size_t block_size)
unsigned int no_opt_sort_bc_functions
unsigned int print_symbolic_assembler
int ws_yy_parse(WsCompiler *compiler)
void ws_free_byte_code(unsigned char *byte_code)
void ws_hash_destroy(WsHashPtr hash)
WsResult ws_compile_file(WsCompilerPtr compiler, const char *input_name, FILE *input, FILE *output)
WsBc * ws_bc_alloc(WsBcStringEncoding string_encoding)
WsUInt32 num_local_functions
void ws_f_destroy(WsFastMalloc *pool)
WsStream * ws_stream_new_data_input(const unsigned char *data, size_t data_len)
WsCompilerPtr ws_create(WsCompilerParams *params)
static int sort_functions_cmp(const void *a, const void *b)
unsigned int use_latin1_strings
size_t ws_buffer_len(WsBuffer *buffer)
void * ws_realloc(void *ptr, size_t size)
#define WS_CHECK_COMPILE_ERROR()
static void std_io(const char *data, size_t len, void *context)
WsBool ws_bc_encode(WsBc *bc, unsigned char **data_return, size_t *data_len_return)
void ws_stream_close(WsStream *stream)
WsBool ws_lexer_register_utf8(WsCompiler *compiler, WsUtf8String *string)
void ws_destroy(WsCompilerPtr compiler)
WsResult ws_compile_data(WsCompilerPtr compiler, const char *input_name, const unsigned char *input, size_t input_len, unsigned char **output_return, size_t *output_len_return)
void ws_lexer_free_block(WsCompiler *compiler, void *ptr)
WsHashPtr ws_pragma_use_hash_create(void)
void ws_bc_free(WsBc *bc)
unsigned int print_assembler
void ws_buffer_init(WsBuffer *buffer)
void ws_asm_dasm(WsCompilerPtr compiler, const unsigned char *code, size_t len)
WsHashPtr ws_function_hash_create(void)
void ** lexer_active_list
void ws_bc_data_free(unsigned char *data)
void ws_buffer_uninit(WsBuffer *buffer)
WsUInt32 last_syntax_error_line
WsFunctionHash * ws_function_hash(WsCompilerPtr compiler, char *name)
WsBool ws_lexer_register_block(WsCompiler *compiler, void *ptr)
void ws_asm_linearize(WsCompiler *compiler)
void ws_asm_optimize(WsCompilerPtr compiler)
WsHashPtr ws_variable_hash_create(void)
WsNamespace * ws_variable_define(WsCompilerPtr compiler, WsUInt32 line, WsBool variablep, char *name)
WsUInt32 num_extern_functions
WsStream * ws_stream_new_file(FILE *fp, WsBool output, WsBool close)
const char * ws_result_to_string(WsResult result)
void ws_asm_print(WsCompiler *compiler)
WsFastMalloc * pool_stree
void ws_lexer_free_utf8(WsCompiler *compiler, WsUtf8String *string)
WsBool ws_bc_add_function(WsBc *bc, WsUInt8 *index_return, char *name, WsUInt8 num_arguments, WsUInt8 num_locals, WsUInt32 code_size, unsigned char *code)
void ws_info(WsCompilerPtr compiler, char *message,...)
unsigned char * ws_buffer_ptr(WsBuffer *buffer)
static WsResult compile_stream(WsCompilerPtr compiler, const char *input_name, WsStream *input, unsigned char **output_return, size_t *output_len_return)
void ws_stmt_linearize(WsCompiler *compiler, WsStatement *stmt)