📄 jsint.h
字号:
*/
int js_vm_execute (JSVirtualMachine *vm, JSByteCode *bc);
/*
* Apply function <func_name> to arguments <argc, argv>. If
* function's name <func_name> is NULL, then <func> must specify function
* to which arguments are applied.
*/
int js_vm_apply (JSVirtualMachine *vm, char *func_name, JSNode *func,
unsigned int argc, JSNode *argv);
/*
* Call method <method_name> from object <objet> with arguments <argc, argv>.
*/
int js_vm_call_method (JSVirtualMachine *vm, JSNode *object,
const char *method_name, unsigned int argc,
JSNode *argv);
/* Map program counter to the source file line. */
const char *js_vm_debug_position (JSVirtualMachine *vm,
unsigned int *linenum_return);
/* Fetch the function name from the program counter value. */
const char *js_vm_func_name (JSVirtualMachine *vm, void *pc);
/* Intern symbol <name, len> to virtual machine and return its JSSymbol id. */
JSSymbol js_vm_intern_with_len (JSVirtualMachine *vm, const char *name,
unsigned int len);
/* Intern symbol <name> to virtual machine and return its JSSymbol id. */
static __inline JSSymbol
js_vm_intern (JSVirtualMachine *vm, const char *name)
{
return js_vm_intern_with_len (vm, name, strlen (name));
}
/* Return the name of symbol <sym>. */
const char *js_vm_symname (JSVirtualMachine *vm, JSSymbol sym);
/*
* ToPrimitive(). Convert node <n> to its primitive value and return
* the result in <result_return>.
*/
void js_vm_to_primitive (JSVirtualMachine *vm, const JSNode *n,
JSNode *result_return, JSNodeType preferred_type);
/*
* ToString(). Convert node <n> to its string presentations and
* return the result in <result_return>.
*/
void js_vm_to_string (JSVirtualMachine *vm, const JSNode *n,
JSNode *result_return);
/*
* ToNumber(). Convert node <n> to its number presentations and
* return the result in <result_return>.
*/
void js_vm_to_number (JSVirtualMachine *vm, const JSNode *n,
JSNode *result_return);
/* ToObject(). Convert node <n> to object according to its type. */
void js_vm_to_object (JSVirtualMachine *vm, const JSNode *n,
JSNode *result_return);
/*
* ToInt32(). Convert node <n> to its signed 32 bit integer
* presentation and return the result.
*/
JSInt32 js_vm_to_int32 (JSVirtualMachine *vm, JSNode *n);
/*
* ToBoolean(). Convert node <n> to a boolean value and return the
* result.
*/
int js_vm_to_boolean (JSVirtualMachine *vm, JSNode *n);
/*
* Raise an error. The error message must have been saved to vm->error
* before this function is called. The function never returns.
*/
void js_vm_error (JSVirtualMachine *vm);
/*
* Count a hash value for <data_len> bytes of data <data>. The resulting
* hash value should be re-mapped to the correct range, for example,
* with the mod operand.
*/
static __inline unsigned int
js_count_hash (const char *data, unsigned int data_len)
{
unsigned int val = 0, i;
for (i = 0; i < data_len; i++)
val = (val << 5) ^ (unsigned char) data[i]
^ (val >> 16) ^ (val >> 7);
return val;
}
/* Prototypes for the different instruction dispatcher implementations. */
#if ALL_DISPATCHERS
int js_vm_switch0_exec (JSVirtualMachine *vm, JSByteCode *bc,
JSSymtabEntry *symtab,
unsigned int num_symtab_entries,
unsigned int consts_offset,
unsigned int anonymous_function_offset,
unsigned char *debug_info,
unsigned int debug_info_len,
JSNode *object, JSNode *func,
unsigned int argc, JSNode *argv);
const char *js_vm_switch0_func_name (JSVirtualMachine *vm, void *pc);
const char *js_vm_switch0_debug_position (JSVirtualMachine *vm,
unsigned int *linenum_return);
#endif /* ALL_DISPATCHERS */
int js_vm_switch_exec (JSVirtualMachine *vm, JSByteCode *bc,
JSSymtabEntry *symtab,
unsigned int num_symtab_entries,
unsigned int consts_offset,
unsigned int anonymous_function_offset,
unsigned char *debug_info, unsigned int debug_info_len,
JSNode *object, JSNode *func,
unsigned int argc, JSNode *argv);
const char *js_vm_switch_func_name (JSVirtualMachine *vm, void *pc);
const char *js_vm_switch_debug_position (JSVirtualMachine *vm,
unsigned int *linenum_return);
int js_vm_jumps_exec (JSVirtualMachine *vm, JSByteCode *bc,
JSSymtabEntry *symtab,
unsigned int num_symtab_entries,
unsigned int consts_offset,
unsigned int anonymous_function_offset,
unsigned char *debug_info, unsigned int debug_info_len,
JSNode *object, JSNode *func,
unsigned int argc, JSNode *argv);
const char *js_vm_jumps_func_name (JSVirtualMachine *vm, void *pc);
const char *js_vm_jumps_debug_position (JSVirtualMachine *vm,
unsigned int *linenum_return);
/* Heap. */
void *js_vm_alloc (JSVirtualMachine *vm, unsigned int size);
void *js_vm_alloc_destroyable (JSVirtualMachine *vm, unsigned int size);
void *js_vm_realloc (JSVirtualMachine *vm, void *ptr, unsigned int new_size);
void js_vm_free (JSVirtualMachine *vm, void *ptr);
void js_vm_garbage_collect (JSVirtualMachine *vm, JSNode *fp, JSNode *sp);
void js_vm_clear_heap (JSVirtualMachine *vm);
void js_vm_mark (JSNode *node);
int js_vm_mark_ptr (void *ptr);
int js_vm_is_marked_ptr (void *ptr);
/* Function. */
static __inline JSFunction *
js_vm_make_function (JSVirtualMachine *vm, void *implementation)
{
JSFunction *f = (JSFunction *) js_vm_alloc (vm, sizeof (*f));
f->implementation = implementation;
f->prototype = (JSObject *) NULL;
return f;
}
/* Built-in. */
/* Create a new built-in info. */
JSBuiltinInfo *js_vm_builtin_info_create (JSVirtualMachine *vm);
/* Create a new builtin object with <info, instance_context> to <result>. */
void js_vm_builtin_create (JSVirtualMachine *vm, JSNode *result,
JSBuiltinInfo *info, void *instance_context);
/* Array. */
static __inline void
js_vm_make_array (JSVirtualMachine *vm, JSNode *n, unsigned int length)
{
unsigned int i;
n->type = JS_ARRAY;
n->u.varray = (JSArray *) js_vm_alloc (vm, sizeof (*n->u.varray));
n->u.varray->prototype = NULL;
n->u.varray->length = length;
n->u.varray->data = (JSNode *) js_vm_alloc (vm, length * sizeof (JSNode));
for (i = 0; i < length; i++)
n->u.varray->data[i].type = JS_UNDEFINED;
}
static __inline void
js_vm_expand_array (JSVirtualMachine *vm, JSNode *n, unsigned int length)
{
if (n->u.varray->length < length)
{
n->u.varray->data = (JSNode *) js_vm_realloc (vm, n->u.varray->data,
length * sizeof (JSNode));
for (; n->u.varray->length < length; n->u.varray->length++)
n->u.varray->data[n->u.varray->length].type = JS_UNDEFINED;
}
}
/* File. */
/* Enter file <fp> to the system. */
void js_builtin_File_new (JSVirtualMachine *vm, JSNode *result_return,
char *path, JSIOStream *stream, int dont_close);
/* RegExp. */
/*
* Create a new regular expression node from <source, sourcelen> according
* to <flags>. The argument <immutable> defines whether the created
* regexp is immutable. The new regexp is returned in <result_return>.
* If the <info> is NULL, the function will resolve it. Otherwise the given
* value is used.
*/
void js_builtin_RegExp_new (JSVirtualMachine *vm, char *source,
unsigned int source_len, unsigned int flags,
int immutable, JSBuiltinInfo *info,
JSNode *result_return);
/*
* Do search-replace for the string <data, datalen> by replacing
* matches of <regexp> with <repl, repl_len>. The resulting string is
* returned in <result_return>
*/
void js_builtin_RegExp_replace (JSVirtualMachine *vm, char *data,
unsigned int datalen, JSNode *regexp,
char *repl, unsigned int repl_len,
JSNode *result_return);
/*
* Do regexp match against <data, datalen>. Format the result array
* to <result_return>.
*/
void js_builtin_RegExp_match (JSVirtualMachine *vm, char *data,
unsigned int datalen, JSNode *regexp,
JSNode *result_return);
/*
* Do regexp search against <data, datalen>. Return the start index of
* the match in <result_return>.
*/
void js_builtin_RegExp_search (JSVirtualMachine *vm, char *data,
unsigned int datalen, JSNode *regexp,
JSNode *result_return);
/*
* Split the string <data, datalen> by regular expression <regexp>.
* Function returns an array containing the substrings.
*/
void js_builtin_RegExp_split (JSVirtualMachine *vm, char *data,
unsigned int datalen, JSNode *regexp,
unsigned int limit, JSNode *result_return);
/* Object. */
JSObject *js_vm_object_new (JSVirtualMachine *vm);
void js_vm_object_mark (JSObject *obj);
int js_vm_object_load_property (JSVirtualMachine *vm, JSObject *obj,
JSSymbol prop, JSNode *value_return);
void js_vm_object_store_property (JSVirtualMachine *vm, JSObject *obj,
JSSymbol prop, JSNode *value);
void js_vm_object_delete_property (JSVirtualMachine *vm, JSObject *obj,
JSSymbol prop);
void js_vm_object_load_array (JSVirtualMachine *vm, JSObject *obj, JSNode *sel,
JSNode *value_return);
void js_vm_object_store_array (JSVirtualMachine *vm, JSObject *obj,
JSNode *sel, JSNode *value);
void js_vm_object_delete_array (JSVirtualMachine *vm, JSObject *obj,
JSNode *sel);
int js_vm_object_nth (JSVirtualMachine *vm, JSObject *obj, int nth,
JSNode *value_return);
/* Debug. */
void js_vm_stacktrace (JSVirtualMachine *vm, unsigned int num_frames);
/* Strings. */
static __inline void
js_vm_make_string (JSVirtualMachine *vm, JSNode *n, const char *data,
unsigned int data_len)
{
n->type = JS_STRING;
n->u.vstring = (JSString *) js_vm_alloc (vm, sizeof (*n->u.vstring));
n->u.vstring->staticp = 0;
n->u.vstring->prototype = NULL;
n->u.vstring->len = data_len;
n->u.vstring->data = (unsigned char *) js_vm_alloc (vm, data_len);
if (data)
memcpy (n->u.vstring->data, data, data_len);
}
static __inline void
js_vm_make_static_string (JSVirtualMachine *vm, JSNode *n, const char *data,
unsigned int data_len)
{
n->type = JS_STRING;
n->u.vstring = (JSString *) js_vm_alloc (vm, sizeof (*n->u.vstring));
n->u.vstring->staticp = 1;
n->u.vstring->prototype = NULL;
n->u.vstring->len = data_len;
n->u.vstring->data = (unsigned char *) data;
}
static __inline int
js_compare_strings (JSNode *a, JSNode *b)
{
unsigned int i;
for (i = 0; i < a->u.vstring->len && i < b->u.vstring->len; i++)
{
if (a->u.vstring->data[i] < b->u.vstring->data[i])
return -1;
if (a->u.vstring->data[i] > b->u.vstring->data[i])
return 1;
}
if (a->u.vstring->len < b->u.vstring->len)
return -1;
if (a->u.vstring->len > b->u.vstring->len)
return 1;
return 0;
}
static __inline char *
js_string_to_c_string (JSVirtualMachine *vm, const JSNode *a)
{
char *cp;
cp = (char *) js_malloc (vm, a->u.vstring->len + 1);
memcpy (cp, a->u.vstring->data, a->u.vstring->len);
cp[a->u.vstring->len] = '\0';
return cp;
}
/* Dynamic loading. */
/*
* Try to open shared library <filename>. If the opening was
* successful, a handle to the library is returned. Otherwise, the
* function returns NULL, and an error message is returned in
* <error_return>. The argument <error_return_len> specifies the
* maximum length of the error message the function should return.
*/
void *js_dl_open (const char *filename, char *error_return,
unsigned int error_return_len);
/*
* Try to fetch the address of the symbol <symbol> from shared library
* <library>.
*/
void *js_dl_sym (void *library, char *symbol, char *error_return,
unsigned int error_return_len);
/* Misc helper functions. */
unsigned long js_crc32 (const unsigned char *s, unsigned int len);
/*
* Definitions for the JavaScript part of the JavaScript interp.
*/
/* Flags for the compiler. See `jsc/entry.js'. */
#define JSC_FLAG_VERBOSE 0x00000001
#define JSC_FLAG_ANNOTATE_ASSEMBLER 0x00000002
#define JSC_FLAG_GENERATE_DEBUG_INFO 0x00000004
#define JSC_FLAG_GENERATE_EXECUTABLE_BC_FILES 0x00000008
#define JSC_FLAG_OPTIMIZE_PEEPHOLE 0x00000020
#define JSC_FLAG_OPTIMIZE_JUMPS 0x00000040
#define JSC_FLAG_OPTIMIZE_BC_SIZE 0x00000080
#define JSC_FLAG_OPTIMIZE_HEAVY 0x00000100
#define JSC_FLAG_OPTIMIZE_MASK 0x0000fff0
#define JSC_FLAG_WARN_UNUSED_ARGUMENT 0x00010000
#define JSC_FLAG_WARN_UNUSED_VARIABLE 0x00020000
#define JSC_FLAG_WARN_SHADOW 0x00040000
#define JSC_FLAG_WARN_WITH_CLOBBER 0x00080000
#define JSC_FLAG_WARN_MISSING_SEMICOLON 0x00100000
#define JSC_FLAG_WARN_STRICT_ECMA 0x00200000
#define JSC_FLAG_WARN_DEPRECATED 0x00400000
#define JSC_FLAG_WARN_MASK 0xffff0000
/* JavaScript interpreter handle. */
struct js_interp_st
{
JSInterpOptions options;
JSVirtualMachine *vm;
};
/* Declaration for the JS compiler byte-code. */
extern unsigned char js_compiler_bytecode[];
extern unsigned int js_compiler_bytecode_len;
#ifdef __cplusplus
}
#endif
#endif /* not JSINT_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -