1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
|
/*
* @file ejsInternal.h
* @brief Private header for Embedded Javascript (ECMAScript)
* @overview This Embedded Javascript header defines the private Embedded
* Javascript internal structures.
*/
/********************************* Copyright **********************************/
/*
* @copy default.g
*
* Copyright (c) Mbedthis Software LLC, 2003-2005. All Rights Reserved.
* Portions Copyright (c) GoAhead Software, 1995-2000. 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
*/
/********************************* Includes ***********************************/
#ifndef _h_EJS_INTERNAL
#define _h_EJS_INTERNAL 1
#include "ejs.h"
/********************************** Defines ***********************************/
#ifdef __cplusplus
extern "C" {
#endif
/*
* Constants
*/
#if BLD_FEATURE_SQUEEZE
#define EJS_PARSE_INCR 256 /* Growth factor */
#define EJS_MAX_RECURSE 25 /* Sanity for maximum recursion */
#define EJS_MAX_ID 128 /* Maximum ID length */
#define EJS_OBJ_HASH_SIZE 13 /* Object hash table size */
#define EJS_SMALL_OBJ_HASH_SIZE 11 /* Small object hash size */
#define EJS_LIST_INCR 8 /* Growth increment for lists */
#else
#define EJS_PARSE_INCR 1024 /* Growth factor */
#define EJS_MAX_RECURSE 100 /* Sanity for maximum recursion */
#define EJS_MAX_ID 256 /* Maximum ID length */
#define EJS_OBJ_HASH_SIZE 29 /* Object hash table size */
#define EJS_SMALL_OBJ_HASH_SIZE 11 /* Small object hash size */
#define EJS_LIST_INCR 16 /* Growth increment for lists */
#endif
#define EJS_TOKEN_STACK 4 /* Put back token stack */
/*
* Lexical analyser tokens
*/
#define EJS_TOK_ERR -1 /* Any error */
#define EJS_TOK_LPAREN 1 /* ( */
#define EJS_TOK_RPAREN 2 /* ) */
#define EJS_TOK_IF 3 /* if */
#define EJS_TOK_ELSE 4 /* else */
#define EJS_TOK_LBRACE 5 /* { */
#define EJS_TOK_RBRACE 6 /* } */
#define EJS_TOK_LOGICAL 7 /* ||, &&, ! */
#define EJS_TOK_EXPR 8 /* +, -, /, % */
#define EJS_TOK_SEMI 9 /* ; */
#define EJS_TOK_LITERAL 10 /* literal string */
#define EJS_TOK_FUNCTION_NAME 11 /* functionName */
#define EJS_TOK_NEWLINE 12 /* newline white space */
#define EJS_TOK_ID 13 /* Identifier */
#define EJS_TOK_EOF 14 /* End of script */
#define EJS_TOK_COMMA 15 /* Comma */
#define EJS_TOK_VAR 16 /* var */
#define EJS_TOK_ASSIGNMENT 17 /* = */
#define EJS_TOK_FOR 18 /* for */
#define EJS_TOK_INC_DEC 19 /* ++, -- */
#define EJS_TOK_RETURN 20 /* return */
#define EJS_TOK_PERIOD 21 /* . */
#define EJS_TOK_LBRACKET 22 /* [ */
#define EJS_TOK_RBRACKET 23 /* ] */
#define EJS_TOK_NEW 24 /* new */
#define EJS_TOK_DELETE 25 /* delete */
#define EJS_TOK_IN 26 /* in */
#define EJS_TOK_FUNCTION 27 /* function */
#define EJS_TOK_NUMBER 28 /* Number */
/*
* Expression operators
*/
#define EJS_EXPR_LESS 1 /* < */
#define EJS_EXPR_LESSEQ 2 /* <= */
#define EJS_EXPR_GREATER 3 /* > */
#define EJS_EXPR_GREATEREQ 4 /* >= */
#define EJS_EXPR_EQ 5 /* == */
#define EJS_EXPR_NOTEQ 6 /* != */
#define EJS_EXPR_PLUS 7 /* + */
#define EJS_EXPR_MINUS 8 /* - */
#define EJS_EXPR_DIV 9 /* / */
#define EJS_EXPR_MOD 10 /* % */
#define EJS_EXPR_LSHIFT 11 /* << */
#define EJS_EXPR_RSHIFT 12 /* >> */
#define EJS_EXPR_MUL 13 /* * */
#define EJS_EXPR_ASSIGNMENT 14 /* = */
#define EJS_EXPR_INC 15 /* ++ */
#define EJS_EXPR_DEC 16 /* -- */
#define EJS_EXPR_BOOL_COMP 17 /* ! */
/*
* Conditional operators
*/
#define EJS_COND_AND 1 /* && */
#define EJS_COND_OR 2 /* || */
#define EJS_COND_NOT 3 /* ! */
/*
* States
*/
#define EJS_STATE_ERR -1 /* Error state */
#define EJS_STATE_EOF 1 /* End of file */
#define EJS_STATE_COND 2 /* Parsing a "(conditional)" stmt */
#define EJS_STATE_COND_DONE 3
#define EJS_STATE_RELEXP 4 /* Parsing a relational expr */
#define EJS_STATE_RELEXP_DONE 5
#define EJS_STATE_EXPR 6 /* Parsing an expression */
#define EJS_STATE_EXPR_DONE 7
#define EJS_STATE_STMT 8 /* Parsing General statement */
#define EJS_STATE_STMT_DONE 9
#define EJS_STATE_STMT_BLOCK_DONE 10 /* End of block "}" */
#define EJS_STATE_ARG_LIST 11 /* Function arg list */
#define EJS_STATE_ARG_LIST_DONE 12
#define EJS_STATE_DEC_LIST 16 /* Declaration list */
#define EJS_STATE_DEC_LIST_DONE 17
#define EJS_STATE_DEC 18 /* Declaration statement */
#define EJS_STATE_DEC_DONE 19
#define EJS_STATE_RET 20 /* Return statement */
#define EJS_STATE_BEGIN EJS_STATE_STMT
/*
* General parsing flags.
*/
#define EJS_FLAGS_EXE 0x1 /* Execute statements */
#define EJS_FLAGS_LOCAL 0x2 /* Get local vars only */
#define EJS_FLAGS_GLOBAL 0x4 /* Get global vars only */
#define EJS_FLAGS_CREATE 0x8 /* Create var */
#define EJS_FLAGS_ASSIGNMENT 0x10 /* In assignment stmt */
#define EJS_FLAGS_DELETE 0x20 /* Deleting a variable */
#define EJS_FLAGS_FOREACH 0x40 /* In foreach */
#define EJS_FLAGS_NEW 0x80 /* In a new stmt() */
#define EJS_FLAGS_EXIT 0x100 /* Must exit */
/*
* Putback token
*/
typedef struct EjsToken {
char *token; /* Token string */
int id; /* Token ID */
} EjsToken;
/*
* EJ evaluation block structure
*/
typedef struct ejEval {
EjsToken putBack[EJS_TOKEN_STACK]; /* Put back token stack */
int putBackIndex; /* Top of stack index */
MprStr line; /* Current line */
int lineLength; /* Current line length */
int lineNumber; /* Parse line number */
int lineColumn; /* Column in line */
MprStr script; /* Input script for parsing */
char *scriptServp; /* Next token in the script */
int scriptSize; /* Length of script */
MprStr tokbuf; /* Current token */
char *tokEndp; /* Pointer past end of token */
char *tokServp; /* Pointer to next token char */
int tokSize; /* Size of token buffer */
struct ejEval *next; /* used for backtraces */
const char *procName; /* gives name in backtrace */
} EjsInput;
/*
* Function call structure
*/
typedef struct {
MprArray *args; /* Args for function */
MprVar *fn; /* Function definition */
char *procName; /* Function name */
} EjsProc;
/*
* Per EJS structure
*/
typedef struct ej {
EjsHandle altHandle; /* alternate callback handle */
MprVar *currentObj; /* Ptr to current object */
MprVar *currentProperty; /* Ptr to current property */
EjsId eid; /* Halloc handle */
char *error; /* Error message */
int exitStatus; /* Status to exit() */
int flags; /* Flags */
MprArray *frames; /* List of variable frames */
MprVar *global; /* Global object */
EjsInput *input; /* Input evaluation block */
MprVar *local; /* Local object */
EjsHandle primaryHandle; /* primary callback handle */
EjsProc *proc; /* Current function */
MprVar result; /* Variable result */
void *thisPtr; /* C++ ptr for functions */
int tid; /* Current token id */
char *token; /* Pointer to token string */
MprVar tokenNumber; /* Parsed number */
} Ejs;
typedef int EjsBlock; /* Scope block id */
/*
* Function callback when using Alternate handles.
*/
typedef int (*EjsAltStringCFunction)(EjsHandle userHandle, EjsHandle altHandle,
int argc, char **argv);
typedef int (*EjsAltCFunction)(EjsHandle userHandle, EjsHandle altHandle,
int argc, MprVar **argv);
/******************************** Prototypes **********************************/
/*
* Ejs Lex
*/
extern int ejsLexOpenScript(Ejs* ep, char *script);
extern void ejsLexCloseScript(Ejs* ep);
extern int ejsInitInputState(EjsInput *ip);
extern void ejsLexSaveInputState(Ejs* ep, EjsInput* state);
extern void ejsLexFreeInputState(Ejs* ep, EjsInput* state);
extern void ejsLexRestoreInputState(Ejs* ep, EjsInput* state);
extern int ejsLexGetToken(Ejs* ep, int state);
extern void ejsLexPutbackToken(Ejs* ep, int tid, char *string);
/*
* Parsing
*/
extern MprVar *ejsFindObj(Ejs *ep, int state, const char *property,
int flags);
extern MprVar *ejsFindProperty(Ejs *ep, int state, MprVar *obj,
char *property, int flags);
extern int ejsGetVarCore(Ejs *ep, const char *var, MprVar **obj,
MprVar **varValue, int flags);
extern int ejsParse(Ejs *ep, int state, int flags);
extern Ejs *ejsPtr(EjsId eid);
extern void ejsSetExitStatus(int eid, int status);
extern void ejsSetFlags(int orFlags, int andFlags);
/*
* Create variable scope blocks
*/
extern EjsBlock ejsOpenBlock(EjsId eid);
extern int ejsCloseBlock(EjsId eid, EjsBlock vid);
extern int ejsEvalBlock(EjsId eid, char *script, MprVar *v, char **err);
extern int ejsDefineStandardProperties(MprVar *objVar);
/*
* Error handling
*/
extern void ejsError(Ejs *ep, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
#ifdef __cplusplus
}
#endif
#endif /* _h_EJS_INTERNAL */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim:tw=78
* vim600: sw=4 ts=4 fdm=marker
* vim<600: sw=4 ts=4
*/
|