📄 operands.def
字号:
/* -*- c -*-
* Operand definitions for the JavaScript byte-code.
* Copyright (c) 1998 New Generation Software (NGS) Oy
*
* Author: Markku Rossi <mtr@ngs.fi>
*/
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
* MA 02111-1307, USA
*/
/*
* $Source: /cygdrive/c/RCVS/CVS/ReactOS/reactos/lib/kjs/src/operands.def,v $
* $Id: operands.def 21681 2006-04-21 15:00:24Z peterw $
*/
operand halt 0 {
sprintf (buf, "VM: halt%s", JS_HOST_LINE_BREAK);
js_iostream_write (vm->s_stderr, buf, strlen (buf));
js_iostream_flush (vm->s_stderr);
while (1)
sleep (5);
}
operand done 0 {
DONE ();
}
operand nop 0 {
/* Nothing here! */
}
operand dup 0 {
JS_COPY (JS_SP0, JS_SP1);
JS_PUSH ();
}
operand pop 0 {
JS_POP ();
}
operand pop_n 1 {
READ_INT8 (i);
JS_POP_N (i);
}
operand apop 1 {
READ_INT8 (i);
JS_COPY (JS_SP (i + 1), JS_SP1);
JS_POP_N (i);
}
operand swap 0 {
JS_COPY (JS_SP0, JS_SP2);
JS_COPY (JS_SP2, JS_SP1);
JS_COPY (JS_SP1, JS_SP0);
}
operand roll 1 {
READ_INT8 (i8);
if (i8 > 1)
{
int j;
for (j = 0; j < i8; j++)
JS_COPY (JS_SP (j), JS_SP (j + 1));
JS_COPY (JS_SP (i8), JS_SP0);
}
else if (i8 < -1)
{
i8 = -i8;
JS_COPY (JS_SP0, JS_SP (i8));
for (; i8 > 0; i8--)
JS_COPY (JS_SP (i8), JS_SP (i8 - 1));
}
}
operand const 4 {
READ_INT32 (i);
JS_COPY (JS_SP0, JS_CONST (i));
JS_PUSH ();
}
operand const_null 0 {
JS_SP0->type = JS_NULL;
JS_PUSH ();
}
operand const_true 0 {
JS_SP0->type = JS_BOOLEAN;
JS_SP0->u.vboolean = 1;
JS_PUSH ();
}
operand const_false 0 {
JS_SP0->type = JS_BOOLEAN;
JS_SP0->u.vboolean = 0;
JS_PUSH ();
}
operand const_undefined 0 {
JS_SP0->type = JS_UNDEFINED;
JS_PUSH ();
}
operand const_i0 0 {
JS_SP0->type = JS_INTEGER;
JS_SP0->u.vinteger = 0;
JS_PUSH ();
}
operand const_i1 0 {
JS_SP0->type = JS_INTEGER;
JS_SP0->u.vinteger = 1;
JS_PUSH ();
}
operand const_i2 0 {
JS_SP0->type = JS_INTEGER;
JS_SP0->u.vinteger = 2;
JS_PUSH ();
}
operand const_i3 0 {
JS_SP0->type = JS_INTEGER;
JS_SP0->u.vinteger = 3;
JS_PUSH ();
}
operand const_i 4 {
READ_INT32 (i);
JS_SP0->type = JS_INTEGER;
JS_SP0->u.vinteger = i;
JS_PUSH ();
}
operand load_global 4 { /* symbol */
READ_INT32 (j);
/* Use the global value only. */
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));
}
}
operand store_global 4 { /* symbol */
READ_INT32 (i);
/* Operand store_global do not check the with-chain. */
/* WITHCHAIN */
/* Set the global value. */
JS_COPY (JS_GLOBAL (i), JS_SP1);
JS_POP ();
}
operand load_arg 1 {
READ_INT8 (i);
JS_COPY (JS_SP0, JS_ARG (i));
JS_PUSH ();
}
operand store_arg 1 {
READ_INT8 (i);
JS_COPY (JS_ARG (i), JS_SP1);
JS_POP ();
}
operand load_local 2 {
READ_INT16 (i);
JS_COPY (JS_SP0, JS_LOCAL (i));
JS_PUSH ();
}
operand store_local 2 {
READ_INT16 (i);
JS_COPY (JS_LOCAL (i), JS_SP1);
JS_POP ();
}
operand load_property 4 { /* symbol */
/* Fetch the property symbol. */
READ_INT32 (j);
if (JS_SP1->type == JS_BUILTIN)
{
JS_SAVE_REGS ();
if (JS_SP1->u.vbuiltin->info->property_proc)
{
if ((*JS_SP1->u.vbuiltin->info->property_proc) (
vm,
JS_SP1->u.vbuiltin->info,
JS_SP1->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_SP1->u.vbuiltin->prototype)
/* This is an instance. */
builtin_result.u.vobject = JS_SP1->u.vbuiltin->prototype;
else
/* This is a class. */
builtin_result.u.vobject
= JS_SP1->u.vbuiltin->info->prototype;
}
else
{
/* Looking up stuffs from the prototype. */
if (JS_SP1->u.vbuiltin->prototype)
/* An instance. */
js_vm_object_load_property (vm,
JS_SP1->u.vbuiltin->prototype,
j, &builtin_result);
else
/* A class. */
js_vm_object_load_property (
vm,
JS_SP1->u.vbuiltin->info->prototype,
j, &builtin_result);
}
}
JS_COPY (JS_SP1, &builtin_result);
}
else
ERROR ("illegal builtin object for load_property");
}
else if (JS_SP1->type == JS_OBJECT)
{
js_vm_object_load_property (vm, JS_SP1->u.vobject, j, JS_SP1);
}
else if (vm->prim[JS_SP1->type])
{
/* The primitive language types. */
JS_SAVE_REGS ();
if ((*vm->prim[JS_SP1->type]->property_proc) (vm, vm->prim[JS_SP1->type],
JS_SP1, j, 0,
&builtin_result)
== JS_PROPERTY_UNKNOWN)
{
if (j == vm->syms.s_prototype)
{
/* Looking up the prototype. */
switch (JS_SP1->type)
{
case JS_STRING:
if (JS_SP1->u.vstring->prototype)
{
builtin_result.type = JS_OBJECT;
builtin_result.u.vobject = JS_SP1->u.vstring->prototype;
}
else
/* No prototype yet. */
builtin_result.type = JS_NULL;
break;
case JS_ARRAY:
if (JS_SP1->u.varray->prototype)
{
builtin_result.type = JS_OBJECT;
builtin_result.u.vobject = JS_SP1->u.varray->prototype;
}
else
/* No prototype yet. */
builtin_result.type = JS_NULL;
break;
case JS_FUNC:
if (JS_SP1->u.vfunction->prototype)
{
builtin_result.type = JS_OBJECT;
builtin_result.u.vobject
= JS_SP1->u.vfunction->prototype;
}
else
/* No prototype yet. */
builtin_result.type = JS_NULL;
break;
default:
/* The rest do not have prototype. */
builtin_result.type = JS_NULL;
break;
}
}
else
{
/* Looking up stuffs from the prototype. */
switch (JS_SP1->type)
{
case JS_STRING:
if (JS_SP1->u.vstring->prototype)
js_vm_object_load_property (vm,
JS_SP1->u.vstring->prototype,
j, &builtin_result);
else
/* Take it from the class' prototype */
goto _op_load_property_try_proto;
break;
case JS_ARRAY:
if (JS_SP1->u.varray->prototype)
js_vm_object_load_property (vm,
JS_SP1->u.varray->prototype,
j, &builtin_result);
else
/* Take it from the class' prototype */
goto _op_load_property_try_proto;
break;
case JS_FUNC:
if (JS_SP1->u.vfunction->prototype)
js_vm_object_load_property (vm,
JS_SP1->u.vfunction->prototype,
j, &builtin_result);
else
/* Take it from the class' prototype */
goto _op_load_property_try_proto;
break;
default:
/*
* The rest do not have instance prototypes; use the
* class prototypes.
*/
_op_load_property_try_proto:
js_vm_object_load_property (
vm,
vm->prim[JS_SP1->type]->prototype, j,
&builtin_result);
break;
}
}
}
JS_COPY (JS_SP1, &builtin_result);
}
else
ERROR ("illegal object for load_property");
}
operand store_property 4 { /* symbol */
/* Fetch the property symbol. */
READ_INT32 (j);
if (JS_SP1->type == JS_BUILTIN)
{
JS_SAVE_REGS ();
if (JS_SP1->u.vbuiltin->info->property_proc)
{
if ((*JS_SP1->u.vbuiltin->info->property_proc) (
vm,
JS_SP1->u.vbuiltin->info,
JS_SP1->u.vbuiltin->instance_context,
j, 1, JS_SP2)
== JS_PROPERTY_UNKNOWN)
{
if (j == vm->syms.s_prototype)
{
/* Setting the prototype. */
if (JS_SP2->type != JS_OBJECT)
ERROR ("illegal value for set_property");
if (JS_SP1->u.vbuiltin->prototype)
/* Setting the instance's prototype. */
JS_SP1->u.vbuiltin->prototype = JS_SP2->u.vobject;
else
/* Setting the class' prototype. */
JS_SP1->u.vbuiltin->info->prototype = JS_SP2->u.vobject;
}
else
{
/* Setting stuff to the prototype. */
if (JS_SP1->u.vbuiltin->prototype)
/* An instance. */
js_vm_object_store_property (vm,
JS_SP1->u.vbuiltin->prototype,
j, JS_SP2);
else
/* A class. */
js_vm_object_store_property (
vm,
JS_SP1->u.vbuiltin->info->prototype,
j, JS_SP2);
}
}
}
else
ERROR ("illegal builtin object for store_property");
JS_POP ();
JS_POP ();
}
else if (JS_SP1->type == JS_OBJECT)
{
js_vm_object_store_property (vm, JS_SP1->u.vobject, j, JS_SP2);
JS_POP ();
JS_POP ();
}
else if (vm->prim[JS_SP1->type])
{
/* The primitive language types. */
JS_SAVE_REGS ();
if ((*vm->prim[JS_SP1->type]->property_proc) (vm, vm->prim[JS_SP1->type],
JS_SP1, j, 1, JS_SP2)
== JS_PROPERTY_UNKNOWN)
{
if (j == vm->syms.s_prototype)
{
/* Setting the prototype. */
if (JS_SP2->type != JS_OBJECT)
ERROR ("illegal value for set_property");
switch (JS_SP1->type)
{
case JS_STRING:
JS_SP1->u.vstring->prototype = JS_SP2->u.vobject;
break;
case JS_ARRAY:
JS_SP1->u.varray->prototype = JS_SP2->u.vobject;
break;
case JS_FUNC:
JS_SP1->u.vfunction->prototype = JS_SP2->u.vobject;
break;
default:
ERROR ("illegal object for set_property");
break;
}
}
else
{
JSNode prototype;
/* Setting to the prototype. We create them on demand. */
switch (JS_SP1->type)
{
case JS_STRING:
if (JS_SP1->u.vstring->prototype == NULL)
{
prototype.type = JS_OBJECT;
/* Create the prototype and set its __proto__. */
JS_SP1->u.vstring->prototype = js_vm_object_new (vm);
prototype.u.vobject = vm->prim[JS_OBJECT]->prototype;
js_vm_object_store_property (
vm,
JS_SP1->u.vstring->prototype,
vm->syms.s___proto__,
&prototype);
}
js_vm_object_store_property (vm,
JS_SP1->u.vstring->prototype,
j, JS_SP2);
break;
case JS_ARRAY:
if (JS_SP1->u.varray->prototype == NULL)
{
prototype.type = JS_OBJECT;
/* Create the prototype and set its __proto__. */
JS_SP1->u.varray->prototype = js_vm_object_new (vm);
prototype.u.vobject = vm->prim[JS_OBJECT]->prototype;
js_vm_object_store_property (
vm,
JS_SP1->u.varray->prototype,
vm->syms.s___proto__,
&prototype);
}
js_vm_object_store_property (vm,
JS_SP1->u.varray->prototype,
j, JS_SP2);
break;
case JS_FUNC:
if (JS_SP1->u.vfunction->prototype == NULL)
{
prototype.type = JS_OBJECT;
/* Create the prototype and set its __proto__. */
JS_SP1->u.vfunction->prototype = js_vm_object_new (vm);
prototype.u.vobject = vm->prim[JS_OBJECT]->prototype;
js_vm_object_store_property (
vm,
JS_SP1->u.vfunction->prototype,
vm->syms.s___proto__,
&prototype);
}
js_vm_object_store_property (vm,
JS_SP1->u.vfunction->prototype,
j, JS_SP2);
break;
default:
ERROR ("illegal object for set_property");
break;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -