Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

ws.h File Reference

#include "wsutf8.h"

Include dependency graph for ws.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  WsCompilerParamsRec

Typedefs

typedef void(* WsIOProc )(const char *data, size_t len, void *context)
typedef void(* WsPragmaMetaProc )(const WsUtf8String *property_name, const WsUtf8String *content, const WsUtf8String *scheme, void *context)
typedef WsCompilerParamsRec WsCompilerParams
typedef WsCompilerRecWsCompilerPtr

Enumerations

enum  WsResult {
  WS_OK, WS_ERROR_OUT_OF_MEMORY, WS_ERROR_SYNTAX, WS_ERROR_SEMANTIC,
  WS_ERROR_IO, WS_ERROR
}

Functions

WsCompilerPtr ws_create (WsCompilerParams *params)
void ws_destroy (WsCompilerPtr compiler)
WsResult ws_compile_file (WsCompilerPtr compiler, const char *input_name, FILE *input, FILE *output)
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_free_byte_code (unsigned char *byte_code)
const char * ws_result_to_string (WsResult result)


Typedef Documentation

typedef struct WsCompilerParamsRec WsCompilerParams
 

Definition at line 182 of file ws.h.

Referenced by convert_wmlscript_to_wmlscriptc(), main(), and ws_create().

typedef struct WsCompilerRec* WsCompilerPtr
 

Definition at line 185 of file ws.h.

Referenced by buffer_to_int(), compile_stream(), convert_wmlscript_to_wmlscriptc(), main(), opt_conv(), opt_dead_code(), opt_jumps_to_jumps(), opt_jumps_to_next_instruction(), opt_peephole(), ws_asm_optimize(), ws_compile_data(), ws_compile_file(), ws_create(), ws_destroy(), ws_error_memory(), ws_error_syntax(), ws_expr_assign(), ws_expr_binary(), ws_expr_comma(), ws_expr_conditional(), ws_expr_logical(), ws_expr_postfix_var(), ws_expr_unary(), ws_expr_unary_var(), ws_formal_parameter(), ws_function_hash(), ws_info(), ws_pragma_meta_body(), ws_pragma_meta_body_free(), ws_pragma_use(), ws_src_error(), ws_src_warning(), ws_stmt_for(), ws_stmt_return(), ws_stmt_variable(), ws_variable_declaration(), ws_variable_define(), and ws_variable_lookup().

typedef void(* WsIOProc)(const char *data, size_t len, void *context)
 

Definition at line 84 of file ws.h.

typedef void(* WsPragmaMetaProc)(const WsUtf8String *property_name, const WsUtf8String *content, const WsUtf8String *scheme, void *context)
 

Definition at line 95 of file ws.h.


Enumeration Type Documentation

enum WsResult
 

Enumeration values:
WS_OK 
WS_ERROR_OUT_OF_MEMORY 
WS_ERROR_SYNTAX 
WS_ERROR_SEMANTIC 
WS_ERROR_IO 
WS_ERROR 

Definition at line 203 of file ws.h.

Referenced by compile_stream(), convert_wmlscript_to_wmlscriptc(), main(), ws_compile_data(), and ws_compile_file().

00204 {
00205     /* Successful termination */
00206     WS_OK,
00207 
00208     /* The compiler ran out of memory. */
00209     WS_ERROR_OUT_OF_MEMORY,
00210 
00211     /* The input was not syntactically correct. */
00212     WS_ERROR_SYNTAX,
00213 
00214     /* The input was not semantically correct. */
00215     WS_ERROR_SEMANTIC,
00216 
00217     /* IO error. */
00218     WS_ERROR_IO,
00219 
00220     /* A generic `catch-all' error code.  This should not be used.  More
00221        descriptive error messages should be generated instead. */
00222     WS_ERROR
00223 } WsResult;


Function Documentation

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
 

Definition at line 206 of file ws.c.

References compile_stream(), result, ws_stream_close(), ws_stream_new_data_input(), WsCompilerPtr, WsResult, and WsStream.

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

00210 {
00211     WsResult result;
00212     WsStream *stream;
00213 
00214     /* Initialize the input stream. */
00215     stream = ws_stream_new_data_input(input, input_len);
00216     if (stream == NULL)
00217         return WS_ERROR_OUT_OF_MEMORY;
00218 
00219     result = compile_stream(compiler, input_name, stream, output_return,
00220                             output_len_return);
00221 
00222     ws_stream_close(stream);
00223 
00224     return result;
00225 }

Here is the call graph for this function:

WsResult ws_compile_file WsCompilerPtr  compiler,
const char *  input_name,
FILE *  input,
FILE *  output
 

Definition at line 177 of file ws.c.

References compile_stream(), result, ws_bc_data_free(), WS_FALSE, ws_stream_close(), ws_stream_new_file(), WsCompilerPtr, WsResult, and WsStream.

Referenced by main().

00179 {
00180     WsResult result;
00181     WsStream *stream;
00182     unsigned char *bc;
00183     size_t bc_len;
00184 
00185     /* Initialize the input stream. */
00186     stream = ws_stream_new_file(input, WS_FALSE, WS_FALSE);
00187     if (stream == NULL)
00188         return WS_ERROR_OUT_OF_MEMORY;
00189 
00190     result = compile_stream(compiler, input_name, stream, &bc, &bc_len);
00191 
00192     ws_stream_close(stream);
00193 
00194     if (result == WS_OK) {
00195         /* Store the result to the file. */
00196         if (fwrite(bc, 1, bc_len, output) != bc_len)
00197             result = WS_ERROR_IO;
00198 
00199         ws_bc_data_free(bc);
00200     }
00201 
00202     return result;
00203 }

Here is the call graph for this function:

WsCompilerPtr ws_create WsCompilerParams params  ) 
 

Definition at line 135 of file ws.c.

References WsCompilerRec::params, WsCompilerParamsRec::stderr_cb, WsCompilerParamsRec::stderr_cb_context, WsCompilerParamsRec::stdout_cb, WsCompilerParamsRec::stdout_cb_context, ws_calloc(), WsCompilerParams, and WsCompilerPtr.

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

00136 {
00137     WsCompilerPtr compiler = ws_calloc(1, sizeof(*compiler));
00138 
00139     if (compiler == NULL)
00140         return NULL;
00141 
00142     /* Store user params if specified. */
00143     if (params)
00144         compiler->params = *params;
00145 
00146     /* Basic initialization. */
00147 
00148     compiler->magic = COMPILER_MAGIC;
00149 
00150     if (compiler->params.stdout_cb == NULL) {
00151         compiler->params.stdout_cb = std_io;
00152         compiler->params.stdout_cb_context = stdout;
00153     }
00154     if (compiler->params.stderr_cb == NULL) {
00155         compiler->params.stderr_cb = std_io;
00156         compiler->params.stderr_cb_context = stderr;
00157     }
00158 
00159     return compiler;
00160 }

Here is the call graph for this function:

void ws_destroy WsCompilerPtr  compiler  ) 
 

Definition at line 163 of file ws.c.

References ws_free(), and WsCompilerPtr.

Referenced by main().

00164 {
00165     if (compiler == NULL)
00166         return;
00167 
00168     ws_free(compiler);
00169 
00170 #if WS_MEM_DEBUG
00171     if (ws_has_leaks())
00172         ws_dump_blocks();
00173 #endif /* WS_MEM_DEBUG */
00174 }

Here is the call graph for this function:

void ws_free_byte_code unsigned char *  byte_code  ) 
 

Definition at line 228 of file ws.c.

References ws_bc_data_free().

Referenced by main().

00229 {
00230     ws_bc_data_free(byte_code);
00231 }

Here is the call graph for this function:

const char* ws_result_to_string WsResult  result  ) 
 

Definition at line 234 of file ws.c.

References result_codes.

Referenced by convert_wmlscript_to_wmlscriptc(), and main().

00235 {
00236     int i;
00237 
00238     for (i = 0; result_codes[i].description; i++) {
00239         if (result_codes[i].code == result)
00240             return result_codes[i].description;
00241     }
00242 
00243     return "unknown result code";
00244 }

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.