1 |
786 |
skrzyp |
/* Jim - A small embeddable Tcl interpreter
|
2 |
|
|
* Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
|
3 |
|
|
* Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
|
4 |
|
|
*
|
5 |
|
|
* $Id: jim.h,v 1.76 2006/11/06 20:29:15 antirez Exp $
|
6 |
|
|
*
|
7 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
8 |
|
|
* you may not use this file except in compliance with the License.
|
9 |
|
|
* You may obtain a copy of the License at
|
10 |
|
|
*
|
11 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
12 |
|
|
*
|
13 |
|
|
* A copy of the license is also included in the source distribution
|
14 |
|
|
* of Jim, as a TXT file name called LICENSE.
|
15 |
|
|
*
|
16 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
17 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19 |
|
|
* See the License for the specific language governing permissions and
|
20 |
|
|
* limitations under the License.
|
21 |
|
|
*/
|
22 |
|
|
|
23 |
|
|
#ifndef __JIM__H
|
24 |
|
|
#define __JIM__H
|
25 |
|
|
|
26 |
|
|
#ifdef __cplusplus
|
27 |
|
|
extern "C" {
|
28 |
|
|
#endif
|
29 |
|
|
|
30 |
|
|
#include <time.h>
|
31 |
|
|
#include <limits.h>
|
32 |
|
|
#include <stdio.h> /* for the FILE typedef definition */
|
33 |
|
|
#include <stdlib.h> /* In order to export the Jim_Free() macro */
|
34 |
|
|
|
35 |
|
|
/* -----------------------------------------------------------------------------
|
36 |
|
|
* Some /very/ old compiler maybe do not know how to
|
37 |
|
|
* handle 'const'. They even do not know, how to ignore
|
38 |
|
|
* it. For those compiler it may be better to compile with
|
39 |
|
|
* define JIM_NO_CONST activated
|
40 |
|
|
* ---------------------------------------------------------------------------*/
|
41 |
|
|
|
42 |
|
|
#ifdef JIM_NO_CONST
|
43 |
|
|
# define const
|
44 |
|
|
#endif
|
45 |
|
|
|
46 |
|
|
/* -----------------------------------------------------------------------------
|
47 |
|
|
* System configuration
|
48 |
|
|
* For most modern systems, you can leave the default.
|
49 |
|
|
* For embedded systems some change may be required.
|
50 |
|
|
* ---------------------------------------------------------------------------*/
|
51 |
|
|
|
52 |
|
|
#define HAVE_LONG_LONG
|
53 |
|
|
|
54 |
|
|
/* -----------------------------------------------------------------------------
|
55 |
|
|
* Compiler specific fixes.
|
56 |
|
|
* ---------------------------------------------------------------------------*/
|
57 |
|
|
|
58 |
|
|
/* MSC has _stricmp instead of strcasecmp */
|
59 |
|
|
#ifdef _MSC_VER
|
60 |
|
|
# define strcasecmp _stricmp
|
61 |
|
|
#endif /* _MSC_VER */
|
62 |
|
|
|
63 |
|
|
/* Long Long type and related issues */
|
64 |
|
|
#ifdef HAVE_LONG_LONG
|
65 |
|
|
# ifdef _MSC_VER /* MSC compiler */
|
66 |
|
|
# define jim_wide _int64
|
67 |
|
|
# ifndef LLONG_MAX
|
68 |
|
|
# define LLONG_MAX 9223372036854775807I64
|
69 |
|
|
# endif
|
70 |
|
|
# ifndef LLONG_MIN
|
71 |
|
|
# define LLONG_MIN (-LLONG_MAX - 1I64)
|
72 |
|
|
# endif
|
73 |
|
|
# define JIM_WIDE_MIN LLONG_MIN
|
74 |
|
|
# define JIM_WIDE_MAX LLONG_MAX
|
75 |
|
|
# else /* Other compilers (mainly GCC) */
|
76 |
|
|
# define jim_wide long long
|
77 |
|
|
# ifndef LLONG_MAX
|
78 |
|
|
# define LLONG_MAX 9223372036854775807LL
|
79 |
|
|
# endif
|
80 |
|
|
# ifndef LLONG_MIN
|
81 |
|
|
# define LLONG_MIN (-LLONG_MAX - 1LL)
|
82 |
|
|
# endif
|
83 |
|
|
# define JIM_WIDE_MIN LLONG_MIN
|
84 |
|
|
# define JIM_WIDE_MAX LLONG_MAX
|
85 |
|
|
# endif
|
86 |
|
|
#else
|
87 |
|
|
# define jim_wide long
|
88 |
|
|
# define JIM_WIDE_MIN LONG_MIN
|
89 |
|
|
# define JIM_WIDE_MAX LONG_MAX
|
90 |
|
|
#endif
|
91 |
|
|
|
92 |
|
|
/* -----------------------------------------------------------------------------
|
93 |
|
|
* LIBC specific fixes
|
94 |
|
|
* ---------------------------------------------------------------------------*/
|
95 |
|
|
|
96 |
|
|
#ifdef HAVE_LONG_LONG
|
97 |
|
|
# if defined(_MSC_VER) || defined(__MSVCRT__)
|
98 |
|
|
# define JIM_WIDE_MODIFIER "I64d"
|
99 |
|
|
# else
|
100 |
|
|
# define JIM_WIDE_MODIFIER "lld"
|
101 |
|
|
# endif
|
102 |
|
|
#else
|
103 |
|
|
# define JIM_WIDE_MODIFIER "ld"
|
104 |
|
|
#endif
|
105 |
|
|
|
106 |
|
|
/* -----------------------------------------------------------------------------
|
107 |
|
|
* Exported defines
|
108 |
|
|
* ---------------------------------------------------------------------------*/
|
109 |
|
|
|
110 |
|
|
/* Jim version numbering: every version of jim is marked with a
|
111 |
|
|
* successive integer number. This is version 0. The first
|
112 |
|
|
* stable version will be 1, then 2, 3, and so on. */
|
113 |
|
|
#define JIM_VERSION 51
|
114 |
|
|
|
115 |
|
|
#define JIM_OK 0
|
116 |
|
|
#define JIM_ERR 1
|
117 |
|
|
#define JIM_RETURN 2
|
118 |
|
|
#define JIM_BREAK 3
|
119 |
|
|
#define JIM_CONTINUE 4
|
120 |
|
|
#define JIM_EVAL 5
|
121 |
|
|
#define JIM_EXIT 6
|
122 |
|
|
#define JIM_MAX_NESTING_DEPTH 10000 /* default max nesting depth */
|
123 |
|
|
|
124 |
|
|
/* Some function get an integer argument with flags to change
|
125 |
|
|
* the behaviour. */
|
126 |
|
|
#define JIM_NONE 0 /* no flags set */
|
127 |
|
|
#define JIM_ERRMSG 1 /* set an error message in the interpreter. */
|
128 |
|
|
|
129 |
|
|
/* Flags for Jim_SubstObj() */
|
130 |
|
|
#define JIM_SUBST_NOVAR 1 /* don't perform variables substitutions */
|
131 |
|
|
#define JIM_SUBST_NOCMD 2 /* don't perform command substitutions */
|
132 |
|
|
#define JIM_SUBST_NOESC 4 /* don't perform escapes substitutions */
|
133 |
|
|
|
134 |
|
|
/* Unused arguments generate annoying warnings... */
|
135 |
|
|
#define JIM_NOTUSED(V) ((void) V)
|
136 |
|
|
|
137 |
|
|
/* Flags used by API calls getting a 'nocase' argument. */
|
138 |
|
|
#define JIM_CASESENS 0 /* case sensitive */
|
139 |
|
|
#define JIM_NOCASE 1 /* no case */
|
140 |
|
|
|
141 |
|
|
/* Filesystem related */
|
142 |
|
|
#define JIM_PATH_LEN 1024
|
143 |
|
|
|
144 |
|
|
/* Newline, some embedded system may need -DJIM_CRLF */
|
145 |
|
|
#ifdef JIM_CRLF
|
146 |
|
|
#define JIM_NL "\r\n"
|
147 |
|
|
#else
|
148 |
|
|
#define JIM_NL "\n"
|
149 |
|
|
#endif
|
150 |
|
|
|
151 |
|
|
/* -----------------------------------------------------------------------------
|
152 |
|
|
* Stack
|
153 |
|
|
* ---------------------------------------------------------------------------*/
|
154 |
|
|
|
155 |
|
|
typedef struct Jim_Stack {
|
156 |
|
|
int len;
|
157 |
|
|
int maxlen;
|
158 |
|
|
void **vector;
|
159 |
|
|
} Jim_Stack;
|
160 |
|
|
|
161 |
|
|
/* -----------------------------------------------------------------------------
|
162 |
|
|
* Hash table
|
163 |
|
|
* ---------------------------------------------------------------------------*/
|
164 |
|
|
|
165 |
|
|
typedef struct Jim_HashEntry {
|
166 |
|
|
const void *key;
|
167 |
|
|
void *val;
|
168 |
|
|
struct Jim_HashEntry *next;
|
169 |
|
|
} Jim_HashEntry;
|
170 |
|
|
|
171 |
|
|
typedef struct Jim_HashTableType {
|
172 |
|
|
unsigned int (*hashFunction)(const void *key);
|
173 |
|
|
const void *(*keyDup)(void *privdata, const void *key);
|
174 |
|
|
void *(*valDup)(void *privdata, const void *obj);
|
175 |
|
|
int (*keyCompare)(void *privdata, const void *key1, const void *key2);
|
176 |
|
|
void (*keyDestructor)(void *privdata, const void *key);
|
177 |
|
|
void (*valDestructor)(void *privdata, void *obj);
|
178 |
|
|
} Jim_HashTableType;
|
179 |
|
|
|
180 |
|
|
typedef struct Jim_HashTable {
|
181 |
|
|
Jim_HashEntry **table;
|
182 |
|
|
Jim_HashTableType *type;
|
183 |
|
|
unsigned int size;
|
184 |
|
|
unsigned int sizemask;
|
185 |
|
|
unsigned int used;
|
186 |
|
|
unsigned int collisions;
|
187 |
|
|
void *privdata;
|
188 |
|
|
} Jim_HashTable;
|
189 |
|
|
|
190 |
|
|
typedef struct Jim_HashTableIterator {
|
191 |
|
|
Jim_HashTable *ht;
|
192 |
|
|
int index;
|
193 |
|
|
Jim_HashEntry *entry, *nextEntry;
|
194 |
|
|
} Jim_HashTableIterator;
|
195 |
|
|
|
196 |
|
|
/* This is the initial size of every hash table */
|
197 |
|
|
#define JIM_HT_INITIAL_SIZE 16
|
198 |
|
|
|
199 |
|
|
/* ------------------------------- Macros ------------------------------------*/
|
200 |
|
|
#define Jim_FreeEntryVal(ht, entry) \
|
201 |
|
|
if ((ht)->type->valDestructor) \
|
202 |
|
|
(ht)->type->valDestructor((ht)->privdata, (entry)->val)
|
203 |
|
|
|
204 |
|
|
#define Jim_SetHashVal(ht, entry, _val_) do { \
|
205 |
|
|
if ((ht)->type->valDup) \
|
206 |
|
|
entry->val = (ht)->type->valDup((ht)->privdata, _val_); \
|
207 |
|
|
else \
|
208 |
|
|
entry->val = (_val_); \
|
209 |
|
|
} while(0)
|
210 |
|
|
|
211 |
|
|
#define Jim_FreeEntryKey(ht, entry) \
|
212 |
|
|
if ((ht)->type->keyDestructor) \
|
213 |
|
|
(ht)->type->keyDestructor((ht)->privdata, (entry)->key)
|
214 |
|
|
|
215 |
|
|
#define Jim_SetHashKey(ht, entry, _key_) do { \
|
216 |
|
|
if ((ht)->type->keyDup) \
|
217 |
|
|
entry->key = (ht)->type->keyDup((ht)->privdata, _key_); \
|
218 |
|
|
else \
|
219 |
|
|
entry->key = (_key_); \
|
220 |
|
|
} while(0)
|
221 |
|
|
|
222 |
|
|
#define Jim_CompareHashKeys(ht, key1, key2) \
|
223 |
|
|
(((ht)->type->keyCompare) ? \
|
224 |
|
|
(ht)->type->keyCompare((ht)->privdata, key1, key2) : \
|
225 |
|
|
(key1) == (key2))
|
226 |
|
|
|
227 |
|
|
#define Jim_HashKey(ht, key) (ht)->type->hashFunction(key)
|
228 |
|
|
|
229 |
|
|
#define Jim_GetHashEntryKey(he) ((he)->key)
|
230 |
|
|
#define Jim_GetHashEntryVal(he) ((he)->val)
|
231 |
|
|
#define Jim_GetHashTableCollisions(ht) ((ht)->collisions)
|
232 |
|
|
#define Jim_GetHashTableSize(ht) ((ht)->size)
|
233 |
|
|
#define Jim_GetHashTableUsed(ht) ((ht)->used)
|
234 |
|
|
|
235 |
|
|
/* -----------------------------------------------------------------------------
|
236 |
|
|
* Jim_Obj structure
|
237 |
|
|
* ---------------------------------------------------------------------------*/
|
238 |
|
|
|
239 |
|
|
/* -----------------------------------------------------------------------------
|
240 |
|
|
* Jim object. This is mostly the same as Tcl_Obj itself,
|
241 |
|
|
* with the addition of the 'prev' and 'next' pointers.
|
242 |
|
|
* In Jim all the objects are stored into a linked list for GC purposes,
|
243 |
|
|
* so that it's possible to access every object living in a given interpreter
|
244 |
|
|
* sequentially. When an object is freed, it's moved into a different
|
245 |
|
|
* linked list, used as object pool.
|
246 |
|
|
*
|
247 |
|
|
* The refcount of a freed object is always -1.
|
248 |
|
|
* ---------------------------------------------------------------------------*/
|
249 |
|
|
typedef struct Jim_Obj {
|
250 |
|
|
int refCount; /* reference count */
|
251 |
|
|
char *bytes; /* string representation buffer. NULL = no string repr. */
|
252 |
|
|
int length; /* number of bytes in 'bytes', not including the numterm. */
|
253 |
|
|
struct Jim_ObjType *typePtr; /* object type. */
|
254 |
|
|
/* Internal representation union */
|
255 |
|
|
union {
|
256 |
|
|
/* integer number type */
|
257 |
|
|
jim_wide wideValue;
|
258 |
|
|
/* hashed object type value */
|
259 |
|
|
int hashValue;
|
260 |
|
|
/* index type */
|
261 |
|
|
int indexValue;
|
262 |
|
|
/* return code type */
|
263 |
|
|
int returnCode;
|
264 |
|
|
/* double number type */
|
265 |
|
|
double doubleValue;
|
266 |
|
|
/* Generic pointer */
|
267 |
|
|
void *ptr;
|
268 |
|
|
/* Generic two pointers value */
|
269 |
|
|
struct {
|
270 |
|
|
void *ptr1;
|
271 |
|
|
void *ptr2;
|
272 |
|
|
} twoPtrValue;
|
273 |
|
|
/* Variable object */
|
274 |
|
|
struct {
|
275 |
|
|
unsigned jim_wide callFrameId;
|
276 |
|
|
struct Jim_Var *varPtr;
|
277 |
|
|
} varValue;
|
278 |
|
|
/* Command object */
|
279 |
|
|
struct {
|
280 |
|
|
unsigned jim_wide procEpoch;
|
281 |
|
|
struct Jim_Cmd *cmdPtr;
|
282 |
|
|
} cmdValue;
|
283 |
|
|
/* List object */
|
284 |
|
|
struct {
|
285 |
|
|
struct Jim_Obj **ele; /* Elements vector */
|
286 |
|
|
int len; /* Length */
|
287 |
|
|
int maxLen; /* Allocated 'ele' length */
|
288 |
|
|
} listValue;
|
289 |
|
|
/* String type */
|
290 |
|
|
struct {
|
291 |
|
|
int maxLength;
|
292 |
|
|
} strValue;
|
293 |
|
|
/* Reference type */
|
294 |
|
|
struct {
|
295 |
|
|
jim_wide id;
|
296 |
|
|
struct Jim_Reference *refPtr;
|
297 |
|
|
} refValue;
|
298 |
|
|
/* Source type */
|
299 |
|
|
struct {
|
300 |
|
|
const char *fileName;
|
301 |
|
|
int lineNumber;
|
302 |
|
|
} sourceValue;
|
303 |
|
|
/* Dict substitution type */
|
304 |
|
|
struct {
|
305 |
|
|
struct Jim_Obj *varNameObjPtr;
|
306 |
|
|
struct Jim_Obj *indexObjPtr;
|
307 |
|
|
} dictSubstValue;
|
308 |
|
|
/* tagged binary type */
|
309 |
|
|
struct {
|
310 |
|
|
unsigned char *data;
|
311 |
|
|
size_t len;
|
312 |
|
|
} binaryValue;
|
313 |
|
|
} internalRep;
|
314 |
|
|
/* This are 8 or 16 bytes more for every object
|
315 |
|
|
* but this is required for efficient garbage collection
|
316 |
|
|
* of Jim references. */
|
317 |
|
|
struct Jim_Obj *prevObjPtr; /* pointer to the prev object. */
|
318 |
|
|
struct Jim_Obj *nextObjPtr; /* pointer to the next object. */
|
319 |
|
|
} Jim_Obj;
|
320 |
|
|
|
321 |
|
|
/* Jim_Obj related macros */
|
322 |
|
|
#define Jim_IncrRefCount(objPtr) \
|
323 |
|
|
++(objPtr)->refCount
|
324 |
|
|
#define Jim_DecrRefCount(interp, objPtr) \
|
325 |
|
|
if (--(objPtr)->refCount <= 0) Jim_FreeObj(interp, objPtr)
|
326 |
|
|
#define Jim_IsShared(objPtr) \
|
327 |
|
|
((objPtr)->refCount > 1)
|
328 |
|
|
|
329 |
|
|
/* This macro is used when we allocate a new object using
|
330 |
|
|
* Jim_New...Obj(), but for some error we need to destroy it.
|
331 |
|
|
* Instead to use Jim_IncrRefCount() + Jim_DecrRefCount() we
|
332 |
|
|
* can just call Jim_FreeNewObj. To call Jim_Free directly
|
333 |
|
|
* seems too raw, the object handling may change and we want
|
334 |
|
|
* that Jim_FreeNewObj() can be called only against objects
|
335 |
|
|
* that are belived to have refcount == 0. */
|
336 |
|
|
#define Jim_FreeNewObj Jim_FreeObj
|
337 |
|
|
|
338 |
|
|
/* Free the internal representation of the object. */
|
339 |
|
|
#define Jim_FreeIntRep(i,o) \
|
340 |
|
|
if ((o)->typePtr && (o)->typePtr->freeIntRepProc) \
|
341 |
|
|
(o)->typePtr->freeIntRepProc(i, o)
|
342 |
|
|
|
343 |
|
|
/* Get the internal representation pointer */
|
344 |
|
|
#define Jim_GetIntRepPtr(o) (o)->internalRep.ptr
|
345 |
|
|
|
346 |
|
|
/* Set the internal representation pointer */
|
347 |
|
|
#define Jim_SetIntRepPtr(o, p) \
|
348 |
|
|
(o)->internalRep.ptr = (p)
|
349 |
|
|
|
350 |
|
|
/* The object type structure.
|
351 |
|
|
* There are four methods.
|
352 |
|
|
*
|
353 |
|
|
* - FreeIntRep is used to free the internal representation of the object.
|
354 |
|
|
* Can be NULL if there is nothing to free.
|
355 |
|
|
* - DupIntRep is used to duplicate the internal representation of the object.
|
356 |
|
|
* If NULL, when an object is duplicated, the internalRep union is
|
357 |
|
|
* directly copied from an object to another.
|
358 |
|
|
* Note that it's up to the caller to free the old internal repr of the
|
359 |
|
|
* object before to call the Dup method.
|
360 |
|
|
* - UpdateString is used to create the string from the internal repr.
|
361 |
|
|
* - setFromAny is used to convert the current object into one of this type.
|
362 |
|
|
*/
|
363 |
|
|
|
364 |
|
|
struct Jim_Interp;
|
365 |
|
|
|
366 |
|
|
typedef void (Jim_FreeInternalRepProc)(struct Jim_Interp *interp,
|
367 |
|
|
struct Jim_Obj *objPtr);
|
368 |
|
|
typedef void (Jim_DupInternalRepProc)(struct Jim_Interp *interp,
|
369 |
|
|
struct Jim_Obj *srcPtr, Jim_Obj *dupPtr);
|
370 |
|
|
typedef void (Jim_UpdateStringProc)(struct Jim_Obj *objPtr);
|
371 |
|
|
|
372 |
|
|
typedef struct Jim_ObjType {
|
373 |
|
|
const char *name; /* The name of the type. */
|
374 |
|
|
Jim_FreeInternalRepProc *freeIntRepProc;
|
375 |
|
|
Jim_DupInternalRepProc *dupIntRepProc;
|
376 |
|
|
Jim_UpdateStringProc *updateStringProc;
|
377 |
|
|
int flags;
|
378 |
|
|
} Jim_ObjType;
|
379 |
|
|
|
380 |
|
|
/* Jim_ObjType flags */
|
381 |
|
|
#define JIM_TYPE_NONE 0 /* No flags */
|
382 |
|
|
#define JIM_TYPE_REFERENCES 1 /* The object may contain referneces. */
|
383 |
|
|
|
384 |
|
|
/* Starting from 1 << 20 flags are reserved for private uses of
|
385 |
|
|
* different calls. This way the same 'flags' argument may be used
|
386 |
|
|
* to pass both global flags and private flags. */
|
387 |
|
|
#define JIM_PRIV_FLAG_SHIFT 20
|
388 |
|
|
|
389 |
|
|
/* -----------------------------------------------------------------------------
|
390 |
|
|
* Call frame, vars, commands structures
|
391 |
|
|
* ---------------------------------------------------------------------------*/
|
392 |
|
|
|
393 |
|
|
/* Call frame */
|
394 |
|
|
typedef struct Jim_CallFrame {
|
395 |
|
|
unsigned jim_wide id; /* Call Frame ID. Used for caching. */
|
396 |
|
|
struct Jim_HashTable vars; /* Where local vars are stored */
|
397 |
|
|
struct Jim_HashTable *staticVars; /* pointer to procedure static vars */
|
398 |
|
|
struct Jim_CallFrame *parentCallFrame;
|
399 |
|
|
Jim_Obj *const *argv; /* object vector of the current procedure call. */
|
400 |
|
|
int argc; /* number of args of the current procedure call. */
|
401 |
|
|
Jim_Obj *procArgsObjPtr; /* arglist object of the running procedure */
|
402 |
|
|
Jim_Obj *procBodyObjPtr; /* body object of the running procedure */
|
403 |
|
|
struct Jim_CallFrame *nextFramePtr;
|
404 |
|
|
} Jim_CallFrame;
|
405 |
|
|
|
406 |
|
|
/* The var structure. It just holds the pointer of the referenced
|
407 |
|
|
* object. If linkFramePtr is not NULL the variable is a link
|
408 |
|
|
* to a variable of name store on objPtr living on the given callframe
|
409 |
|
|
* (this happens when the [global] or [upvar] command is used).
|
410 |
|
|
* The interp in order to always know how to free the Jim_Obj associated
|
411 |
|
|
* with a given variable because In Jim objects memory managment is
|
412 |
|
|
* bound to interpreters. */
|
413 |
|
|
typedef struct Jim_Var {
|
414 |
|
|
Jim_Obj *objPtr;
|
415 |
|
|
struct Jim_CallFrame *linkFramePtr;
|
416 |
|
|
} Jim_Var;
|
417 |
|
|
|
418 |
|
|
/* The cmd structure. */
|
419 |
|
|
typedef int (*Jim_CmdProc)(struct Jim_Interp *interp, int argc,
|
420 |
|
|
Jim_Obj *const *argv);
|
421 |
|
|
typedef void (*Jim_DelCmdProc)(struct Jim_Interp *interp, void *privData);
|
422 |
|
|
|
423 |
|
|
/* A command is implemented in C if funcPtr is != NULL, otherwise
|
424 |
|
|
* it's a Tcl procedure with the arglist and body represented by the
|
425 |
|
|
* two objects referenced by arglistObjPtr and bodyoObjPtr. */
|
426 |
|
|
typedef struct Jim_Cmd {
|
427 |
|
|
Jim_CmdProc cmdProc; /* Not-NULL for a C command. */
|
428 |
|
|
void *privData; /* Only used for C commands. */
|
429 |
|
|
Jim_DelCmdProc delProc; /* Called when the command is deleted if != NULL */
|
430 |
|
|
Jim_Obj *argListObjPtr;
|
431 |
|
|
Jim_Obj *bodyObjPtr;
|
432 |
|
|
Jim_HashTable *staticVars; /* Static vars hash table. NULL if no statics. */
|
433 |
|
|
int arityMin; /* Min number of arguments. */
|
434 |
|
|
int arityMax; /* Max number of arguments. */
|
435 |
|
|
} Jim_Cmd;
|
436 |
|
|
|
437 |
|
|
/* Pseudo Random Number Generator State structure */
|
438 |
|
|
typedef struct Jim_PrngState {
|
439 |
|
|
unsigned char sbox[256];
|
440 |
|
|
unsigned int i, j;
|
441 |
|
|
} Jim_PrngState;
|
442 |
|
|
|
443 |
|
|
/* -----------------------------------------------------------------------------
|
444 |
|
|
* Jim interpreter structure.
|
445 |
|
|
* Fields similar to the real Tcl interpreter structure have the same names.
|
446 |
|
|
* ---------------------------------------------------------------------------*/
|
447 |
|
|
typedef struct Jim_Interp {
|
448 |
|
|
Jim_Obj *result; /* object returned by the last command called. */
|
449 |
|
|
int errorLine; /* Error line where an error occurred. */
|
450 |
|
|
const char *errorFileName; /* Error file where an error occurred. */
|
451 |
|
|
int numLevels; /* Number of current nested calls. */
|
452 |
|
|
int maxNestingDepth; /* Used for infinite loop detection. */
|
453 |
|
|
int returnCode; /* Completion code to return on JIM_RETURN. */
|
454 |
|
|
int exitCode; /* Code to return to the OS on JIM_EXIT. */
|
455 |
|
|
Jim_CallFrame *framePtr; /* Pointer to the current call frame */
|
456 |
|
|
Jim_CallFrame *topFramePtr; /* toplevel/global frame pointer. */
|
457 |
|
|
struct Jim_HashTable commands; /* Commands hash table */
|
458 |
|
|
unsigned jim_wide procEpoch; /* Incremented every time the result
|
459 |
|
|
of procedures names lookup caching
|
460 |
|
|
may no longer be valid. */
|
461 |
|
|
unsigned jim_wide callFrameEpoch; /* Incremented every time a new
|
462 |
|
|
callframe is created. This id is used for the
|
463 |
|
|
'ID' field contained in the Jim_CallFrame
|
464 |
|
|
structure. */
|
465 |
|
|
Jim_Obj *liveList; /* Linked list of all the live objects. */
|
466 |
|
|
Jim_Obj *freeList; /* Linked list of all the unused objects. */
|
467 |
|
|
const char *scriptFileName; /* File name of the script currently in execution. */
|
468 |
|
|
Jim_Obj *emptyObj; /* Shared empty string object. */
|
469 |
|
|
unsigned jim_wide referenceNextId; /* Next id for reference. */
|
470 |
|
|
struct Jim_HashTable references; /* References hash table. */
|
471 |
|
|
jim_wide lastCollectId; /* reference max Id of the last GC
|
472 |
|
|
execution. It's set to -1 while the collection
|
473 |
|
|
is running as sentinel to avoid to recursive
|
474 |
|
|
calls via the [collect] command inside
|
475 |
|
|
finalizers. */
|
476 |
|
|
time_t lastCollectTime; /* unix time of the last GC execution */
|
477 |
|
|
struct Jim_HashTable sharedStrings; /* Shared Strings hash table */
|
478 |
|
|
Jim_Obj *stackTrace; /* Stack trace object. */
|
479 |
|
|
Jim_Obj *unknown; /* Unknown command cache */
|
480 |
|
|
int errorFlag; /* Set if an error occurred during execution. */
|
481 |
|
|
int evalRetcodeLevel; /* Level where the last return with code JIM_EVAL
|
482 |
|
|
happened. */
|
483 |
|
|
void *cmdPrivData; /* Used to pass the private data pointer to
|
484 |
|
|
a command. It is set to what the user specified
|
485 |
|
|
via Jim_CreateCommand(). */
|
486 |
|
|
|
487 |
|
|
struct Jim_HashTable stub; /* Stub hash table to export API */
|
488 |
|
|
/* Jim_GetApi() function pointer, used to bootstrap the STUB table */
|
489 |
|
|
int (*getApiFuncPtr)(struct Jim_Interp *, const char *, void *);
|
490 |
|
|
struct Jim_CallFrame *freeFramesList; /* list of CallFrame structures. */
|
491 |
|
|
struct Jim_HashTable assocData; /* per-interp storage for use by packages */
|
492 |
|
|
Jim_PrngState *prngState; /* per interpreter Random Number Gen. state. */
|
493 |
|
|
struct Jim_HashTable packages; /* Provided packages hash table */
|
494 |
|
|
FILE *stdin; /* input file pointer, 'stdin' by default */
|
495 |
|
|
FILE *stdout; /* output file pointer, 'stdout' by default */
|
496 |
|
|
FILE *stderr; /* errors file pointer, 'stderr' by default */
|
497 |
|
|
} Jim_Interp;
|
498 |
|
|
|
499 |
|
|
/* Currently provided as macro that performs the increment.
|
500 |
|
|
* At some point may be a real function doing more work.
|
501 |
|
|
* The proc epoch is used in order to know when a command lookup
|
502 |
|
|
* cached can no longer considered valid. */
|
503 |
|
|
#define Jim_InterpIncrProcEpoch(i) (i)->procEpoch++
|
504 |
|
|
#define Jim_SetResultString(i,s,l) Jim_SetResult(i, Jim_NewStringObj(i,s,l))
|
505 |
|
|
#define Jim_SetEmptyResult(i) Jim_SetResult(i, (i)->emptyObj)
|
506 |
|
|
#define Jim_GetResult(i) ((i)->result)
|
507 |
|
|
#define Jim_CmdPrivData(i) ((i)->cmdPrivData)
|
508 |
|
|
|
509 |
|
|
/* Note that 'o' is expanded only one time inside this macro,
|
510 |
|
|
* so it's safe to use side effects. */
|
511 |
|
|
#define Jim_SetResult(i,o) do { \
|
512 |
|
|
Jim_Obj *_resultObjPtr_ = (o); \
|
513 |
|
|
Jim_IncrRefCount(_resultObjPtr_); \
|
514 |
|
|
Jim_DecrRefCount(i,(i)->result); \
|
515 |
|
|
(i)->result = _resultObjPtr_; \
|
516 |
|
|
} while(0)
|
517 |
|
|
|
518 |
|
|
/* Reference structure. The interpreter pointer is held within privdata member in HashTable */
|
519 |
|
|
#define JIM_REFERENCE_TAGLEN 7 /* The tag is fixed-length, because the reference
|
520 |
|
|
string representation must be fixed length. */
|
521 |
|
|
typedef struct Jim_Reference {
|
522 |
|
|
Jim_Obj *objPtr;
|
523 |
|
|
Jim_Obj *finalizerCmdNamePtr;
|
524 |
|
|
char tag[JIM_REFERENCE_TAGLEN+1];
|
525 |
|
|
} Jim_Reference;
|
526 |
|
|
|
527 |
|
|
/* -----------------------------------------------------------------------------
|
528 |
|
|
* Exported API prototypes.
|
529 |
|
|
* ---------------------------------------------------------------------------*/
|
530 |
|
|
|
531 |
|
|
/* Macros that are common for extensions and core. */
|
532 |
|
|
#define Jim_NewEmptyStringObj(i) Jim_NewStringObj(i, "", 0)
|
533 |
|
|
|
534 |
|
|
/* The core includes real prototypes, extensions instead
|
535 |
|
|
* include a global function pointer for every function exported.
|
536 |
|
|
* Once the extension calls Jim_InitExtension(), the global
|
537 |
|
|
* functon pointers are set to the value of the STUB table
|
538 |
|
|
* contained in the Jim_Interp structure.
|
539 |
|
|
*
|
540 |
|
|
* This makes Jim able to load extensions even if it is statically
|
541 |
|
|
* linked itself, and to load extensions compiled with different
|
542 |
|
|
* versions of Jim (as long as the API is still compatible.) */
|
543 |
|
|
|
544 |
|
|
/* Macros are common for core and extensions */
|
545 |
|
|
#define Jim_FreeHashTableIterator(iter) Jim_Free(iter)
|
546 |
|
|
|
547 |
|
|
#ifndef __JIM_CORE__
|
548 |
|
|
# if defined JIM_EXTENSION || defined JIM_EMBEDDED
|
549 |
|
|
# define JIM_API(x) (*x)
|
550 |
|
|
# define JIM_STATIC
|
551 |
|
|
# else
|
552 |
|
|
# define JIM_API(x) (*x)
|
553 |
|
|
# define JIM_STATIC extern
|
554 |
|
|
# endif
|
555 |
|
|
#else
|
556 |
|
|
# define JIM_API(x) x
|
557 |
|
|
# define JIM_STATIC static
|
558 |
|
|
#endif /* __JIM_CORE__ */
|
559 |
|
|
|
560 |
|
|
/* Memory allocation */
|
561 |
|
|
JIM_STATIC void * JIM_API(Jim_Alloc) (int size);
|
562 |
|
|
JIM_STATIC void JIM_API(Jim_Free) (void *ptr);
|
563 |
|
|
JIM_STATIC char * JIM_API(Jim_StrDup) (const char *s);
|
564 |
|
|
|
565 |
|
|
/* evaluation */
|
566 |
|
|
JIM_STATIC int JIM_API(Jim_Eval)(Jim_Interp *interp, const char *script);
|
567 |
|
|
JIM_STATIC int JIM_API(Jim_EvalGlobal)(Jim_Interp *interp, const char *script);
|
568 |
|
|
JIM_STATIC int JIM_API(Jim_EvalFile)(Jim_Interp *interp, const char *filename);
|
569 |
|
|
JIM_STATIC int JIM_API(Jim_EvalObj) (Jim_Interp *interp, Jim_Obj *scriptObjPtr);
|
570 |
|
|
JIM_STATIC int JIM_API(Jim_EvalObjBackground) (Jim_Interp *interp,
|
571 |
|
|
Jim_Obj *scriptObjPtr);
|
572 |
|
|
JIM_STATIC int JIM_API(Jim_EvalObjVector) (Jim_Interp *interp, int objc,
|
573 |
|
|
Jim_Obj *const *objv);
|
574 |
|
|
JIM_STATIC int JIM_API(Jim_SubstObj) (Jim_Interp *interp, Jim_Obj *substObjPtr,
|
575 |
|
|
Jim_Obj **resObjPtrPtr, int flags);
|
576 |
|
|
|
577 |
|
|
/* stack */
|
578 |
|
|
JIM_STATIC void JIM_API(Jim_InitStack)(Jim_Stack *stack);
|
579 |
|
|
JIM_STATIC void JIM_API(Jim_FreeStack)(Jim_Stack *stack);
|
580 |
|
|
JIM_STATIC int JIM_API(Jim_StackLen)(Jim_Stack *stack);
|
581 |
|
|
JIM_STATIC void JIM_API(Jim_StackPush)(Jim_Stack *stack, void *element);
|
582 |
|
|
JIM_STATIC void * JIM_API(Jim_StackPop)(Jim_Stack *stack);
|
583 |
|
|
JIM_STATIC void * JIM_API(Jim_StackPeek)(Jim_Stack *stack);
|
584 |
|
|
JIM_STATIC void JIM_API(Jim_FreeStackElements)(Jim_Stack *stack, void (*freeFunc)(void *ptr));
|
585 |
|
|
|
586 |
|
|
/* hash table */
|
587 |
|
|
JIM_STATIC int JIM_API(Jim_InitHashTable) (Jim_HashTable *ht,
|
588 |
|
|
Jim_HashTableType *type, void *privdata);
|
589 |
|
|
JIM_STATIC int JIM_API(Jim_ExpandHashTable) (Jim_HashTable *ht,
|
590 |
|
|
unsigned int size);
|
591 |
|
|
JIM_STATIC int JIM_API(Jim_AddHashEntry) (Jim_HashTable *ht, const void *key,
|
592 |
|
|
void *val);
|
593 |
|
|
JIM_STATIC int JIM_API(Jim_ReplaceHashEntry) (Jim_HashTable *ht,
|
594 |
|
|
const void *key, void *val);
|
595 |
|
|
JIM_STATIC int JIM_API(Jim_DeleteHashEntry) (Jim_HashTable *ht,
|
596 |
|
|
const void *key);
|
597 |
|
|
JIM_STATIC int JIM_API(Jim_FreeHashTable) (Jim_HashTable *ht);
|
598 |
|
|
JIM_STATIC Jim_HashEntry * JIM_API(Jim_FindHashEntry) (Jim_HashTable *ht,
|
599 |
|
|
const void *key);
|
600 |
|
|
JIM_STATIC int JIM_API(Jim_ResizeHashTable) (Jim_HashTable *ht);
|
601 |
|
|
JIM_STATIC Jim_HashTableIterator *JIM_API(Jim_GetHashTableIterator)
|
602 |
|
|
(Jim_HashTable *ht);
|
603 |
|
|
JIM_STATIC Jim_HashEntry * JIM_API(Jim_NextHashEntry)
|
604 |
|
|
(Jim_HashTableIterator *iter);
|
605 |
|
|
|
606 |
|
|
/* objects */
|
607 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewObj) (Jim_Interp *interp);
|
608 |
|
|
JIM_STATIC void JIM_API(Jim_FreeObj) (Jim_Interp *interp, Jim_Obj *objPtr);
|
609 |
|
|
JIM_STATIC void JIM_API(Jim_InvalidateStringRep) (Jim_Obj *objPtr);
|
610 |
|
|
JIM_STATIC void JIM_API(Jim_InitStringRep) (Jim_Obj *objPtr, const char *bytes,
|
611 |
|
|
int length);
|
612 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_DuplicateObj) (Jim_Interp *interp,
|
613 |
|
|
Jim_Obj *objPtr);
|
614 |
|
|
JIM_STATIC const char * JIM_API(Jim_GetString)(Jim_Obj *objPtr,
|
615 |
|
|
int *lenPtr);
|
616 |
|
|
JIM_STATIC int JIM_API(Jim_Length)(Jim_Obj *objPtr);
|
617 |
|
|
|
618 |
|
|
/* string object */
|
619 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewStringObj) (Jim_Interp *interp,
|
620 |
|
|
const char *s, int len);
|
621 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewStringObjNoAlloc) (Jim_Interp *interp,
|
622 |
|
|
char *s, int len);
|
623 |
|
|
JIM_STATIC void JIM_API(Jim_AppendString) (Jim_Interp *interp, Jim_Obj *objPtr,
|
624 |
|
|
const char *str, int len);
|
625 |
|
|
JIM_STATIC void JIM_API(Jim_AppendObj) (Jim_Interp *interp, Jim_Obj *objPtr,
|
626 |
|
|
Jim_Obj *appendObjPtr);
|
627 |
|
|
JIM_STATIC void JIM_API(Jim_AppendStrings) (Jim_Interp *interp,
|
628 |
|
|
Jim_Obj *objPtr, ...);
|
629 |
|
|
JIM_STATIC int JIM_API(Jim_StringEqObj) (Jim_Obj *aObjPtr,
|
630 |
|
|
Jim_Obj *bObjPtr, int nocase);
|
631 |
|
|
JIM_STATIC int JIM_API(Jim_StringMatchObj) (Jim_Obj *patternObjPtr,
|
632 |
|
|
Jim_Obj *objPtr, int nocase);
|
633 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_StringRangeObj) (Jim_Interp *interp,
|
634 |
|
|
Jim_Obj *strObjPtr, Jim_Obj *firstObjPtr,
|
635 |
|
|
Jim_Obj *lastObjPtr);
|
636 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_FormatString) (Jim_Interp *interp,
|
637 |
|
|
Jim_Obj *fmtObjPtr, int objc, Jim_Obj *const *objv);
|
638 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_ScanString) (Jim_Interp *interp, Jim_Obj *strObjPtr,
|
639 |
|
|
Jim_Obj *fmtObjPtr, int flags);
|
640 |
|
|
JIM_STATIC int JIM_API(Jim_CompareStringImmediate) (Jim_Interp *interp,
|
641 |
|
|
Jim_Obj *objPtr, const char *str);
|
642 |
|
|
|
643 |
|
|
/* reference object */
|
644 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewReference) (Jim_Interp *interp,
|
645 |
|
|
Jim_Obj *objPtr, Jim_Obj *tagPtr, Jim_Obj *cmdNamePtr);
|
646 |
|
|
JIM_STATIC Jim_Reference * JIM_API(Jim_GetReference) (Jim_Interp *interp,
|
647 |
|
|
Jim_Obj *objPtr);
|
648 |
|
|
JIM_STATIC int JIM_API(Jim_SetFinalizer) (Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj *cmdNamePtr);
|
649 |
|
|
JIM_STATIC int JIM_API(Jim_GetFinalizer) (Jim_Interp *interp, Jim_Obj *objPtr, Jim_Obj **cmdNamePtrPtr);
|
650 |
|
|
|
651 |
|
|
/* interpreter */
|
652 |
|
|
JIM_STATIC Jim_Interp * JIM_API(Jim_CreateInterp) (void);
|
653 |
|
|
JIM_STATIC void JIM_API(Jim_FreeInterp) (Jim_Interp *i);
|
654 |
|
|
JIM_STATIC int JIM_API(Jim_GetExitCode) (Jim_Interp *interp);
|
655 |
|
|
JIM_STATIC FILE * JIM_API(Jim_SetStdin) (Jim_Interp *interp, FILE *fp);
|
656 |
|
|
JIM_STATIC FILE * JIM_API(Jim_SetStdout) (Jim_Interp *interp, FILE *fp);
|
657 |
|
|
JIM_STATIC FILE * JIM_API(Jim_SetStderr) (Jim_Interp *interp, FILE *fp);
|
658 |
|
|
|
659 |
|
|
/* commands */
|
660 |
|
|
JIM_STATIC void JIM_API(Jim_RegisterCoreCommands) (Jim_Interp *interp);
|
661 |
|
|
JIM_STATIC int JIM_API(Jim_CreateCommand) (Jim_Interp *interp,
|
662 |
|
|
const char *cmdName, Jim_CmdProc cmdProc, void *privData,
|
663 |
|
|
Jim_DelCmdProc delProc);
|
664 |
|
|
JIM_STATIC int JIM_API(Jim_CreateProcedure) (Jim_Interp *interp,
|
665 |
|
|
const char *cmdName, Jim_Obj *argListObjPtr, Jim_Obj *staticsListObjPtr,
|
666 |
|
|
Jim_Obj *bodyObjPtr, int arityMin, int arityMax);
|
667 |
|
|
JIM_STATIC int JIM_API(Jim_DeleteCommand) (Jim_Interp *interp,
|
668 |
|
|
const char *cmdName);
|
669 |
|
|
JIM_STATIC int JIM_API(Jim_RenameCommand) (Jim_Interp *interp,
|
670 |
|
|
const char *oldName, const char *newName);
|
671 |
|
|
JIM_STATIC Jim_Cmd * JIM_API(Jim_GetCommand) (Jim_Interp *interp,
|
672 |
|
|
Jim_Obj *objPtr, int flags);
|
673 |
|
|
JIM_STATIC int JIM_API(Jim_SetVariable) (Jim_Interp *interp,
|
674 |
|
|
Jim_Obj *nameObjPtr, Jim_Obj *valObjPtr);
|
675 |
|
|
JIM_STATIC int JIM_API(Jim_SetVariableStr) (Jim_Interp *interp,
|
676 |
|
|
const char *name, Jim_Obj *objPtr);
|
677 |
|
|
JIM_STATIC int JIM_API(Jim_SetGlobalVariableStr) (Jim_Interp *interp,
|
678 |
|
|
const char *name, Jim_Obj *objPtr);
|
679 |
|
|
JIM_STATIC int JIM_API(Jim_SetVariableStrWithStr) (Jim_Interp *interp,
|
680 |
|
|
const char *name, const char *val);
|
681 |
|
|
JIM_STATIC int JIM_API(Jim_SetVariableLink) (Jim_Interp *interp,
|
682 |
|
|
Jim_Obj *nameObjPtr, Jim_Obj *targetNameObjPtr,
|
683 |
|
|
Jim_CallFrame *targetCallFrame);
|
684 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_GetVariable) (Jim_Interp *interp,
|
685 |
|
|
Jim_Obj *nameObjPtr, int flags);
|
686 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_GetGlobalVariable) (Jim_Interp *interp,
|
687 |
|
|
Jim_Obj *nameObjPtr, int flags);
|
688 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_GetVariableStr) (Jim_Interp *interp,
|
689 |
|
|
const char *name, int flags);
|
690 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_GetGlobalVariableStr) (Jim_Interp *interp,
|
691 |
|
|
const char *name, int flags);
|
692 |
|
|
JIM_STATIC int JIM_API(Jim_UnsetVariable) (Jim_Interp *interp,
|
693 |
|
|
Jim_Obj *nameObjPtr, int flags);
|
694 |
|
|
|
695 |
|
|
/* call frame */
|
696 |
|
|
JIM_STATIC int JIM_API(Jim_GetCallFrameByLevel) (Jim_Interp *interp,
|
697 |
|
|
Jim_Obj *levelObjPtr, Jim_CallFrame **framePtrPtr,
|
698 |
|
|
int *newLevelPtr);
|
699 |
|
|
|
700 |
|
|
/* garbage collection */
|
701 |
|
|
JIM_STATIC int JIM_API(Jim_Collect) (Jim_Interp *interp);
|
702 |
|
|
JIM_STATIC void JIM_API(Jim_CollectIfNeeded) (Jim_Interp *interp);
|
703 |
|
|
|
704 |
|
|
/* index object */
|
705 |
|
|
JIM_STATIC int JIM_API(Jim_GetIndex) (Jim_Interp *interp, Jim_Obj *objPtr,
|
706 |
|
|
int *indexPtr);
|
707 |
|
|
|
708 |
|
|
/* list object */
|
709 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewListObj) (Jim_Interp *interp,
|
710 |
|
|
Jim_Obj *const *elements, int len);
|
711 |
|
|
JIM_STATIC void JIM_API(Jim_ListInsertElements) (Jim_Interp *interp,
|
712 |
|
|
Jim_Obj *listPtr, int index, int objc, Jim_Obj *const *objVec);
|
713 |
|
|
JIM_STATIC void JIM_API(Jim_ListAppendElement) (Jim_Interp *interp,
|
714 |
|
|
Jim_Obj *listPtr, Jim_Obj *objPtr);
|
715 |
|
|
JIM_STATIC void JIM_API(Jim_ListAppendList) (Jim_Interp *interp,
|
716 |
|
|
Jim_Obj *listPtr, Jim_Obj *appendListPtr);
|
717 |
|
|
JIM_STATIC void JIM_API(Jim_ListLength) (Jim_Interp *interp, Jim_Obj *listPtr,
|
718 |
|
|
int *intPtr);
|
719 |
|
|
JIM_STATIC int JIM_API(Jim_ListIndex) (Jim_Interp *interp, Jim_Obj *listPrt,
|
720 |
|
|
int index, Jim_Obj **objPtrPtr, int seterr);
|
721 |
|
|
JIM_STATIC int JIM_API(Jim_SetListIndex) (Jim_Interp *interp,
|
722 |
|
|
Jim_Obj *varNamePtr, Jim_Obj *const *indexv, int indexc,
|
723 |
|
|
Jim_Obj *newObjPtr);
|
724 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_ConcatObj) (Jim_Interp *interp, int objc,
|
725 |
|
|
Jim_Obj *const *objv);
|
726 |
|
|
|
727 |
|
|
/* dict object */
|
728 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewDictObj) (Jim_Interp *interp,
|
729 |
|
|
Jim_Obj *const *elements, int len);
|
730 |
|
|
JIM_STATIC int JIM_API(Jim_DictKey) (Jim_Interp *interp, Jim_Obj *dictPtr,
|
731 |
|
|
Jim_Obj *keyPtr, Jim_Obj **objPtrPtr, int flags);
|
732 |
|
|
JIM_STATIC int JIM_API(Jim_DictKeysVector) (Jim_Interp *interp,
|
733 |
|
|
Jim_Obj *dictPtr, Jim_Obj *const *keyv, int keyc,
|
734 |
|
|
Jim_Obj **objPtrPtr, int flags);
|
735 |
|
|
JIM_STATIC int JIM_API(Jim_SetDictKeysVector) (Jim_Interp *interp,
|
736 |
|
|
Jim_Obj *varNamePtr, Jim_Obj *const *keyv, int keyc,
|
737 |
|
|
Jim_Obj *newObjPtr);
|
738 |
|
|
|
739 |
|
|
/* return code object */
|
740 |
|
|
JIM_STATIC int JIM_API(Jim_GetReturnCode) (Jim_Interp *interp, Jim_Obj *objPtr,
|
741 |
|
|
int *intPtr);
|
742 |
|
|
|
743 |
|
|
/* expression object */
|
744 |
|
|
JIM_STATIC int JIM_API(Jim_EvalExpression) (Jim_Interp *interp,
|
745 |
|
|
Jim_Obj *exprObjPtr, Jim_Obj **exprResultPtrPtr);
|
746 |
|
|
JIM_STATIC int JIM_API(Jim_GetBoolFromExpr) (Jim_Interp *interp,
|
747 |
|
|
Jim_Obj *exprObjPtr, int *boolPtr);
|
748 |
|
|
|
749 |
|
|
/* integer object */
|
750 |
|
|
JIM_STATIC int JIM_API(Jim_GetWide) (Jim_Interp *interp, Jim_Obj *objPtr,
|
751 |
|
|
jim_wide *widePtr);
|
752 |
|
|
JIM_STATIC int JIM_API(Jim_GetLong) (Jim_Interp *interp, Jim_Obj *objPtr,
|
753 |
|
|
long *longPtr);
|
754 |
|
|
JIM_STATIC void JIM_API(Jim_SetWide) (Jim_Interp *interp, Jim_Obj *objPtr,
|
755 |
|
|
jim_wide wideValue);
|
756 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewIntObj) (Jim_Interp *interp,
|
757 |
|
|
jim_wide wideValue);
|
758 |
|
|
|
759 |
|
|
/* double object */
|
760 |
|
|
JIM_STATIC int JIM_API(Jim_GetDouble)(Jim_Interp *interp, Jim_Obj *objPtr,
|
761 |
|
|
double *doublePtr);
|
762 |
|
|
JIM_STATIC void JIM_API(Jim_SetDouble)(Jim_Interp *interp, Jim_Obj *objPtr,
|
763 |
|
|
double doubleValue);
|
764 |
|
|
JIM_STATIC Jim_Obj * JIM_API(Jim_NewDoubleObj)(Jim_Interp *interp, double doubleValue);
|
765 |
|
|
|
766 |
|
|
/* shared strings */
|
767 |
|
|
JIM_STATIC const char * JIM_API(Jim_GetSharedString) (Jim_Interp *interp,
|
768 |
|
|
const char *str);
|
769 |
|
|
JIM_STATIC void JIM_API(Jim_ReleaseSharedString) (Jim_Interp *interp,
|
770 |
|
|
const char *str);
|
771 |
|
|
|
772 |
|
|
/* commands utilities */
|
773 |
|
|
JIM_STATIC void JIM_API(Jim_WrongNumArgs) (Jim_Interp *interp, int argc,
|
774 |
|
|
Jim_Obj *const *argv, const char *msg);
|
775 |
|
|
JIM_STATIC int JIM_API(Jim_GetEnum) (Jim_Interp *interp, Jim_Obj *objPtr,
|
776 |
|
|
const char **tablePtr, int *indexPtr, const char *name, int flags);
|
777 |
|
|
JIM_STATIC int JIM_API(Jim_ScriptIsComplete) (const char *s, int len,
|
778 |
|
|
char *stateCharPtr);
|
779 |
|
|
|
780 |
|
|
/* package utilities */
|
781 |
|
|
typedef void (Jim_InterpDeleteProc)(Jim_Interp *interp, void *data);
|
782 |
|
|
JIM_STATIC void * JIM_API(Jim_GetAssocData)(Jim_Interp *interp, const char *key);
|
783 |
|
|
JIM_STATIC int JIM_API(Jim_SetAssocData)(Jim_Interp *interp, const char *key,
|
784 |
|
|
Jim_InterpDeleteProc *delProc, void *data);
|
785 |
|
|
JIM_STATIC int JIM_API(Jim_DeleteAssocData)(Jim_Interp *interp, const char *key);
|
786 |
|
|
|
787 |
|
|
/* API import/export functions */
|
788 |
|
|
JIM_STATIC int JIM_API(Jim_GetApi) (Jim_Interp *interp, const char *funcname,
|
789 |
|
|
void *targetPtrPtr);
|
790 |
|
|
JIM_STATIC int JIM_API(Jim_RegisterApi) (Jim_Interp *interp,
|
791 |
|
|
const char *funcname, void *funcptr);
|
792 |
|
|
|
793 |
|
|
/* Packages C API */
|
794 |
|
|
JIM_STATIC int JIM_API(Jim_PackageProvide) (Jim_Interp *interp,
|
795 |
|
|
const char *name, const char *ver, int flags);
|
796 |
|
|
JIM_STATIC const char * JIM_API(Jim_PackageRequire) (Jim_Interp *interp,
|
797 |
|
|
const char *name, const char *ver, int flags);
|
798 |
|
|
|
799 |
|
|
/* error messages */
|
800 |
|
|
JIM_STATIC void JIM_API(Jim_PrintErrorMessage) (Jim_Interp *interp);
|
801 |
|
|
|
802 |
|
|
/* interactive mode */
|
803 |
|
|
JIM_STATIC int JIM_API(Jim_InteractivePrompt) (Jim_Interp *interp);
|
804 |
|
|
|
805 |
|
|
/* Misc */
|
806 |
|
|
JIM_STATIC void JIM_API(Jim_Panic) (Jim_Interp *interp, const char *fmt, ...);
|
807 |
|
|
|
808 |
|
|
#undef JIM_STATIC
|
809 |
|
|
#undef JIM_API
|
810 |
|
|
|
811 |
|
|
#ifndef __JIM_CORE__
|
812 |
|
|
|
813 |
|
|
#define JIM_GET_API(name) \
|
814 |
|
|
Jim_GetApi(interp, "Jim_" #name, ((void *)&Jim_ ## name))
|
815 |
|
|
|
816 |
|
|
#if defined JIM_EXTENSION || defined JIM_EMBEDDED
|
817 |
|
|
/* This must be included "inline" inside the extension */
|
818 |
|
|
static void Jim_InitExtension(Jim_Interp *interp)
|
819 |
|
|
{
|
820 |
|
|
Jim_GetApi = interp->getApiFuncPtr;
|
821 |
|
|
|
822 |
|
|
JIM_GET_API(Alloc);
|
823 |
|
|
JIM_GET_API(Free);
|
824 |
|
|
JIM_GET_API(Eval);
|
825 |
|
|
JIM_GET_API(EvalGlobal);
|
826 |
|
|
JIM_GET_API(EvalFile);
|
827 |
|
|
JIM_GET_API(EvalObj);
|
828 |
|
|
JIM_GET_API(EvalObjBackground);
|
829 |
|
|
JIM_GET_API(EvalObjVector);
|
830 |
|
|
JIM_GET_API(InitHashTable);
|
831 |
|
|
JIM_GET_API(ExpandHashTable);
|
832 |
|
|
JIM_GET_API(AddHashEntry);
|
833 |
|
|
JIM_GET_API(ReplaceHashEntry);
|
834 |
|
|
JIM_GET_API(DeleteHashEntry);
|
835 |
|
|
JIM_GET_API(FreeHashTable);
|
836 |
|
|
JIM_GET_API(FindHashEntry);
|
837 |
|
|
JIM_GET_API(ResizeHashTable);
|
838 |
|
|
JIM_GET_API(GetHashTableIterator);
|
839 |
|
|
JIM_GET_API(NextHashEntry);
|
840 |
|
|
JIM_GET_API(NewObj);
|
841 |
|
|
JIM_GET_API(FreeObj);
|
842 |
|
|
JIM_GET_API(InvalidateStringRep);
|
843 |
|
|
JIM_GET_API(InitStringRep);
|
844 |
|
|
JIM_GET_API(DuplicateObj);
|
845 |
|
|
JIM_GET_API(GetString);
|
846 |
|
|
JIM_GET_API(Length);
|
847 |
|
|
JIM_GET_API(InvalidateStringRep);
|
848 |
|
|
JIM_GET_API(NewStringObj);
|
849 |
|
|
JIM_GET_API(NewStringObjNoAlloc);
|
850 |
|
|
JIM_GET_API(AppendString);
|
851 |
|
|
JIM_GET_API(AppendObj);
|
852 |
|
|
JIM_GET_API(AppendStrings);
|
853 |
|
|
JIM_GET_API(StringEqObj);
|
854 |
|
|
JIM_GET_API(StringMatchObj);
|
855 |
|
|
JIM_GET_API(StringRangeObj);
|
856 |
|
|
JIM_GET_API(FormatString);
|
857 |
|
|
JIM_GET_API(ScanString);
|
858 |
|
|
JIM_GET_API(CompareStringImmediate);
|
859 |
|
|
JIM_GET_API(NewReference);
|
860 |
|
|
JIM_GET_API(GetReference);
|
861 |
|
|
JIM_GET_API(SetFinalizer);
|
862 |
|
|
JIM_GET_API(GetFinalizer);
|
863 |
|
|
JIM_GET_API(CreateInterp);
|
864 |
|
|
JIM_GET_API(FreeInterp);
|
865 |
|
|
JIM_GET_API(GetExitCode);
|
866 |
|
|
JIM_GET_API(SetStdin);
|
867 |
|
|
JIM_GET_API(SetStdout);
|
868 |
|
|
JIM_GET_API(SetStderr);
|
869 |
|
|
JIM_GET_API(CreateCommand);
|
870 |
|
|
JIM_GET_API(CreateProcedure);
|
871 |
|
|
JIM_GET_API(DeleteCommand);
|
872 |
|
|
JIM_GET_API(RenameCommand);
|
873 |
|
|
JIM_GET_API(GetCommand);
|
874 |
|
|
JIM_GET_API(SetVariable);
|
875 |
|
|
JIM_GET_API(SetVariableStr);
|
876 |
|
|
JIM_GET_API(SetGlobalVariableStr);
|
877 |
|
|
JIM_GET_API(SetVariableStrWithStr);
|
878 |
|
|
JIM_GET_API(SetVariableLink);
|
879 |
|
|
JIM_GET_API(GetVariable);
|
880 |
|
|
JIM_GET_API(GetCallFrameByLevel);
|
881 |
|
|
JIM_GET_API(Collect);
|
882 |
|
|
JIM_GET_API(CollectIfNeeded);
|
883 |
|
|
JIM_GET_API(GetIndex);
|
884 |
|
|
JIM_GET_API(NewListObj);
|
885 |
|
|
JIM_GET_API(ListInsertElements);
|
886 |
|
|
JIM_GET_API(ListAppendElement);
|
887 |
|
|
JIM_GET_API(ListAppendList);
|
888 |
|
|
JIM_GET_API(ListLength);
|
889 |
|
|
JIM_GET_API(ListIndex);
|
890 |
|
|
JIM_GET_API(SetListIndex);
|
891 |
|
|
JIM_GET_API(ConcatObj);
|
892 |
|
|
JIM_GET_API(NewDictObj);
|
893 |
|
|
JIM_GET_API(DictKey);
|
894 |
|
|
JIM_GET_API(DictKeysVector);
|
895 |
|
|
JIM_GET_API(GetIndex);
|
896 |
|
|
JIM_GET_API(GetReturnCode);
|
897 |
|
|
JIM_GET_API(EvalExpression);
|
898 |
|
|
JIM_GET_API(GetBoolFromExpr);
|
899 |
|
|
JIM_GET_API(GetWide);
|
900 |
|
|
JIM_GET_API(GetLong);
|
901 |
|
|
JIM_GET_API(SetWide);
|
902 |
|
|
JIM_GET_API(NewIntObj);
|
903 |
|
|
JIM_GET_API(GetDouble);
|
904 |
|
|
JIM_GET_API(SetDouble);
|
905 |
|
|
JIM_GET_API(NewDoubleObj);
|
906 |
|
|
JIM_GET_API(WrongNumArgs);
|
907 |
|
|
JIM_GET_API(SetDictKeysVector);
|
908 |
|
|
JIM_GET_API(SubstObj);
|
909 |
|
|
JIM_GET_API(RegisterApi);
|
910 |
|
|
JIM_GET_API(PrintErrorMessage);
|
911 |
|
|
JIM_GET_API(InteractivePrompt);
|
912 |
|
|
JIM_GET_API(RegisterCoreCommands);
|
913 |
|
|
JIM_GET_API(GetSharedString);
|
914 |
|
|
JIM_GET_API(ReleaseSharedString);
|
915 |
|
|
JIM_GET_API(Panic);
|
916 |
|
|
JIM_GET_API(StrDup);
|
917 |
|
|
JIM_GET_API(UnsetVariable);
|
918 |
|
|
JIM_GET_API(GetVariableStr);
|
919 |
|
|
JIM_GET_API(GetGlobalVariable);
|
920 |
|
|
JIM_GET_API(GetGlobalVariableStr);
|
921 |
|
|
JIM_GET_API(GetAssocData);
|
922 |
|
|
JIM_GET_API(SetAssocData);
|
923 |
|
|
JIM_GET_API(DeleteAssocData);
|
924 |
|
|
JIM_GET_API(GetEnum);
|
925 |
|
|
JIM_GET_API(ScriptIsComplete);
|
926 |
|
|
JIM_GET_API(PackageProvide);
|
927 |
|
|
JIM_GET_API(PackageRequire);
|
928 |
|
|
JIM_GET_API(InitStack);
|
929 |
|
|
JIM_GET_API(FreeStack);
|
930 |
|
|
JIM_GET_API(StackLen);
|
931 |
|
|
JIM_GET_API(StackPush);
|
932 |
|
|
JIM_GET_API(StackPop);
|
933 |
|
|
JIM_GET_API(StackPeek);
|
934 |
|
|
JIM_GET_API(FreeStackElements);
|
935 |
|
|
}
|
936 |
|
|
#endif /* defined JIM_EXTENSION || defined JIM_EMBEDDED */
|
937 |
|
|
|
938 |
|
|
#undef JIM_GET_API
|
939 |
|
|
|
940 |
|
|
#ifdef JIM_EMBEDDED
|
941 |
|
|
Jim_Interp *ExportedJimCreateInterp(void);
|
942 |
|
|
static void Jim_InitEmbedded(void) {
|
943 |
|
|
Jim_Interp *i = ExportedJimCreateInterp();
|
944 |
|
|
Jim_InitExtension(i);
|
945 |
|
|
Jim_FreeInterp(i);
|
946 |
|
|
}
|
947 |
|
|
#endif /* JIM_EMBEDDED */
|
948 |
|
|
#endif /* __JIM_CORE__ */
|
949 |
|
|
|
950 |
|
|
#ifdef __cplusplus
|
951 |
|
|
}
|
952 |
|
|
#endif
|
953 |
|
|
|
954 |
|
|
#endif /* __JIM__H */
|