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

📄 eswt0.h

📁 一个类似windows
💻 H
📖 第 1 页 / 共 4 页
字号:
      if (JS_SP1->type == JS_INTEGER)
	{
	  ERROR ("integer indexes not implemented yet for BUILTIN in load_array");
	}
      else if (JS_SP1->type == JS_STRING)
	{
	  /* Intern the string. */
	  j = js_vm_intern_with_len (vm, (char*)JS_SP1->u.vstring->data,
				     JS_SP1->u.vstring->len);

	  /* The code below must be in sync with operand `load_property'. */
	  JS_SAVE_REGS ();

	  if (JS_SP2->u.vbuiltin->info->property_proc)
	    {
	      if ((*JS_SP2->u.vbuiltin->info->property_proc) (
					vm,
					JS_SP2->u.vbuiltin->info,
					JS_SP2->u.vbuiltin->instance_context,
					j, 0, &builtin_result)
		  == JS_PROPERTY_UNKNOWN)
		{
		  if (j == vm->syms.s_prototype)
		    {
		      /* Looking up the prototype. */

		      builtin_result.type = JS_OBJECT;
		      if (JS_SP2->u.vbuiltin->prototype)
			/* This is an instance. */
			builtin_result.u.vobject
			  = JS_SP2->u.vbuiltin->prototype;
		      else
			/* This is a class. */
			builtin_result.u.vobject
			  = JS_SP2->u.vbuiltin->info->prototype;
		    }
		  else
		    {
		      /* Looking up stuffs from the prototype. */

		      if (JS_SP2->u.vbuiltin->prototype)
			/* An instance. */
			js_vm_object_load_property (
						vm,
						JS_SP2->u.vbuiltin->prototype,
						j, &builtin_result);
		      else
			/* A class. */
			js_vm_object_load_property (
					vm,
					JS_SP2->u.vbuiltin->info->prototype,
					j, &builtin_result);
		    }
		}
	      JS_COPY (JS_SP2, &builtin_result);
	      JS_POP ();
	    }
	  else
	    ERROR ("illegal builtin object for load_array");
	}
      else
	{
	  sprintf (buf, "illegal array index in load_array (%d)",
		   JS_SP1->type);
	  ERROR (buf);
	}
    }
  else if (JS_SP2->type == JS_OBJECT)
    {
      js_vm_object_load_array (vm, JS_SP2->u.vobject, JS_SP1, JS_SP2);
      JS_POP ();
    }
  else if (JS_SP2->type == JS_ARRAY)
    {
      if (JS_SP1->type == JS_INTEGER)
	{
	  if (JS_SP1->u.vinteger < 0
	      || JS_SP1->u.vinteger >= JS_SP2->u.varray->length)
	    JS_SP2->type = JS_UNDEFINED;
	  else
	    {
	      JSNode *n = &JS_SP2->u.varray->data[JS_SP1->u.vinteger];
	      JS_COPY (JS_SP2, n);
	    }
	  JS_POP ();
	}
      else
	{
	  sprintf (buf, "illegal array index in load_array (%d)",
		   JS_SP1->type);
	  ERROR (buf);
	}
    }
  else if (JS_SP2->type == JS_STRING)
    {
      if (JS_SP1->type == JS_INTEGER)
	{
	  int ch;

	  if (JS_SP1->u.vinteger < 0
	      || JS_SP1->u.vinteger >= JS_SP2->u.vstring->len)
	    ERROR ("string index out of range in load_array");

	  ch = JS_SP2->u.vstring->data[JS_SP1->u.vinteger];
	  JS_SP2->type = JS_INTEGER;
	  JS_SP2->u.vinteger = ch;

	  JS_POP ();
	}
      else
	ERROR ("illegal string index in load_array");
    }
  else
    ERROR ("illegal object for load_array");
  break;

/* operand store_array (28) */
case 28:
  if (JS_SP2->type == JS_BUILTIN)
    {
      if (JS_SP1->type == JS_INTEGER)
	{
	  ERROR ("integer index not implemented yet for BUILTIN in store_array");
	}
      else if (JS_SP1->type == JS_STRING)
	{
	  /* Intern the string. */
	  j = js_vm_intern_with_len (vm, (char*)JS_SP1->u.vstring->data,
				     JS_SP1->u.vstring->len);

	  /* The code below msut be in sync with operand `store_property'. */
	  JS_SAVE_REGS ();
	  if (JS_SP2->u.vbuiltin->info->property_proc)
	    {
	      if ((*JS_SP2->u.vbuiltin->info->property_proc) (
					vm,
					JS_SP2->u.vbuiltin->info,
					JS_SP2->u.vbuiltin->instance_context,
					j, 1, JS_SP (3))
		  == JS_PROPERTY_UNKNOWN)
		{
		  if (j == vm->syms.s_prototype)
		    {
		      /* Setting the prototype. */
		      if (JS_SP (3)->type != JS_OBJECT)
			ERROR ("illegal value for prototype");

		      if (JS_SP2->u.vbuiltin->prototype)
			/* Setting the instance's prototype. */
			JS_SP2->u.vbuiltin->prototype = JS_SP (3)->u.vobject;
		      else
			/* Setting the class' prototype. */
			JS_SP2->u.vbuiltin->info->prototype
			  = JS_SP (3)->u.vobject;
		    }
		  else
		    {
		      /* Setting stuff to the prototype. */
		      if (JS_SP2->u.vbuiltin->prototype)
			/* An instance. */
			js_vm_object_store_property (
						vm,
						JS_SP2->u.vbuiltin->prototype,
						j, JS_SP (3));
		      else
			/* A class. */
			js_vm_object_store_property (
					vm,
					JS_SP2->u.vbuiltin->info->prototype,
					j, JS_SP (3));
		    }
		}
	    }
	  else
	    ERROR ("illegal builtin object for store_array");

	  JS_POP_N (3);
	}
      else
	ERROR ("illegal array index in store_array");
    }
  else if (JS_SP2->type == JS_OBJECT)
    {
      js_vm_object_store_array (vm, JS_SP2->u.vobject, JS_SP1, JS_SP (3));
      JS_POP_N (3);
    }
  else if (JS_SP2->type == JS_ARRAY)
    {
      if (JS_SP1->type == JS_INTEGER)
	{
	  if (JS_SP1->u.vinteger < 0)
	    ERROR ("negative array index in store_array");
	  if (JS_SP1->u.vinteger >= JS_SP2->u.varray->length)
	    js_vm_expand_array (vm, JS_SP2, JS_SP1->u.vinteger + 1);

	  JS_COPY (&JS_SP2->u.varray->data[JS_SP1->u.vinteger], JS_SP (3));
	  JS_POP_N (3);
	}
      else
	ERROR ("illegal array index in store_array");
    }
  else if (JS_SP2->type == JS_STRING)
    {
      if (JS_SP1->type == JS_INTEGER)
	{
	  if (JS_SP2->u.vstring->staticp)
	    ERROR ("static string in store_array");

	  if (JS_SP1->u.vinteger < 0)
	    ERROR ("negative string index in store_array");

	  if (JS_SP (3)->type != JS_INTEGER)
	    ERROR ("non-integer value to store into string in store_array");

	  if (JS_SP1->u.vinteger >= JS_SP2->u.vstring->len)
	    {
	      /* Expand the string. */
	      JS_SP2->u.vstring->data = js_vm_realloc (vm,
						       JS_SP2->u.vstring->data,
						       JS_SP1->u.vinteger + 1);
	      /* Fill the gap with ' '. */
	      for (; JS_SP2->u.vstring->len <= JS_SP1->u.vinteger;)
		JS_SP2->u.vstring->data[JS_SP2->u.vstring->len++] = ' ';
	    }

	  JS_SP2->u.vstring->data[JS_SP1->u.vinteger]
	    = (unsigned char) JS_SP (3)->u.vinteger;
	  JS_POP_N (3);
	}
      else
	ERROR ("illegal string index in store_array");
    }
  else
    ERROR ("illegal object for store_array");

  JS_MAYBE_GC ();
  break;

/* operand nth (29) */
case 29:
  if (JS_SP2->type == JS_STRING)
    {
      if (JS_SP1->u.vinteger < 0
	  || JS_SP1->u.vinteger >= JS_SP2->u.vstring->len)
	{
	  JS_SP2->type = JS_UNDEFINED;

	  JS_SP1->type = JS_BOOLEAN;
	  JS_SP1->u.vboolean = 0;
	}
      else
	{
	  JS_SP2->type = JS_INTEGER;
	  JS_SP2->u.vinteger = JS_SP2->u.vstring->data[JS_SP1->u.vinteger];

	  JS_SP1->type = JS_BOOLEAN;
	  JS_SP1->u.vboolean = 1;
	}
    }
  else if (JS_SP2->type == JS_ARRAY)
    {
      if (JS_SP1->u.vinteger < 0
	  || JS_SP1->u.vinteger >= JS_SP2->u.varray->length)
	{
	  JS_SP2->type = JS_UNDEFINED;

	  JS_SP1->type = JS_BOOLEAN;
	  JS_SP1->u.vboolean = 0;
	}
      else
	{
	  JSNode *n = &JS_SP2->u.varray->data[JS_SP1->u.vinteger];
	  JS_COPY (JS_SP2, n);

	  JS_SP1->type = JS_BOOLEAN;
	  JS_SP1->u.vboolean = 1;
	}
    }
  else if (JS_SP2->type == JS_OBJECT)
    {
      i = js_vm_object_nth (vm, JS_SP2->u.vobject, JS_SP1->u.vinteger, JS_SP2);
      JS_SP1->type = JS_BOOLEAN;
      JS_SP1->u.vboolean = i;
    }
  else
    ERROR ("illegal object for nth");
  break;

/* operand cmp_eq (30) */
case 30:
  JS_OPERAND_CMP_EQ (==, 1);
  break;

/* operand cmp_ne (31) */
case 31:
  JS_OPERAND_CMP_EQ (!=, 0);
  break;

/* operand cmp_lt (32) */
case 32:
  JS_OPERAND_CMP_REL (<);
  break;

/* operand cmp_gt (33) */
case 33:
  JS_OPERAND_CMP_REL (>);
  break;

/* operand cmp_le (34) */
case 34:
  JS_OPERAND_CMP_REL (<=);
  break;

/* operand cmp_ge (35) */
case 35:
  JS_OPERAND_CMP_REL (>=);
  break;

/* operand cmp_seq (36) */
case 36:
  JS_OPERAND_CMP_SEQ (==, 1);
  break;

/* operand cmp_sne (37) */
case 37:
  JS_OPERAND_CMP_SEQ (!=, 0);
  break;

/* operand sub (38) */
case 38:
  if (JS_SP2->type == JS_INTEGER && JS_SP1->type == JS_INTEGER)
    {
      JS_SP2->u.vinteger -= JS_SP1->u.vinteger;
    }
  else
    {
      JSNode l_cvt, r_cvt;
      JSNode *l, *r;

      if (JS_IS_NUMBER (JS_SP2))
	l = JS_SP2;
      else
	{
	  js_vm_to_number (vm, JS_SP2, &l_cvt);
	  l = &l_cvt;
	}

      if (JS_IS_NUMBER (JS_SP1))
	r = JS_SP1;
      else
	{
	  js_vm_to_number (vm, JS_SP1, &r_cvt);
	  r = &r_cvt;
	}

      if (l->type == JS_NAN || r->type == JS_NAN)
	JS_SP2->type = JS_NAN;
      else if (l->type == JS_INTEGER)
	{
	  if (r->type == JS_INTEGER)
	    {
	      JS_SP2->type = JS_INTEGER;
	      JS_SP2->u.vinteger = l->u.vinteger - r->u.vinteger;
	    }
	  else
	    {
	      JS_SP2->type = JS_FLOAT;
	      JS_SP2->u.vfloat = (double) l->u.vinteger - r->u.vfloat;
	    }
	}
      else
	{
	  if (r->type == JS_INTEGER)
	    {
	      JS_SP2->type = JS_FLOAT;
	      JS_SP2->u.vfloat = l->u.vfloat - (double) r->u.vinteger;
	    }
	  else
	    {
	      JS_SP2->type = JS_FLOAT;
	      JS_SP2->u.vfloat = l->u.vfloat - r->u.vfloat;
	    }
	}
    }

  JS_POP ();
  break;

/* operand add (39) */
case 39:
  if (JS_SP2->type == JS_STRING || JS_SP1->type == JS_STRING)
    {
      unsigned char *d2, *d1, *ndata;
      unsigned int d2_len, d1_len, nlen;
      JSNode cvt;

      if (JS_SP2->type == JS_STRING)
	{
	  d2 = JS_SP2->u.vstring->data;
	  d2_len = JS_SP2->u.vstring->len;
	}
      else
	{
	  js_vm_to_string (vm, JS_SP2, &cvt);
	  d2 = cvt.u.vstring->data;
	  d2_len = cvt.u.vstring->len;
	}
      if (JS_SP1->type == JS_STRING)
	{
	  d1 = JS_SP1->u.vstring->data;
	  d1_len = JS_SP1->u.vstring->len;
	}
      else
	{
	  js_vm_to_string (vm, JS_SP1, &cvt);
	  d1 = cvt.u.vstring->data;
	  d1_len = cvt.u.vstring->len;
	}

      nlen = d2_len + d1_len;
      ndata = js_vm_alloc (vm, nlen);
      memcpy (ndata, d2, d2_len);
      memcpy (ndata + d2_len, d1, d1_len);

      js_vm_make_static_string (vm, JS_SP2, (char*)ndata, nlen);
      JS_SP2->u.vstring->staticp = 0;
      JS_POP ();
      JS_MAYBE_GC ();
    }
  else if (JS_SP2->type == JS_INTEGER && JS_SP1->type == JS_INTEGER)
    {
      JS_SP2->u.vinteger += JS_SP1->u.vinteger;
      JS_POP ();
    }
  else
    {
      JSNode l_cvt, r_cvt;
      JSNode *l, *r;

      if (JS_IS_NUMBER (JS_SP2))
	l = JS_SP2;
      else
	{
	  js_vm_to_number (vm, JS_SP2, &l_cvt);
	  l = &l_cvt;
	}

      if (JS_IS_NUMBER (JS_SP1))
	r = JS_SP1;
      else
	{
	  js_vm_to_number (vm, JS_SP1, &r_cvt);
	  r = &r_cvt;
	}

      if (l->type == JS_NAN || r->type == JS_NAN)
	JS_SP2->type = JS_NAN;
      else if (l->type == JS_INTEGER)
	{
	  if (r->type == JS_INTEGER)
	    {
	      JS_SP2->type = JS_INTEGER;
	      JS_SP2->u.vinteger = l->u.vinteger + r->u.vinteger;
	    }
	  else
	    {
	      JS_SP2->type = JS_FLOAT;
	      JS_SP2->u.vfloat = (double) l->u.vinteger + r->u.vfloat;
	    }
	}
      else
	{
	  if (r->type == JS_INTEGER)
	    {
	      JS_SP2->type = JS_FLOAT;
	      JS_SP2->u.vfloat = l->u.vfloat + (double) r->u.vinteger;
	    }
	  else
	    {
	      JS_SP2->type = JS_FLOAT;
	      JS_SP2->u.vfloat = l->u.vfloat + r->u.vfloat;
	    }
	}

      JS_POP ();
    }
  break;

/* operand mul (40) */
case 40:
  if (JS_SP2->type == JS_INTEGER && JS_SP1->type == JS_INTEGER)
    {
      JS_SP2->u.vinteger *= JS_SP1->u.vinteger;
    }
  else
    {
      JSNode l_cvt, r_cvt;
      JSNode *l, *r;

      if (JS_IS_NUMBER (JS_SP2))
	l = JS_SP2;
      else
	{
	  js_vm_to_number (vm, JS_SP2, &l_cvt);
	  l = &l_cvt;
	}

      if (JS_IS_NUMBER (JS_SP1))
	r = JS_SP1;
      else
	{
	  js_vm_to_number (vm, JS_SP1, &r_cvt);
	  r = &r_cvt;
	}

      if (l->type == JS_NAN || r->type == JS_NAN)
	JS_SP2->type = JS_NAN;
      else if (l->type == JS_INTEGER)
	{
	  if (r->type == JS_INTEGER)
	    {
	      JS_SP2->type = JS_INTEGER;
	      JS_SP2->u.vinteger = l->u.vinteger * r->u.vinteger;
	    }
	  else
	    {
	      if (l->u.vinteger == 0
		  && (JS_IS_POSITIVE_INFINITY (r)
		      || JS_IS_NEGATIVE_INFINITY (r)))
		JS_SP2->type = JS_NAN;
	      else
		{
		  JS_SP2->type = JS_FLOAT;
		  JS_SP2->u.vfloat = (double) l->u.vinteger * r->u.vfloat;
		}
	    }
	}
      else
	{
	  if ((JS_IS_POSITIVE_INFINITY (l) || JS_IS_NEGATIVE_INFINITY (l))
	      && ((r->type == JS_INTEGER && r->u.vinteger == 0)
		  || (r->type == JS_FLOAT && r->u.vfloat == 0.0)))
	    JS_SP2->type = JS_NAN;

⌨️ 快捷键说明

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