📄 ejsvar.h
字号:
/* * ejsVar.h -- EJS Universal Variable Type *//* * @copy default * * Copyright (c) Mbedthis Software LLC, 2003-2006. All Rights Reserved. * Copyright (c) Michael O'Brien, 1994-1995. All Rights Reserved. * * This software is distributed under commercial and open source licenses. * You may use the GPL open source license described below or you may acquire * a commercial license from Mbedthis Software. You agree to be fully bound * by the terms of either license. Consult the LICENSE.TXT distributed with * this software for full details. * * This software is open source; you can redistribute it and/or modify it * under the terms of the GNU General Public License as published by the * Free Software Foundation; either version 2 of the License, or (at your * option) any later version. See the GNU General Public License for more * details at: http://www.mbedthis.com/downloads/gplLicense.html * * This program is distributed WITHOUT ANY WARRANTY; without even the * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * This GPL license does NOT permit incorporating this software into * proprietary programs. If you are unable to comply with the GPL, you must * acquire a commercial license to use this software. Commercial licenses * for this software and support services are available from Mbedthis * Software at http://www.mbedthis.com * * @end *//* * Variables can efficiently store primitive types and can hold references to * objects. Objects can store properties which are themselves variables. * Properties can be primitive data types, other objects or methods. * Properties are indexed by a character name. A variable may store one of * the following types: * * string, integer, integer-64bit, C method, C method with string args, * Javascript method, Floating point number, boolean value, Undefined * value and the Null value. * * Variables have names while objects may be referenced by multiple variables. * Objects use reference counting for garbage collection. * * This module is not thread safe for performance and compactness. It relies * on upper modules to provide thread synchronization as required. The API * provides primitives to get variable/object references or to get copies of * variables which will help minimize required lock times. */#ifndef _h_EJS_VAR#define _h_EJS_VAR 1/********************************* Includes ***********************************/#include "mpr.h"/********************************** Defines ***********************************/#ifdef __cplusplusextern "C" {#endif/* * Defined in ejs.h */typedef struct Ejs Ejs;/* * Constants */#if BLD_FEATURE_SQUEEZE /** * Maximum property or variable name size */ #define EJS_MAX_ID 64 /* * EJS_VAR_HASH_SIZE must be less than the size of the bit field * propertyIndex in EjsProperty. */ #define EJS_OBJ_HASH_SIZE 13 /** * Maximum number of arguments per function call */ #define EJS_MAX_ARGS 32 #define EJS_INC_ARGS 8 /* Frame stack increment */#else #define EJS_MAX_ID 256 #define EJS_OBJ_HASH_SIZE 29 #define EJS_MAX_ARGS 64 #define EJS_INC_ARGS 8#endif#define EJS_VAR_MAX_RECURSE 5 /* Max object loops */#if !DOXYGEN/* * Forward declare types */struct Ejs;struct EjsObj;struct EjsProperty;struct EjsVar;#endif/** * @overview EJ primitive variable type * @description EJ primitive variable values are stored in EjsVar structures. * The type of the primitive data is described by an EjsType field. * EjsVar variable types. * @stability Prototype. * @library libejs. * @see EJS_TYPE_UNDEFINED, EJS_TYPE_NULL, EJS_TYPE_BOOL, EJS_TYPE_CMETHOD, * EJS_TYPE_FLOAT, EJS_TYPE_INT, EJS_TYPE_INT64, EJS_TYPE_OBJECT, * EJS_TYPE_METHOD, EJS_TYPE_STRING, EJS_TYPE_STRING_CMETHOD, EJS_TYPE_PTR, */typedef uint EjsType;#define EJS_TYPE_UNDEFINED 0 /**< Undefined. No value has been set */#define EJS_TYPE_NULL 1 /**< Value defined to be null. */#define EJS_TYPE_BOOL 2 /**< Boolean type. */#define EJS_TYPE_CMETHOD 3 /**< C method */#define EJS_TYPE_FLOAT 4 /**< Floating point number */#define EJS_TYPE_INT 5 /**< Integer number */#define EJS_TYPE_INT64 6 /**< 64-bit Integer number */#define EJS_TYPE_OBJECT 7 /**< Object reference */#define EJS_TYPE_METHOD 8 /**< JavaScript method */#define EJS_TYPE_STRING 9 /**< String (immutable) */#define EJS_TYPE_STRING_CMETHOD 10 /**< C method with string args */#define EJS_TYPE_PTR 11 /**< Opaque pointer *//* * Create a type for the default number type * Config.h will define the default number type. For example: * * BLD_FEATURE_NUM_TYPE=int * BLD_FEATURE_NUM_TYPE_ID=EJS_TYPE_INT *//** * Set to the type used for EJS numeric variables. Will equate to int, int64 * or double. */typedef BLD_FEATURE_NUM_TYPE EjsNum;/** * Set to the EJS_TYPE used for EJS numeric variables. Will equate to * EJS_TYPE_INT, EJS_TYPE_INT64 or EJS_TYPE_FLOAT. */#define EJS_NUM_VAR BLD_FEATURE_NUM_TYPE_ID#define EJS_TYPE_NUM BLD_FEATURE_NUM_TYPE_ID/* * Return TRUE if a variable is a method type */#define ejsVarIsMethod(vp) \ ((vp)->type == EJS_TYPE_METHOD || (vp)->type == EJS_TYPE_STRING_CMETHOD || \ (vp)->type == EJS_TYPE_CMETHOD)/* * Return TRUE if a variable is a numeric type */#define ejsVarIsNumber(vp) \ ((vp)->type == EJS_TYPE_INT || (vp)->type == EJS_TYPE_INT64 || \ (vp)->type == EJS_TYPE_FLOAT)/* * Return TRUE if a variable is a boolean */#define ejsVarIsBoolean(vp) \ ((vp)->type == EJS_TYPE_BOOL)/* * Return TRUE if a variable is an integer type */#define ejsVarIsInteger(vp) ((vp)->type == EJS_TYPE_INT)/* * Return TRUE if a variable is a string */#define ejsVarIsString(vp) \ ((vp)->type == EJS_TYPE_STRING)/* * Return TRUE if a variable is an object */#define ejsVarIsObject(vp) \ ((vp)->type == EJS_TYPE_OBJECT)/* * Return TRUE if a variable is a floating number */#define ejsVarIsFloating(vp) \ ((vp)->type == EJS_TYPE_FLOAT)/* * Return TRUE if a variable is undefined */#define ejsVarIsUndefined(var) \ ((var)->type == EJS_TYPE_UNDEFINED)/* * Return TRUE if a variable is null */#define ejsVarIsNull(var) \ ((var)->type == EJS_TYPE_NULL)/* * Return TRUE if a variable is a valid type (not null or undefined) */#define ejsVarIsValid(var) \ (((var)->type != EJS_TYPE_NULL) && ((var)->type != EJS_TYPE_UNDEFINED))/* * Return TRUE if a variable is a ptr type */#define ejsVarIsPtr(vp) \ ((vp)->type == EJS_TYPE_PTR)/* MOB -- convert all ep to ejs *//** * @overview C Method signature * @description This is the calling signature for C Methods. * @param ejs Ejs reference returned from ejsCreateInterp * @param thisObj Reference to the "this" object. (The object containing the * method). * @param argc Number of arguments. * @param argv Array of arguments. Each argument is held in an EjsVar type. * @stability Prototype. * @library libejs. * @see ejsCreateCMethodVar */typedef int (*EjsCMethod)(struct Ejs *ejs, struct EjsVar *thisObj, int argc, struct EjsVar **argv);/** * C Method with string arguments signature * @overview C Method with string arguments signature * @description This is the calling signature for C Methods. * @param ejs Ejs reference returned from ejsCreateInterp * @param thisObj Reference to the "this" object (object containing the * method. * @param argc Number of arguments. * @param argv Array of arguments. Each argument is held in an C string * pointer. * @stability Prototype. * @library libejs. * @see ejsCreateStringCMethodVar */typedef int (*EjsStringCMethod)(struct Ejs *ep, struct EjsVar *thisObj, int argc, char **argv);/** * Flags for types: EJS_TYPE_CMETHOD, EJS_TYPE_STRING_CMETHOD * NOTE: flags == 0 means to use the EJS handle on method callbacks *//* Use the primary handle on method callbacks */#define EJS_PRIMARY_HANDLE 0x1/* Use the alternate handle on method callbacks */#define EJS_ALT_HANDLE 0x2/** Method should not create a new local variable block */#define EJS_NO_LOCAL 0x4/* Method is a get accessor */#define EJS_GET_ACCESSOR 0x8/* Method is a set accessor */#define EJS_SET_ACCESSOR 0x10/* * Flags for E4X (Xml type) *//* Node is a text node */#define EJS_XML_FLAGS_TEXT 0x1/* Node is a processing instruction */#define EJS_XML_FLAGS_PI 0x2/* Node is a comment */#define EJS_XML_FLAGS_COMMENT 0x4/* Node is an attribute */#define EJS_XML_FLAGS_ATTRIBUTE 0x8/* Node is an element */#define EJS_XML_FLAGS_ELEMENT 0x10/** * Copy depth * @overview Specifies how an object should be copied * @description The EjsCopyDepth type specifies how an object's properties * should be copied. Several routines take EjsCopyDepth parameters to * control how the properties of an object should be copied. It provides * three copy options: * @see ejsWriteVar */typedef enum EjsCopyDepth { /** * During an object copy, object property references will be copied so * that the original object and the copy will share the same reference to * a property object. Properties containing primitive types including * strings will have their values copied and will not share references. */ EJS_SHALLOW_COPY, /** Copy strings. Copy object references. */ /* * During an object copy, object properties will be replicated so that * the original object and the copy will not share references to the same * object properties. If the original object's properties are themselves * objects, their properties will not be copied. Only their references * will be copied. i.e. the deep copy is one level deep. */ EJS_DEEP_COPY, /** Copy strings and copy object contents. */ /* * During an object copy, all object properties will be replicated so that * the original object and the copy will not share references to the same * object properties. If the original object's properties are themselves * objects, their properties will be copied. i.e. the copy is of infinite * depth. */ EJS_RECURSIVE_DEEP_COPY /** Copy strings and copy object contents recursively (complete copy). */} EjsCopyDepth;/* * Enumeration flags *//** Enumerate data properties */#define EJS_ENUM_DATA 0x0/** Enumerate sub classes */#define EJS_ENUM_CLASSES 0x1/** Enumerate non-enumerable properties */#define EJS_ENUM_HIDDEN 0x2/** Enumerate all properties */#define EJS_ENUM_ALL (0x3)/** Magic number when allocated */#define EJS_MAGIC 0xe801e2ec#define EJS_MAGIC_FREE 0xe701e3ea/* * Garbage Collection Linkage. Free list only uses the next pointers. */typedef struct EjsGCLink {#if BLD_DEBUG uint magic; /* Magic number */#endif#if BLD_FEATURE_ALLOC_LEAK_TRACK const char *allocatedBy; /* Who allocated this */#endif struct EjsGCLink *next; /* Next property */} EjsGCLink;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -