📄 eswt0.h
字号:
break;
case JS_FUNC:
typeof_name = "function";
break;
case JS_IPTR:
typeof_name = "#iptr";
break;
case JS_ARGS_FIX:
typeof_name = "#argsfix";
break;
}
js_vm_make_static_string (vm, JS_SP1, typeof_name, strlen (typeof_name));
JS_MAYBE_GC ();
}
break;
/* operand new (58) */
case 58:
/* Check object. */
if (JS_SP1->type == JS_BUILTIN && JS_SP1->u.vbuiltin->info->new_proc)
{
JS_SAVE_REGS ();
(*JS_SP1->u.vbuiltin->info->new_proc) (vm, JS_SP1->u.vbuiltin->info,
JS_SP2, JS_SP1);
/* Push a dummy return value for the constructor. This is ignored. */
JS_SP0->type = JS_UNDEFINED;
JS_PUSH ();
}
else if (JS_SP1->type == JS_FUNC)
{
JSObject *obj;
JSNode f;
JSNode prototype;
/* The prototype is an object. */
prototype.type = JS_OBJECT;
/* Create the prototype for the function, if it is not defined. */
if (JS_SP1->u.vfunction->prototype == NULL)
{
JS_SP1->u.vfunction->prototype = js_vm_object_new (vm);
/* Set its __proto__ to point to Object's prototype. */
prototype.u.vobject = vm->prim[JS_OBJECT]->prototype;
js_vm_object_store_property (vm, JS_SP1->u.vfunction->prototype,
vm->syms.s___proto__, &prototype);
}
/* Allocate a new object and set its prototype. */
obj = js_vm_object_new (vm);
prototype.u.vobject = JS_SP1->u.vfunction->prototype;
js_vm_object_store_property (vm, obj, vm->syms.s___proto__, &prototype);
/*
* Basicly we do a jsr to the function given in JS_SP1. But first,
* we must set `this' pointer to the correct value. See `jsr' for
* the details.
*/
JS_COPY (&f, JS_SP1);
/* Replace func with the new object. */
JS_SP1->type = JS_OBJECT;
JS_SP1->u.vobject = obj;
JS_SUBROUTINE_CALL (f.u.vfunction->implementation);
}
/* The primitive language types. */
else if (vm->prim[JS_SP1->type])
{
JS_SAVE_REGS ();
(*vm->prim[JS_SP1->type]->new_proc) (vm, vm->prim[JS_SP1->type], JS_SP2,
JS_SP1);
JS_PUSH ();
}
else
ERROR ("illegal object for new");
JS_MAYBE_GC ();
break;
/* operand delete_property (59) */
case 59:
/* Fetch the property symbol. */
READ_INT32 (j);
if (JS_SP1->type == JS_BUILTIN)
{
/*
* XXX It should be possible to apply delete operand to builtin
* XXX objects.
*/
ERROR ("delete_property: JS_BUILTIN: not implemented yet");
}
else if (JS_SP1->type == JS_OBJECT)
{
js_vm_object_delete_property (vm, JS_SP1->u.vobject, j);
}
else if (JS_SP1->type == JS_NULL)
{
/* Delete a property from an object in the with-chain. */
/* WITHCHAIN */
ERROR ("delete_property: not implemented yet for the with-chain objects");
}
/* The primitive language types. */
/*
* XXX Since we can't delete properties from builtins, we can't delete
* XXX them from the primitive language types.
*/
else
ERROR ("illegal object for delete_property");
/* The delete operand returns an undefined value. */
JS_SP1->type = JS_UNDEFINED;
break;
/* operand delete_array (60) */
case 60:
if (JS_SP2->type == JS_BUILTIN)
{
ERROR ("delete_array: JS_BUILTIN: not implemented yet");
}
else if (JS_SP2->type == JS_OBJECT)
{
js_vm_object_delete_array (vm, JS_SP2->u.vobject, JS_SP1);
JS_POP ();
}
else if (JS_SP2->type == JS_ARRAY)
{
if (JS_SP1->type == JS_INTEGER)
{
if (0 <= JS_SP1->u.vinteger
&& JS_SP1->u.vinteger < JS_SP2->u.varray->length)
JS_SP2->u.varray->data[JS_SP1->u.vinteger].type = JS_UNDEFINED;
JS_POP ();
}
else
ERROR ("illegal array index in delete_array");
}
else
ERROR ("illegal object for delete_array");
/* The delete operand returns an undefined value. */
JS_SP1->type = JS_UNDEFINED;
break;
/* operand locals (61) */
case 61:
READ_INT16 (i);
if (sp - i - JS_RESERVE_STACK_FOR_FUNCTION < vm->stack)
ERROR ("stack overflow");
for (; i > 0; i--)
{
JS_SP0->type = JS_UNDEFINED;
JS_PUSH ();
}
break;
/* operand min_args (62) */
case 62:
READ_INT8 (i);
if (JS_SP1->u.vinteger < i)
{
unsigned int delta = i - JS_SP1->u.vinteger;
unsigned int argc = JS_SP1->u.vinteger;
memmove (JS_SP1 - delta, JS_SP1, (fp - JS_SP0 + argc) * sizeof (JSNode));
sp -= delta;
fp -= delta;
/* Fill up the fix_args slot. */
JS_ARGS_FIXP->u.args_fix.argc = argc;
JS_ARGS_FIXP->u.args_fix.delta = delta;
for (; argc < i; argc++)
JS_ARG (argc)->type = JS_UNDEFINED;
}
JS_POP ();
break;
/* operand load_nth_arg (63) */
case 63:
{
int index = JS_SP1->u.vinteger;
JS_COPY (JS_SP1, JS_ARG (index));
}
break;
/* operand with_push (64) */
case 64:
if (JS_SP1->type != JS_OBJECT && JS_SP1->type != JS_BUILTIN)
ERROR ("illegal object for with_push");
/* WITHCHAIN */
if (JS_WITHPTR->u.iptr == NULL)
{
JSNode *np;
JSUIntAlign *ip = js_vm_alloc (vm,
sizeof (JSUIntAlign)
+ sizeof (JSNode));
*ip = 1;
np = (JSNode *) ((unsigned char *) ip + sizeof (JSUIntAlign));
JS_COPY (np, JS_SP1);
JS_WITHPTR->u.iptr = ip;
}
else
{
JSNode *np;
JSUIntAlign *ip = JS_WITHPTR->u.iptr;
JSUIntAlign ui = *ip;
ip = js_vm_realloc (vm, ip,
sizeof (JSUIntAlign)
+ ((ui + 1) * sizeof (JSNode)));
(*ip)++;
np = (JSNode *) ((unsigned char *) ip + sizeof (JSUIntAlign));
JS_COPY (&np[ui], JS_SP1);
JS_WITHPTR->u.iptr = ip;
}
JS_POP ();
break;
/* operand with_pop (65) */
case 65:
READ_INT8 (i);
/* WITHCHAIN */
{
JSUIntAlign *ip = JS_WITHPTR->u.iptr;
if (ip == NULL || *ip < i)
ERROR ("with stack underflow in with_pop");
*ip -= i;
}
break;
/* operand try_push (66) */
case 66:
READ_INT32 (i);
{
JSErrorHandlerFrame *frame = js_calloc (vm, 1, sizeof (*frame));
frame->next = vm->error_handler;
frame->sp = sp;
frame->fp = fp;
frame->pc = pc;
frame->pc_delta = i;
vm->error_handler = frame;
if (setjmp (vm->error_handler->error_jmp))
{
/* Ok, we caught an error. */
/* Restore our state. */
sp = vm->error_handler->sp;
fp = vm->error_handler->fp;
pc = vm->error_handler->pc;
i = vm->error_handler->pc_delta;
/* Push the thrown value to the stack. */
JS_COPY (JS_SP0, &vm->error_handler->thrown);
JS_PUSH ();
/* Remove this handler frame. */
frame = vm->error_handler;
vm->error_handler = vm->error_handler->next;
js_free (frame);
/* Do the jump to the catch block. */
SETPC_RELATIVE (i);
}
}
break;
/* operand try_pop (67) */
case 67:
READ_INT8 (i);
for (; i > 0; i--)
{
JSErrorHandlerFrame *frame = vm->error_handler;
vm->error_handler = vm->error_handler->next;
js_free (frame);
}
break;
/* operand throw (68) */
case 68:
{
JSErrorHandlerFrame *f = vm->error_handler;
if (f->sp == NULL)
{
JSNode cvt;
int len;
/*
* We are jumping to the C-toplevel. Convert our thrown value
* to string and store it to the vm->error.
*/
js_vm_to_string (vm, JS_SP1, &cvt);
len = cvt.u.vstring->len;
if (len + 1 > sizeof (vm->error))
len = sizeof (vm->error) - 1;
memcpy (vm->error, cvt.u.vstring->data, len);
vm->error[len] = '\0';
}
else
JS_COPY (&f->thrown, JS_SP1);
longjmp (f->error_jmp, 1);
/* NOTREACHED (I hope). */
sprintf (buf, "VM: no valid error handler initialized%s",
JS_HOST_LINE_BREAK);
DbgPrint("%s\n", buf);
#if 0
js_iostream_write (vm->s_stderr, buf, strlen (buf));
js_iostream_flush (vm->s_stderr);
#endif
abort ();
}
break;
/* operand iffalse_b (69) */
case 69:
READ_INT32 (i);
if (!JS_SP1->u.vboolean)
SETPC_RELATIVE (i);
JS_POP ();
break;
/* operand iftrue_b (70) */
case 70:
READ_INT32 (i);
if (JS_SP1->u.vboolean)
SETPC_RELATIVE (i);
JS_POP ();
break;
/* operand add_1_i (71) */
case 71:
JS_SP1->u.vinteger++;
break;
/* operand add_2_i (72) */
case 72:
JS_SP1->u.vinteger += 2;
break;
/* operand load_global_w (73) */
case 73:
READ_INT32 (j);
{
int found = 0;
/* Loop over the with chain. */
/* WITHCHAIN */
if (JS_WITHPTR->u.iptr)
{
JSUIntAlign *uip = JS_WITHPTR->u.iptr;
JSUIntAlign ui = *uip;
JSNode *wp = (JSNode *) ((unsigned char *) uip
+ sizeof (JSUIntAlign));
for (i = 0; i < ui; i++)
{
JSNode *w = &wp[i];
int result = JS_PROPERTY_UNKNOWN;
if (w->type == JS_BUILTIN)
{
JS_SAVE_REGS ();
if (w->u.vbuiltin->info->property_proc)
result = (*w->u.vbuiltin->info->property_proc) (
vm,
w->u.vbuiltin->info,
w->u.vbuiltin->instance_context,
j, 0, &builtin_result);
}
else if (w->type == JS_OBJECT)
{
result = js_vm_object_load_property (vm, w->u.vobject, j,
&builtin_result);
}
else
ERROR ("corrupted with-chain in load_global");
if (result == JS_PROPERTY_FOUND)
{
JS_COPY (JS_SP0, &builtin_result);
JS_PUSH ();
found = 1;
break;
}
}
}
if (!found)
{
/* Use the global value. */
JS_COPY (JS_SP0, JS_GLOBAL (j));
JS_PUSH ();
if (vm->warn_undef && JS_SP1->type == JS_UNDEFINED)
{
sprintf (buf, "VM: warning: using undefined global `%s'%s",
js_vm_symname (vm, j), JS_HOST_LINE_BREAK);
js_iostream_write (vm->s_stderr, buf, strlen (buf));
}
}
}
break;
/* operand jsr_w (74) */
case 74:
/* Read the subroutine symbol index. */
READ_INT32 (j);
{
int found = 0;
/* Loop over the with-chain. */
/* WITHCHAIN */
if (JS_WITHPTR->u.iptr)
{
JSUIntAlign *uip = JS_WITHPTR->u.iptr;
JSUIntAlign ui = *uip;
JSNode *wp = (JSNode *) ((unsigned char *) uip
+ sizeof (JSUIntAlign));
for (i = 0; i < ui; i++)
{
JSNode *w = &wp[i];
int result = JS_PROPERTY_UNKNOWN;
if (w->type == JS_BUILTIN)
{
JS_SAVE_REGS ();
if (w->u.vbuiltin->info->method_proc)
result = (*w->u.vbuiltin->info->method_proc) (
vm,
w->u.vbuiltin->info,
w->u.vbuiltin->instance_context, j,
&builtin_result, JS_SP2);
JS_MAYBE_GC ();
if (result == JS_PROPERTY_FOUND)
{
JS_COPY (JS_SP0, &builtin_result);
JS_PUSH ();
}
}
else if (w->type == JS_OBJECT)
{
JSNode method;
js_vm_object_load_property (vm, w->u.vobject, j, &method);
if (method.type == JS_FUNC)
{
result = JS_PROPERTY_FOUND;
/* The object defines the method. Do a subroutine call. */
/* First: replace the null `this' with `w'. */
JS_COPY (JS_SP1, w);
/* Then, do the normal subroutine call. */
JS_SUBROUTINE_CALL (method.u.vfunction->implementation);
}
}
else
ERROR ("corrupted with-chain in jsr_w");
if (result == JS_PROPERTY_FOUND)
{
found = 1;
break;
}
}
}
if (!found)
{
JSNode f;
/* Call the global method. */
JS_COPY (&f, JS_SP1);
function = &f;
/* Reset the `this' to null. */
JS_SP1->type = JS_NULL;
if (function->type == JS_BUILTIN
&& function->u.vbuiltin->info->global_method_proc)
{
JS_SAVE_REGS ();
(*function->u.vbuiltin->info->global_method_proc) (
vm,
function->u.vbuiltin->info,
function->u.vbuiltin->instance_context,
&builtin_result,
JS_SP2);
JS_COPY (JS_SP0, &builtin_result);
JS_PUSH ();
}
else if (function->type == JS_FUNC)
{
JS_SUBROUTINE_CALL (function->u.vfunction->implementation);
}
else
{
sprintf (buf, "symbol `%s' is undefined as function",
js_vm_symname (vm, j));
ERROR (buf);
}
}
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -