⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jsint.h

📁 一个类似windows
💻 H
📖 第 1 页 / 共 4 页
字号:
		  if (r.type == JS_INTEGER)				\
		    res = l.u.vinteger _OP_ r.u.vinteger;		\
		  else							\
		    res = (double) l.u.vinteger _OP_ r.u.vfloat;	\
		}							\
	      else							\
		{							\
		  if (r.type == JS_INTEGER)				\
		    res = l.u.vfloat _OP_ (double) r.u.vinteger;	\
		  else							\
		    res = l.u.vfloat _OP_ r.u.vfloat;			\
		}							\
	    }								\
	  else if (JS_SP2->type == JS_OBJECT				\
		   && (JS_SP1->type == JS_STRING			\
		       || JS_IS_NUMBER (JS_SP1)))			\
	    {								\
	      JSNode cvt;						\
									\
	      /* ECMA 11.9.3 21. No preferred type specified. */	\
	      js_vm_to_primitive (vm, JS_SP2, &cvt, JS_UNDEFINED);	\
	      JS_COPY (JS_SP2, &cvt);					\
	      continue;							\
	    }								\
	  else if (JS_SP1->type == JS_OBJECT				\
		   && (JS_SP2->type == JS_STRING			\
		       || JS_IS_NUMBER (JS_SP2)))			\
	    {								\
	      JSNode cvt;						\
									\
	      /* ECMA 11.9.3 20. No preferred type specified. */	\
	      js_vm_to_primitive (vm, JS_SP1, &cvt, JS_UNDEFINED);	\
	      JS_COPY (JS_SP1, &cvt);					\
	      continue;							\
	    }								\
	  else								\
	    res = !_VAL_;						\
	}								\
    }									\
									\
  JS_SP2->type = JS_BOOLEAN;						\
  JS_SP2->u.vboolean = res;						\
  JS_POP ();								\
  break;								\
  }

#define JS_OPERAND_CMP_SEQ(_OP_, _VAL_)					\
  do {									\
  int res;								\
  if (JS_SP2->type == JS_SP1->type)					\
    {									\
      switch (JS_SP2->type)						\
	{								\
	case JS_INTEGER:						\
	  res = JS_SP2->u.vinteger _OP_ JS_SP1->u.vinteger;		\
	  break;							\
									\
	case JS_FLOAT:							\
	  res = JS_SP2->u.vfloat _OP_ JS_SP1->u.vfloat;			\
	  break;							\
									\
	case JS_NAN:							\
	  /* 11.9.6: cases 3 and 4 */					\
	  res = !_VAL_;							\
	  break;							\
									\
	case JS_STRING:							\
	  res = js_compare_strings (JS_SP2, JS_SP1) _OP_ 0;		\
	  break;							\
									\
	case JS_BOOLEAN:						\
	  res = JS_SP2->u.vboolean _OP_ JS_SP1->u.vboolean;		\
	  break;							\
									\
	case JS_OBJECT:							\
	  res = JS_SP2->u.vobject _OP_ JS_SP1->u.vobject;		\
	  break;							\
									\
	case JS_BUILTIN:						\
	  res = ((JS_SP2->u.vbuiltin->info				\
		  == JS_SP1->u.vbuiltin->info				\
		  && (JS_SP2->u.vbuiltin->instance_context		\
		      == JS_SP1->u.vbuiltin->instance_context))		\
		 ? _VAL_ : !_VAL_);					\
	  break;							\
									\
	case JS_FUNC:							\
	  res = JS_SP2->u.vfunction _OP_ JS_SP1->u.vfunction;		\
	  break;							\
									\
	default:							\
	  /* 11.9.6: case 12 */						\
	  res = !_VAL_;							\
	  break;							\
	}								\
    }									\
  else									\
    {									\
      /* Only numbers are allowed here. */				\
      if (JS_IS_NUMBER (JS_SP2) && JS_IS_NUMBER (JS_SP1))		\
	{								\
	  if (JS_SP2->type == JS_NAN || JS_SP1->type == JS_NAN)		\
	    /* 11.9.6: cases 3 and 4 */					\
	    res = !_VAL_;						\
	  else if (JS_SP2->type == JS_INTEGER)				\
	    res = (double) JS_SP2->u.vinteger _OP_ JS_SP1->u.vfloat;	\
	  else								\
	    res = JS_SP2->u.vfloat _OP_ (double) JS_SP1->u.vinteger;	\
	}								\
      else								\
	res = !_VAL_;							\
    }									\
									\
  JS_SP2->type = JS_BOOLEAN;						\
  JS_SP2->u.vboolean = res;						\
  JS_POP ();								\
									\
  } while (0)

#define JS_OPERAND_BINARY(_OP_)					\
  do {								\
  if (JS_SP2->type == JS_INTEGER && JS_SP1->type == JS_INTEGER) \
    {								\
      JS_SP2->u.vinteger = ((JSInt32) JS_SP2->u.vinteger	\
			    _OP_ (JSInt32) JS_SP1->u.vinteger); \
      JS_POP ();						\
    }								\
  else								\
    {								\
      JSInt32 l, r;						\
								\
      l = js_vm_to_int32 (vm, JS_SP2);				\
      r = js_vm_to_int32 (vm, JS_SP1);				\
								\
      JS_SP2->u.vinteger = (l _OP_ r);				\
      JS_SP2->type = JS_INTEGER;				\
      JS_POP ();						\
    }								\
  } while (0)


#define JS_IS_NUMBER(n) \
  ((n)->type == JS_INTEGER || (n)->type == JS_FLOAT || (n)->type == JS_NAN)

/* Some math macros. */

#define JS_MAKE_POSITIVE_INFINITY(node) \
  do {					\
    (node)->type = JS_FLOAT;		\
    (node)->u.vfloat = HUGE_VAL;	\
  } while (0)

#define JS_MAKE_NEGATIVE_INFINITY(node) \
  do {					\
    (node)->type = JS_FLOAT;		\
    (node)->u.vfloat = -HUGE_VAL;	\
  } while (0)

#define JS_IS_POSITIVE_INFINITY(node) \
  ((node)->type == JS_FLOAT && (node)->u.vfloat == HUGE_VAL)

#define JS_IS_NEGATIVE_INFINITY(node) \
  ((node)->type == JS_FLOAT && (node)->u.vfloat == -HUGE_VAL)

#define JS_IS_FINITE(node)		\
  (!JS_IS_POSITIVE_INFINITY ((node))	\
   && !JS_IS_NEGATIVE_INFINITY ((node)) \
   && (node)->type != JS_NAN)		\

#define JS_IS_PRIMITIVE_VALUE(node)				\
  ((node)->type == JS_UNDEFINED || (node)->type == JS_NULL	\
   || (node)->type == JS_BOOLEAN || JS_IS_NUMBER ((node))	\
   || (node)->type == JS_STRING)

/* Macro to clear all flags from a heap memory block. */
#define JS_HEAP_MEMORY_BLOCK_CLEAR_FLAGS(mb)	\
  do {						\
    (mb)->flag_mark = 0;			\
    (mb)->flag_destroyable = 0;			\
  } while (0)

#define JS_NUM_HEAP_FREELISTS	20

/*
 * Virtual machine security flags.  When these flags are enabled in
 * the vm->security, the appropriate built-in modules don't implement
 * insecure methods.
 */

#define JS_VM_SECURE_FILE	0x01
#define JS_VM_SECURE_SYSTEM	0x02

/*
 * Noticeable virtual machine events.  The `JS_VM_EVENT_OPERAND_COUNT'
 * event is generated only if the interpreter was configured with the
 * `--enable-operand-hooks' option.
 */

#define JS_VM_EVENT_OPERAND_COUNT	1
#define JS_VM_EVENT_GARBAGE_COLLECT	2

/*
 * Integer types.
 */

typedef unsigned char JSUInt8;
typedef signed char JSInt8;

typedef unsigned short JSUInt16;
typedef short JSInt16;

#if SIZEOF_INT == 4

typedef unsigned int JSUInt32;
typedef int JSInt32;

#else /* not SIZEOF_INT == 4 */

#if SIZEOF_LONG == 4

typedef unsigned long JSUInt32;
typedef long JSInt32;

#else /* not SIZEOF_LONG == 4 */

#error "do not know how to define a 32 bit long integer"

#endif /* not SIZEOF_LONG == 4 */

#endif /* not SIZEOF_INT == 4 */

/*
 * An unsigned interger number that can be used to align structures to
 * correct byte boundaries.  On 64 bit machines (Alpha) this should be
 * 64 bits long, etc.  For now one, we just assume that the mashine is
 * a LP64 so the `unsigned long' is a correct type for it.
 */
typedef unsigned long JSUIntAlign;

/* I/O streams. */

/* Buffer filler or flusher function. */
typedef int (*JSIOStreamIOFunc) (void *context, unsigned char *buffer,
				 unsigned int todo, int *error_return);

typedef int (*JSIOStreamSeek) (void *context, long offset, int whence);

typedef long (*JSIOStreamGetPosition) (void *context);

typedef long (*JSIOStreamGetLength) (void *context);

typedef void (*JSIOStreamClose) (void *context);

/* The I/O stream handle. */
struct js_io_stream_st
{
  unsigned char *buffer;	/* Must be reallocatable with js_realloc(). */
  unsigned int buflen;
  unsigned int data_in_buf;
  unsigned int bufpos;

  /* Flags. */
  unsigned int at_eof : 1;
  unsigned int autoflush : 1;
  unsigned int writep : 1;	/* Does the buffer contain write data? */

  /* The system error code for the last operation that failed. */
  int error;

  /* Only one of the read and write is active. */
  JSIOStreamIOFunc	read;
  JSIOStreamIOFunc	write;
  JSIOStreamSeek	seek;
  JSIOStreamGetPosition	get_position;
  JSIOStreamGetLength	get_length;

  JSIOStreamClose close;

  void *context;
};

typedef struct js_io_stream_st JSIOStream;


/* The destroy callback for the destroyable heap blocks. */
typedef void (*JSHeapDestroyableCB) (void *ptr);

/*
 * Each destroyable heap block must be castable to this structure e.g.
 * the first item in the block must be pointer to the destroy function.
 */
struct js_heap_destroyable_st
{
  JSHeapDestroyableCB destroy;
};

typedef struct js_heap_destroyable_st JSHeapDestroyable;


/* Interned symbol. */
typedef unsigned int JSSymbol;

/* JavaScript Types. */

typedef enum
{
  JS_UNDEFINED	= 0,
  JS_NULL	= 1,
  JS_BOOLEAN 	= 2,
  JS_INTEGER 	= 3,		/* Integer, float and nan are `number' */
  JS_STRING 	= 4,
  JS_FLOAT 	= 5,
  JS_ARRAY	= 6,
  JS_OBJECT	= 7,

  /*
   * The following ones are the internal types, used by this implementation.
   */

  JS_SYMBOL 	= 10,
  JS_BUILTIN 	= 11,
  JS_FUNC	= 12,
  JS_NAN	= 13,

  JS_IPTR 	= 14,
  JS_ARGS_FIX	= 15
} JSNodeType;

struct js_node_st;
struct js_vm_st;
struct js_builtin_info_st;

/* Registry information for builtin objects. */

#define JS_PROPERTY_FOUND	1
#define JS_PROPERTY_UNKNOWN	0

typedef void (*JSBuiltinGlobalMethod) (struct js_vm_st *vm,
				       struct js_builtin_info_st *builtin_info,
				       void *instance_context,
				       struct js_node_st *result_return,
				       struct js_node_st *args);

/*
 * Function to call method <method> from the object.  Function must return
 * JS_PROPERTY_FOUND if the method was found or JS_PROPERTY_UNKNOWN
 * otherwise.
 */
typedef int (*JSBuiltinMethod) (struct js_vm_st *vm,
				struct js_builtin_info_st *builtin_info,
				void *instance_context,
				JSSymbol method,
				struct js_node_st *result_return,
				struct js_node_st *args);

/*
 * Function to load and set property <property> of object.  If <set>
 * is true, property <property> should be set to value <node>.  Otherwise
 * function should return the value of property <property> in <node>.
 * Function must return JS_PROPERTY_FOUND if the property was found or
 * JS_PROPERTY_UNKNOWN otherwise.
 */
typedef int (*JSBuiltinProperty) (struct js_vm_st *vm,
				  struct js_builtin_info_st *builtin_info,
				  void *instance_context,
				  JSSymbol property, int set,
				  struct js_node_st *node);

typedef void (*JSBuiltinNew) (struct js_vm_st *vm,
			      struct js_builtin_info_st *builtin_info,
			      struct js_node_st *args,
			      struct js_node_st *result_return);

typedef void (*JSBuiltinDelete) (struct js_builtin_info_st *builtin_info,
				 void *instance_context);

typedef void (*JSBuiltinMark) (struct js_builtin_info_st *builtin_info,
			       void *instance_context);

typedef void (*JSBuiltinObjectCtxDelete) (void *obj_context);

struct js_builtin_info_st
{
  JSHeapDestroyableCB	destroy;

  JSBuiltinGlobalMethod	global_method_proc;
  JSBuiltinMethod 	method_proc;
  JSBuiltinProperty	property_proc;
  JSBuiltinNew		new_proc;
  JSBuiltinDelete	delete_proc;
  JSBuiltinMark		mark_proc;

  void *obj_context;
  JSBuiltinObjectCtxDelete obj_context_delete;

  struct js_object_st *prototype;
};

typedef struct js_builtin_info_st JSBuiltinInfo;

/* Builtin object / class. */
struct js_builtin_st
{
  JSHeapDestroyableCB destroy;

  JSBuiltinInfo *info;
  void *instance_context;

  struct js_object_st *prototype;
};

typedef struct js_builtin_st JSBuiltin;

/* String. */
struct js_string_st
{
  /* Flags. */
  unsigned int staticp : 1;

  unsigned char *data;
  unsigned int len;

  struct js_object_st *prototype;
};

typedef struct js_string_st JSString;

/* Array. */
struct js_array_st
{
  unsigned int length;
  struct js_node_st *data;

  struct js_object_st *prototype;
};

typedef struct js_array_st JSArray;

/* Function. */
struct js_function_st
{
  void *implementation;
  struct js_object_st *prototype;
};

typedef struct js_function_st JSFunction;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -