home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / js / src / jsinterp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  5.9 KB  |  141 lines

  1. /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifndef jsinterp_h___
  20. #define jsinterp_h___
  21. /*
  22.  * JS interpreter interface.
  23.  */
  24. #include "jsprvtd.h"
  25. #include "jspubtd.h"
  26.  
  27. /*
  28.  * JS stack frame, allocated on the C stack.
  29.  */
  30. struct JSStackFrame {
  31.     JSObject        *object;        /* object for fun.arguments/fun.caller */
  32.     JSScript        *script;        /* script being interpreted */
  33.     JSFunction      *fun;           /* function being called or null */
  34.     JSObject        *thisp;         /* "this" pointer if in method */
  35.     uintN           argc;           /* actual argument count */
  36.     jsval           *argv;          /* base of argument stack slots */
  37.     jsval           rval;           /* function return value */
  38.     uintN           nvars;          /* local variable count */
  39.     jsval           *vars;          /* base of variable stack slots */
  40.     JSStackFrame    *down;          /* previous frame */
  41.     void            *annotation;    /* used by Java security */
  42.     JSObject        *scopeChain;    /* scope chain */
  43.     jsbytecode      *pc;            /* program counter */
  44.     jsval           *sp;            /* stack pointer */
  45.     uintN           sharpDepth;     /* array/object initializer depth */
  46.     JSObject        *sharpArray;    /* scope for #n= initializer vars */
  47. };
  48.  
  49. /*
  50.  * Property cache for quickened get/set property opcodes.
  51.  */
  52. #define PROPERTY_CACHE_LOG2     10
  53. #define PROPERTY_CACHE_SIZE     PR_BIT(PROPERTY_CACHE_LOG2)
  54. #define PROPERTY_CACHE_MASK     PR_BITMASK(PROPERTY_CACHE_LOG2)
  55.  
  56. #define PROPERTY_CACHE_HASH(obj, id) \
  57.     ((((pruword)(obj) >> JSVAL_TAGBITS) ^ (pruword)(id)) & PROPERTY_CACHE_MASK)
  58.  
  59. typedef struct JSPropertyCacheEntry {
  60.     JSProperty  *property;      /* weak link to property */
  61.     jsval       symbolid;       /* strong link to name atom, or index jsval */
  62. } JSPropertyCacheEntry;
  63.  
  64. typedef struct JSPropertyCache {
  65.     JSPropertyCacheEntry table[PROPERTY_CACHE_SIZE];
  66.     JSBool               empty;
  67.     uint32               fills;
  68.     uint32               recycles;
  69.     uint32               tests;
  70.     uint32               misses;
  71.     uint32               flushes;
  72.     uint32               pflushes;
  73. } JSPropertyCache;
  74.  
  75. #define PROP_NOT_FOUND   ((JSProperty *)1)
  76. #define PROP_FOUND(prop) ((prword)(prop) & (prword)-2)
  77.  
  78. #define PROPERTY_CACHE_FILL(cx, cache, obj, id, prop)                         \
  79.     PR_BEGIN_MACRO                                                            \
  80.     uintN _hashIndex = (uintN)PROPERTY_CACHE_HASH(obj, id);               \
  81.     JSPropertyCacheEntry *_pce = &(cache)->table[_hashIndex];             \
  82.     if (_pce->property && _pce->property != prop) {                       \
  83.         (cache)->recycles++;                                              \
  84.         if (!JSVAL_IS_INT(_pce->symbolid))                                \
  85.         js_DropAtom(cx, (JSAtom *)_pce->symbolid);                    \
  86.     }                                                                     \
  87.     _pce->property = prop;                                                \
  88.     _pce->symbolid = id;                                                  \
  89.     if (!JSVAL_IS_INT(id))                                                \
  90.         js_HoldAtom(cx, (JSAtom *)id);                                    \
  91.     (cache)->empty = JS_FALSE;                                            \
  92.     (cache)->fills++;                                                     \
  93.     PR_END_MACRO
  94.  
  95. #define PROPERTY_CACHE_TEST(cache, obj, id, prop)                             \
  96.     PR_BEGIN_MACRO                                                            \
  97.     uintN _hashIndex = (uintN)PROPERTY_CACHE_HASH(obj, id);               \
  98.     JSPropertyCacheEntry *_pce = &(cache)->table[_hashIndex];             \
  99.     (cache)->tests++;                                                     \
  100.     if (_pce->property &&                                                 \
  101.         (_pce->property == PROP_NOT_FOUND ||                              \
  102.          _pce->property->object == obj) &&                                \
  103.         _pce->symbolid == id) {                                           \
  104.         prop = _pce->property;                                            \
  105.     } else {                                                              \
  106.         (cache)->misses++;                                                \
  107.         prop = NULL;                                                      \
  108.     }                                                                     \
  109.     PR_END_MACRO
  110.  
  111. extern void
  112. js_FlushPropertyCache(JSContext *cx);
  113.  
  114. extern void
  115. js_FlushPropertyCacheByProp(JSContext *cx, JSProperty *prop);
  116.  
  117. extern JSBool
  118. js_GetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  119.  
  120. extern JSBool
  121. js_SetArgument(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  122.  
  123. extern JSBool
  124. js_GetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  125.  
  126. extern JSBool
  127. js_SetLocalVariable(JSContext *cx, JSObject *obj, jsval id, jsval *vp);
  128.  
  129. extern JSBool
  130. js_DoCall(JSContext *cx, uintN argc);
  131.  
  132. extern JSBool
  133. js_Call(JSContext *cx, JSObject *obj, jsval fval, uintN argc, jsval *argv,
  134.     jsval *rval);
  135.  
  136. extern JSBool
  137. js_Execute(JSContext *cx, JSObject *chain, JSScript *script, JSStackFrame *down,
  138.        jsval *result);
  139.  
  140. #endif /* jsinterp_h___ */
  141.