📄 jim.h
字号:
/* Jim - A small embeddable Tcl interpreter
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
*
* $Id: jim.h,v 1.76 2006/11/06 20:29:15 antirez Exp $
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* A copy of the license is also included in the source distribution
* of Jim, as a TXT file name called LICENSE.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef __JIM__H
#define __JIM__H
#ifdef __cplusplus
extern "C" {
#endif
#include <time.h>
#include <limits.h>
#include <stdio.h> /* for the FILE typedef definition */
#include <stdlib.h> /* In order to export the Jim_Free() macro */
/* -----------------------------------------------------------------------------
* Some /very/ old compiler maybe do not know how to
* handle 'const'. They even do not know, how to ignore
* it. For those compiler it may be better to compile with
* define JIM_NO_CONST activated
* ---------------------------------------------------------------------------*/
#ifdef JIM_NO_CONST
# define const
#endif
/* -----------------------------------------------------------------------------
* System configuration
* For most modern systems, you can leave the default.
* For embedded systems some change may be required.
* ---------------------------------------------------------------------------*/
#define HAVE_LONG_LONG
/* -----------------------------------------------------------------------------
* Compiler specific fixes.
* ---------------------------------------------------------------------------*/
/* MSC has _stricmp instead of strcasecmp */
#ifdef _MSC_VER
# define strcasecmp _stricmp
#endif /* _MSC_VER */
/* Long Long type and related issues */
#ifdef HAVE_LONG_LONG
# ifdef _MSC_VER /* MSC compiler */
# define jim_wide _int64
# ifndef LLONG_MAX
# define LLONG_MAX 9223372036854775807I64
# endif
# ifndef LLONG_MIN
# define LLONG_MIN (-LLONG_MAX - 1I64)
# endif
# define JIM_WIDE_MIN LLONG_MIN
# define JIM_WIDE_MAX LLONG_MAX
# else /* Other compilers (mainly GCC) */
# define jim_wide long long
# ifndef LLONG_MAX
# define LLONG_MAX 9223372036854775807LL
# endif
# ifndef LLONG_MIN
# define LLONG_MIN (-LLONG_MAX - 1LL)
# endif
# define JIM_WIDE_MIN LLONG_MIN
# define JIM_WIDE_MAX LLONG_MAX
# endif
#else
# define jim_wide long
# define JIM_WIDE_MIN LONG_MIN
# define JIM_WIDE_MAX LONG_MAX
#endif
/* -----------------------------------------------------------------------------
* LIBC specific fixes
* ---------------------------------------------------------------------------*/
#ifdef HAVE_LONG_LONG
# if defined(_MSC_VER) || defined(__MSVCRT__)
# define JIM_WIDE_MODIFIER "I64d"
# else
# define JIM_WIDE_MODIFIER "lld"
# endif
#else
# define JIM_WIDE_MODIFIER "ld"
#endif
/* -----------------------------------------------------------------------------
* Exported defines
* ---------------------------------------------------------------------------*/
/* Jim version numbering: every version of jim is marked with a
* successive integer number. This is version 0. The first
* stable version will be 1, then 2, 3, and so on. */
#define JIM_VERSION 51
#define JIM_OK 0
#define JIM_ERR 1
#define JIM_RETURN 2
#define JIM_BREAK 3
#define JIM_CONTINUE 4
#define JIM_EVAL 5
#define JIM_EXIT 6
#define JIM_MAX_NESTING_DEPTH 10000 /* default max nesting depth */
/* Some function get an integer argument with flags to change
* the behaviour. */
#define JIM_NONE 0 /* no flags set */
#define JIM_ERRMSG 1 /* set an error message in the interpreter. */
/* Flags for Jim_SubstObj() */
#define JIM_SUBST_NOVAR 1 /* don't perform variables substitutions */
#define JIM_SUBST_NOCMD 2 /* don't perform command substitutions */
#define JIM_SUBST_NOESC 4 /* don't perform escapes substitutions */
/* Unused arguments generate annoying warnings... */
#define JIM_NOTUSED(V) ((void) V)
/* Flags used by API calls getting a 'nocase' argument. */
#define JIM_CASESENS 0 /* case sensitive */
#define JIM_NOCASE 1 /* no case */
/* Filesystem related */
#define JIM_PATH_LEN 1024
/* Newline, some embedded system may need -DJIM_CRLF */
#ifdef JIM_CRLF
#define JIM_NL "\r\n"
#else
#define JIM_NL "\n"
#endif
/* -----------------------------------------------------------------------------
* Stack
* ---------------------------------------------------------------------------*/
typedef struct Jim_Stack {
int len;
int maxlen;
void **vector;
} Jim_Stack;
/* -----------------------------------------------------------------------------
* Hash table
* ---------------------------------------------------------------------------*/
typedef struct Jim_HashEntry {
const void *key;
void *val;
struct Jim_HashEntry *next;
} Jim_HashEntry;
typedef struct Jim_HashTableType {
unsigned int (*hashFunction)(const void *key);
const void *(*keyDup)(void *privdata, const void *key);
void *(*valDup)(void *privdata, const void *obj);
int (*keyCompare)(void *privdata, const void *key1, const void *key2);
void (*keyDestructor)(void *privdata, const void *key);
void (*valDestructor)(void *privdata, void *obj);
} Jim_HashTableType;
typedef struct Jim_HashTable {
Jim_HashEntry **table;
Jim_HashTableType *type;
unsigned int size;
unsigned int sizemask;
unsigned int used;
unsigned int collisions;
void *privdata;
} Jim_HashTable;
typedef struct Jim_HashTableIterator {
Jim_HashTable *ht;
int index;
Jim_HashEntry *entry, *nextEntry;
} Jim_HashTableIterator;
/* This is the initial size of every hash table */
#define JIM_HT_INITIAL_SIZE 16
/* ------------------------------- Macros ------------------------------------*/
#define Jim_FreeEntryVal(ht, entry) \
if ((ht)->type->valDestructor) \
(ht)->type->valDestructor((ht)->privdata, (entry)->val)
#define Jim_SetHashVal(ht, entry, _val_) do { \
if ((ht)->type->valDup) \
entry->val = (ht)->type->valDup((ht)->privdata, _val_); \
else \
entry->val = (_val_); \
} while(0)
#define Jim_FreeEntryKey(ht, entry) \
if ((ht)->type->keyDestructor) \
(ht)->type->keyDestructor((ht)->privdata, (entry)->key)
#define Jim_SetHashKey(ht, entry, _key_) do { \
if ((ht)->type->keyDup) \
entry->key = (ht)->type->keyDup((ht)->privdata, _key_); \
else \
entry->key = (_key_); \
} while(0)
#define Jim_CompareHashKeys(ht, key1, key2) \
(((ht)->type->keyCompare) ? \
(ht)->type->keyCompare((ht)->privdata, key1, key2) : \
(key1) == (key2))
#define Jim_HashKey(ht, key) (ht)->type->hashFunction(key)
#define Jim_GetHashEntryKey(he) ((he)->key)
#define Jim_GetHashEntryVal(he) ((he)->val)
#define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
#define Jim_GetHashTableSize(ht) ((ht)->size)
#define Jim_GetHashTableUsed(ht) ((ht)->used)
/* -----------------------------------------------------------------------------
* Jim_Obj structure
* ---------------------------------------------------------------------------*/
/* -----------------------------------------------------------------------------
* Jim object. This is mostly the same as Tcl_Obj itself,
* with the addition of the 'prev' and 'next' pointers.
* In Jim all the objects are stored into a linked list for GC purposes,
* so that it's possible to access every object living in a given interpreter
* sequentially. When an object is freed, it's moved into a different
* linked list, used as object pool.
*
* The refcount of a freed object is always -1.
* ---------------------------------------------------------------------------*/
typedef struct Jim_Obj {
int refCount; /* reference count */
char *bytes; /* string representation buffer. NULL = no string repr. */
int length; /* number of bytes in 'bytes', not including the numterm. */
struct Jim_ObjType *typePtr; /* object type. */
/* Internal representation union */
union {
/* integer number type */
jim_wide wideValue;
/* hashed object type value */
int hashValue;
/* index type */
int indexValue;
/* return code type */
int returnCode;
/* double number type */
double doubleValue;
/* Generic pointer */
void *ptr;
/* Generic two pointers value */
struct {
void *ptr1;
void *ptr2;
} twoPtrValue;
/* Variable object */
struct {
unsigned jim_wide callFrameId;
struct Jim_Var *varPtr;
} varValue;
/* Command object */
struct {
unsigned jim_wide procEpoch;
struct Jim_Cmd *cmdPtr;
} cmdValue;
/* List object */
struct {
struct Jim_Obj **ele; /* Elements vector */
int len; /* Length */
int maxLen; /* Allocated 'ele' length */
} listValue;
/* String type */
struct {
int maxLength;
} strValue;
/* Reference type */
struct {
jim_wide id;
struct Jim_Reference *refPtr;
} refValue;
/* Source type */
struct {
const char *fileName;
int lineNumber;
} sourceValue;
/* Dict substitution type */
struct {
struct Jim_Obj *varNameObjPtr;
struct Jim_Obj *indexObjPtr;
} dictSubstValue;
/* tagged binary type */
struct {
unsigned char *data;
size_t len;
} binaryValue;
} internalRep;
/* This are 8 or 16 bytes more for every object
* but this is required for efficient garbage collection
* of Jim references. */
struct Jim_Obj *prevObjPtr; /* pointer to the prev object. */
struct Jim_Obj *nextObjPtr; /* pointer to the next object. */
} Jim_Obj;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -