LMMS
Loading...
Searching...
No Matches
ns-eel-int.h
Go to the documentation of this file.
1/*
2 Nullsoft Expression Evaluator Library (NS-EEL)
3 Copyright (C) 1999-2003 Nullsoft, Inc.
4
5 ns-eel-int.h: internal code definition header.
6
7 This software is provided 'as-is', without any express or implied
8 warranty. In no event will the authors be held liable for any damages
9 arising from the use of this software.
10
11 Permission is granted to anyone to use this software for any purpose,
12 including commercial applications, and to alter it and redistribute it
13 freely, subject to the following restrictions:
14
15 1. The origin of this software must not be misrepresented; you must not
16 claim that you wrote the original software. If you use this software
17 in a product, an acknowledgment in the product documentation would be
18 appreciated but is not required.
19 2. Altered source versions must be plainly marked as such, and must not be
20 misrepresented as being the original software.
21 3. This notice may not be removed or altered from any source distribution.
22*/
23
24#ifndef __NS_EELINT_H__
25#define __NS_EELINT_H__
26
27#ifdef _WIN32
28#include <windows.h>
29#else
30#include "../wdltypes.h"
31#endif
32
33#include "ns-eel.h"
34#include "ns-eel-addfuncs.h"
35
36#ifdef __cplusplus
37extern "C" {
38#endif
39
40
41enum {
42
43 // these ignore fn in opcodes, just use fntype to determine function
76
86
89
91
92
93 FUNCTYPE_FUNCTIONTYPEREC=1000, // fn is a functionType *
94 FUNCTYPE_EELFUNC, // fn is a _codeHandleFunctionRec *
95};
96
97
98
99#define YYSTYPE opcodeRec *
100
101#define NSEEL_CLOSEFACTOR 0.00001
102
103
104typedef struct opcodeRec opcodeRec;
105
107{
108 struct _codeHandleFunctionRec *next; // main linked list (only used for high level functions)
109 struct _codeHandleFunctionRec *derivedCopies; // separate linked list, head being the main function, other copies being derived versions
110
111 void *startptr; // compiled code (may be cleared + recompiled when shared)
113
114 int startptr_size; // 0=no code. -1 = needs calculation. >0 = size.
115 int startptr_base_size; // initially calculated size of root function
117
119
120 int rvMode; // RETURNVALUE_*
121 int fpStackUsage; // 0-8, usually
123
124 // local storage's first items are the parameters, then locals. Note that the opcodes will reference localstorage[] via VARPTRPTR, but
125 // the values localstorage[x] points are reallocated from context-to-context, if it is a common function.
126
127 // separately allocated list of pointers, the contents of the list should be zeroed on context changes if a common function
128 // note that when making variations on a function (context), it is shared, but since it is zeroed on context changes, it is context-local
130 EEL_F **localstorage;
131
135
138
139typedef struct _llBlock {
140 struct _llBlock *next;
143 // data follows
145
146typedef struct {
148 void *workTable; // references a chunk in blocks_data
149
150 void *code;
151 int code_size; // in case the caller wants to write it out
153
155 void *stack; // references a chunk in blocks_data, somewhere within the complete NSEEL_STACK_SIZE aligned at NSEEL_STACK_SIZE
156
157 void *ramPtr;
158
159 int workTable_size; // size (minus padding/extra space) of workTable -- only used if EEL_VALIDATE_WORKTABLE_USE set, but might be handy to have around too
162
163typedef struct
164{
165 EEL_F *value;
167 char isreg;
168 char str[1];
169} varNameRec;
170
171typedef struct
172{
173 void *ptr;
176#define EEL_GROWBUF(type) union { eel_growbuf _growbuf; type *_tval; }
177#define EEL_GROWBUF_RESIZE(gb, newsz) __growbuf_resize(&(gb)->_growbuf, (newsz)*(int)sizeof((gb)->_tval[0])) // <0 to free, does not realloc down otherwise
178#define EEL_GROWBUF_GET(gb) ((gb)->_tval)
179#define EEL_GROWBUF_GET_SIZE(gb) ((gb)->_growbuf.size/(int)sizeof((gb)->_tval[0]))
180
181typedef struct _compileContext
182{
184 const char *(*func_check)(const char *fn_name, void *user); // return error message if not permitted
186
187 EEL_GROWBUF(varNameRec *) varNameList;
190
194
195 void *scanner;
196 const char *rdbuf_start, *rdbuf, *rdbuf_end;
197
198 llBlock *tmpblocks, // used while compiling, and freed after compiling
199
200 *blocks_head_code, // used while compiling, transferred to code context (whole pages marked as executable)
201 *blocks_head_data, // used while compiling, transferred to code context
202
203 *ctx_pblocks; // persistent blocks, stores data used by varTable_Names, varTable_Values, etc.
204
205 int l_stats[4]; // source bytes, static code bytes, call code bytes, data bytes
207
209
210 // state used while generating functions
213 struct opcodeRec *directValueCache; // linked list using fn as next
214
218 int function_globalFlag; // set if restrict globals to function_localTable_Names[2]
219 // [0] is parameter+local symbols (combined space)
220 // [1] is symbols which get implied "this." if used
221 // [2] is globals permitted
222 int function_localTable_Size[3]; // for parameters only
223 char **function_localTable_Names[3]; // lists of pointers
225 const char *function_curName; // name of current function
226
227 EEL_F (*onString)(void *caller_this, struct eelStringSegmentRec *list);
228 EEL_F (*onNamedString)(void *caller_this, const char *name);
229
230 EEL_F *(*getVariable)(void *userctx, const char *name);
232
234
235 struct
236 {
241 double closefact;
243 } *ram_state; // allocated from blocks with 16 byte alignment
244
246
248}
250
251#define NSEEL_NPARAMS_FLAG_CONST 0x80000
252typedef struct functionType {
253 const char *name;
254 void *afunc;
256 void *replptrs[4];
259
260functionType *nseel_getFunctionByName(compileContext *ctx, const char *name, int *mchk); // sets mchk (if non-NULL) to how far allowed to scan forward for duplicate names
262
264opcodeRec *nseel_createCompiledValuePtr(compileContext *ctx, EEL_F *addrValue, const char *namestr);
265
270opcodeRec *nseel_createFunctionByName(compileContext *ctx, const char *name, int np, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3);
271
272// converts a generic identifier (VARPTR) opcode into either an actual variable reference (parmcnt = -1),
273// or if parmcnt >= 0, to a function call (see nseel_setCompiledFunctionCallParameters())
274opcodeRec *nseel_resolve_named_symbol(compileContext *ctx, opcodeRec *rec, int parmcnt, int *errOut);
275
276// sets parameters and calculates parameter count for opcode, and calls nseel_resolve_named_symbol() with the right
277// parameter count
279// errOut will be set if return NULL:
280// -1 if postCode set when not wanted (i.e. not while())
281// 0 if func not found,
282// 1 if function requires 2+ parameters but was given more
283// 2 if function needs more parameters
284// 4 if function requires 1 parameter but was given more
285
286
287
288struct eelStringSegmentRec *nseel_createStringSegmentRec(compileContext *ctx, const char *str, int len);
290
291EEL_F *nseel_int_register_var(compileContext *ctx, const char *name, int isReg, const char **namePtrOut);
293
295{
296 EEL_F data;
298 char name[1]; // varlen, does not include _global. prefix
300
301extern nseel_globalVarItem *nseel_globalreg_list; // if NSEEL_EEL1_COMPAT_MODE, must use NSEEL_getglobalregs() for regxx values
302
303#include "y.tab.h"
304
305// nseel_simple_tokenizer will return comments as tokens if state is non-NULL
306const char *nseel_simple_tokenizer(const char **ptr, const char *endptr, int *lenOut, int *state);
307int nseel_filter_escaped_string(char *outbuf, int outbuf_sz, const char *rdptr, size_t rdptr_size, char delim_char); // returns length used, minus NUL char
308
309opcodeRec *nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen); // tmplen=0 for nul-term
310int nseel_lookup(compileContext *ctx, opcodeRec **opOut, const char *sname);
311
312EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAlloc(EEL_F **blocks, unsigned int w);
313EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAllocGMEM(EEL_F ***blocks, unsigned int w);
314EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemSet(EEL_F **blocks,EEL_F *dest, EEL_F *v, EEL_F *lenptr);
315EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemFree(void *blocks, EEL_F *which);
316EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemTop(void *blocks, EEL_F *which);
317EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemCpy(EEL_F **blocks,EEL_F *dest, EEL_F *src, EEL_F *lenptr);
318EEL_F NSEEL_CGEN_CALL __NSEEL_RAM_Mem_SetValues(EEL_F **blocks, INT_PTR np, EEL_F **parms);
319EEL_F NSEEL_CGEN_CALL __NSEEL_RAM_Mem_GetValues(EEL_F **blocks, INT_PTR np, EEL_F **parms);
320
321extern EEL_F nseel_ramalloc_onfail; // address returned by __NSEEL_RAMAlloc et al on failure
322extern EEL_F * volatile nseel_gmembuf_default; // can free/zero this on DLL unload if needed
323
324#ifdef __cplusplus
325}
326#endif
327
328
329#endif//__NS_EELINT_H__
UINT_D64 w
Definition inflate.c:942
unsigned v[N_MAX]
Definition inflate.c:1584
EEL_F *(* nseel_int_register_var)(compileContext *ctx, const char *name, int isReg, const char **namePtrOut)
Definition eel_import.h:21
static PuglViewHint int value
Definition pugl.h:1708
static const char * name
Definition pugl.h:1582
_codeHandleFunctionRec * eel_createFunctionNamespacedInstance(compileContext *ctx, _codeHandleFunctionRec *fr, const char *nameptr)
Definition nseel-compiler.c:1519
EEL_F NSEEL_CGEN_CALL __NSEEL_RAM_Mem_GetValues(EEL_F **blocks, INT_PTR np, EEL_F **parms)
Definition nseel-ram.c:378
int nseel_filter_escaped_string(char *outbuf, int outbuf_sz, const char *rdptr, size_t rdptr_size, char delim_char)
Definition nseel-eval.c:54
struct _compileContext compileContext
@ FN_NE_EXACT
Definition ns-eel-int.h:68
@ FN_GT
Definition ns-eel-int.h:62
@ FN_GTE
Definition ns-eel-int.h:64
@ FN_ADD
Definition ns-eel-int.h:49
@ FN_SHR
Definition ns-eel-int.h:58
@ FN_POW_OP
Definition ns-eel-int.h:85
@ FN_DIVIDE
Definition ns-eel-int.h:45
@ FN_MOD_OP
Definition ns-eel-int.h:79
@ FN_MEMORY
Definition ns-eel-int.h:72
@ FN_EQ
Definition ns-eel-int.h:65
@ FN_LOOP
Definition ns-eel-int.h:88
@ FN_LT
Definition ns-eel-int.h:61
@ FN_OR_OP
Definition ns-eel-int.h:80
@ FN_UMINUS
Definition ns-eel-int.h:53
@ FN_DENORMAL_LIKELY
Definition ns-eel-int.h:47
@ FN_NE
Definition ns-eel-int.h:67
@ FN_MOD
Definition ns-eel-int.h:59
@ FN_GMEMORY
Definition ns-eel-int.h:73
@ FN_WHILE
Definition ns-eel-int.h:87
@ FN_SUB
Definition ns-eel-int.h:50
@ FN_LOGICAL_AND
Definition ns-eel-int.h:69
@ FN_XOR
Definition ns-eel-int.h:56
@ FUNCTYPE_FUNCTIONTYPEREC
Definition ns-eel-int.h:93
@ FUNCTYPE_EELFUNC
Definition ns-eel-int.h:94
@ FN_MUL_OP
Definition ns-eel-int.h:84
@ FN_MULTIPLY
Definition ns-eel-int.h:44
@ FN_DIV_OP
Definition ns-eel-int.h:83
@ FUNCTYPE_SIMPLEMAX
Definition ns-eel-int.h:90
@ FN_XOR_OP
Definition ns-eel-int.h:82
@ FN_DENORMAL_UNLIKELY
Definition ns-eel-int.h:48
@ FN_SUB_OP
Definition ns-eel-int.h:78
@ FN_AND_OP
Definition ns-eel-int.h:81
@ FN_LOGICAL_OR
Definition ns-eel-int.h:70
@ FN_ADD_OP
Definition ns-eel-int.h:77
@ FN_SHL
Definition ns-eel-int.h:57
@ FN_IF_ELSE
Definition ns-eel-int.h:71
@ FN_JOIN_STATEMENTS
Definition ns-eel-int.h:46
@ FN_AND
Definition ns-eel-int.h:51
@ FN_NOT
Definition ns-eel-int.h:54
@ FN_EQ_EXACT
Definition ns-eel-int.h:66
@ FN_NOTNOT
Definition ns-eel-int.h:55
@ FN_OR
Definition ns-eel-int.h:52
@ FN_LTE
Definition ns-eel-int.h:63
@ FN_POW
Definition ns-eel-int.h:60
@ FN_ASSIGN
Definition ns-eel-int.h:75
@ FN_NONCONST_BEGIN
Definition ns-eel-int.h:74
opcodeRec * nseel_setCompiledFunctionCallParameters(compileContext *ctx, opcodeRec *fn, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3, opcodeRec *postCode, int *errOut)
Definition nseel-compiler.c:1359
opcodeRec * nseel_createCompiledValuePtr(compileContext *ctx, EEL_F *addrValue, const char *namestr)
Definition nseel-compiler.c:907
EEL_F *NSEEL_CGEN_CALL __NSEEL_RAM_MemSet(EEL_F **blocks, EEL_F *dest, EEL_F *v, EEL_F *lenptr)
Definition nseel-ram.c:276
EEL_F *NSEEL_CGEN_CALL __NSEEL_RAM_MemFree(void *blocks, EEL_F *which)
Definition nseel-ram.c:169
EEL_F *NSEEL_CGEN_CALL __NSEEL_RAM_MemCpy(EEL_F **blocks, EEL_F *dest, EEL_F *src, EEL_F *lenptr)
Definition nseel-ram.c:192
opcodeRec * nseel_createMemoryAccess(compileContext *ctx, opcodeRec *code1, opcodeRec *code2)
Definition nseel-compiler.c:1459
EEL_F NSEEL_CGEN_CALL __NSEEL_RAM_Mem_SetValues(EEL_F **blocks, INT_PTR np, EEL_F **parms)
Definition nseel-ram.c:373
opcodeRec * nseel_createSimpleCompiledFunction(compileContext *ctx, int fn, int np, opcodeRec *code1, opcodeRec *code2)
Definition nseel-compiler.c:1472
EEL_F *volatile nseel_gmembuf_default
Definition nseel-ram.c:93
EEL_F *NSEEL_CGEN_CALL __NSEEL_RAMAlloc(EEL_F **blocks, unsigned int w)
Definition nseel-ram.c:139
functionType * nseel_getFunctionByName(compileContext *ctx, const char *name, int *mchk)
Definition nseel-compiler.c:663
opcodeRec * nseel_createMoreParametersOpcode(compileContext *ctx, opcodeRec *code1, opcodeRec *code2)
Definition nseel-compiler.c:1429
EEL_F *NSEEL_CGEN_CALL __NSEEL_RAMAllocGMEM(EEL_F ***blocks, unsigned int w)
Definition nseel-ram.c:98
struct opcodeRec opcodeRec
Definition ns-eel-int.h:104
opcodeRec * nseel_createCompiledValue(compileContext *ctx, EEL_F value)
Definition nseel-compiler.c:897
nseel_globalVarItem * nseel_globalreg_list
Definition nseel-compiler.c:179
opcodeRec * nseel_createIfElse(compileContext *ctx, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3)
Definition nseel-compiler.c:1441
EEL_F nseel_ramalloc_onfail
Definition nseel-ram.c:92
opcodeRec * nseel_translate(compileContext *ctx, const char *tmp, size_t tmplen)
Definition nseel-compiler.c:5705
const char * nseel_simple_tokenizer(const char **ptr, const char *endptr, int *lenOut, int *state)
Definition nseel-eval.c:147
struct eelStringSegmentRec * nseel_createStringSegmentRec(compileContext *ctx, const char *str, int len)
Definition nseel-compiler.c:1407
functionType * nseel_enumFunctions(compileContext *ctx, int idx)
Definition nseel-compiler.c:696
opcodeRec * nseel_createFunctionByName(compileContext *ctx, const char *name, int np, opcodeRec *code1, opcodeRec *code2, opcodeRec *code3)
Definition nseel-compiler.c:5676
int nseel_lookup(compileContext *ctx, opcodeRec **opOut, const char *sname)
opcodeRec * nseel_resolve_named_symbol(compileContext *ctx, opcodeRec *rec, int parmcnt, int *errOut)
Definition nseel-compiler.c:946
struct _llBlock llBlock
EEL_F *NSEEL_CGEN_CALL __NSEEL_RAM_MemTop(void *blocks, EEL_F *which)
Definition nseel-ram.c:179
opcodeRec * nseel_eelMakeOpcodeFromStringSegments(compileContext *ctx, struct eelStringSegmentRec *rec)
Definition nseel-compiler.c:1419
void *(* NSEEL_PPPROC)(void *data, int data_size, struct _compileContext *userfunc_data)
Definition ns-eel.h:107
#define NSEEL_CGEN_CALL
Definition ns-eel.h:44
#define NSEEL_RAM_BLOCKS
Definition ns-eel.h:234
#define NSEEL_MAX_FUNCSIG_NAME
Definition ns-eel.h:205
Definition ns-eel-int.h:107
int rvMode
Definition ns-eel-int.h:120
int tmpspace_req
Definition ns-eel-int.h:116
int usesNamespaces
Definition ns-eel-int.h:133
int localstorage_size
Definition ns-eel-int.h:129
struct _codeHandleFunctionRec * next
Definition ns-eel-int.h:108
void * startptr
Definition ns-eel-int.h:111
int startptr_base_size
Definition ns-eel-int.h:115
unsigned int parameterAsNamespaceMask
Definition ns-eel-int.h:134
struct _codeHandleFunctionRec * derivedCopies
Definition ns-eel-int.h:109
int num_params
Definition ns-eel-int.h:118
opcodeRec * opcodes
Definition ns-eel-int.h:112
int canHaveDenormalOutput
Definition ns-eel-int.h:122
int startptr_size
Definition ns-eel-int.h:114
char fname[NSEEL_MAX_FUNCSIG_NAME+1]
Definition ns-eel-int.h:136
int fpStackUsage
Definition ns-eel-int.h:121
EEL_F ** localstorage
Definition ns-eel-int.h:130
int isCommonFunction
Definition ns-eel-int.h:132
Definition ns-eel-int.h:182
const char * rdbuf
Definition ns-eel-int.h:196
llBlock * tmpblocks
Definition ns-eel-int.h:198
EEL_GROWBUF(varNameRec *) varNameList
int has_used_global_vars
Definition ns-eel-int.h:206
int gotEndOfInput
Definition ns-eel-int.h:191
WDL_UINT64 sign_mask[2]
Definition ns-eel-int.h:237
codeHandleType * tmpCodeHandle
Definition ns-eel-int.h:233
llBlock * ctx_pblocks
Definition ns-eel-int.h:203
eel_function_table * registered_func_tab
Definition ns-eel-int.h:183
_codeHandleFunctionRec * functions_common
Definition ns-eel-int.h:208
int current_compile_flags
Definition ns-eel-int.h:212
int isGeneratingCommonFunction
Definition ns-eel-int.h:216
int isSharedFunctions
Definition ns-eel-int.h:215
struct _compileContext::@171017327167146311274025377202307266252366150176 * ram_state
int needfree
Definition ns-eel-int.h:239
char ** function_localTable_Names[3]
Definition ns-eel-int.h:223
char last_error_string[256]
Definition ns-eel-int.h:193
_codeHandleFunctionRec * functions_local
Definition ns-eel-int.h:208
llBlock * blocks_head_data
Definition ns-eel-int.h:201
int function_globalFlag
Definition ns-eel-int.h:218
const char * rdbuf_end
Definition ns-eel-int.h:196
EEL_F(* onString)(void *caller_this, struct eelStringSegmentRec *list)
Definition ns-eel-int.h:227
EEL_F(* onNamedString)(void *caller_this, const char *name)
Definition ns-eel-int.h:228
void * func_check_user
Definition ns-eel-int.h:185
int function_usesNamespaces
Definition ns-eel-int.h:217
int optimizeDisableFlags
Definition ns-eel-int.h:211
void * scanner
Definition ns-eel-int.h:195
struct opcodeRec * directValueCache
Definition ns-eel-int.h:213
EEL_F * blocks[NSEEL_RAM_BLOCKS]
Definition ns-eel-int.h:242
void * gram_blocks
Definition ns-eel-int.h:245
int function_localTable_Size[3]
Definition ns-eel-int.h:222
EEL_F * varValueStore
Definition ns-eel-int.h:188
int varValueStore_left
Definition ns-eel-int.h:189
WDL_UINT64 abs_mask[2]
Definition ns-eel-int.h:238
llBlock * blocks_head_code
Definition ns-eel-int.h:200
const char * function_curName
Definition ns-eel-int.h:225
double closefact
Definition ns-eel-int.h:241
int maxblocks
Definition ns-eel-int.h:240
int l_stats[4]
Definition ns-eel-int.h:205
opcodeRec * result
Definition ns-eel-int.h:192
const char * rdbuf_start
Definition ns-eel-int.h:196
int errVar
Definition ns-eel-int.h:191
void * caller_this
Definition ns-eel-int.h:247
void * getVariable_userctx
Definition ns-eel-int.h:231
EEL_F ** function_localTable_ValuePtrs
Definition ns-eel-int.h:224
Definition ns-eel-int.h:139
struct _llBlock * next
Definition ns-eel-int.h:140
int sizeused
Definition ns-eel-int.h:141
int sizealloc
Definition ns-eel-int.h:142
Definition ns-eel-int.h:146
void * workTable
Definition ns-eel-int.h:148
void * stack
Definition ns-eel-int.h:155
llBlock * blocks_code
Definition ns-eel-int.h:147
int want_stack
Definition ns-eel-int.h:154
void * ramPtr
Definition ns-eel-int.h:157
int code_stats[4]
Definition ns-eel-int.h:152
int code_size
Definition ns-eel-int.h:151
int workTable_size
Definition ns-eel-int.h:159
int compile_flags
Definition ns-eel-int.h:160
void * code
Definition ns-eel-int.h:150
llBlock * blocks_data
Definition ns-eel-int.h:147
Definition ns-eel.h:101
Definition ns-eel-int.h:172
int size
Definition ns-eel-int.h:174
int alloc
Definition ns-eel-int.h:174
void * ptr
Definition ns-eel-int.h:173
Definition eel_import.h:27
Definition ns-eel-int.h:252
void * replptrs[4]
Definition ns-eel-int.h:256
const char * name
Definition ns-eel-int.h:253
void * afunc
Definition ns-eel-int.h:254
int nParams
Definition ns-eel-int.h:255
NSEEL_PPPROC pProc
Definition ns-eel-int.h:257
Definition ns-eel-int.h:295
struct nseel_globalVarItem * _next
Definition ns-eel-int.h:297
char name[1]
Definition ns-eel-int.h:298
EEL_F data
Definition ns-eel-int.h:296
Definition nseel-compiler.c:202
Definition ns-eel-int.h:164
EEL_F * value
Definition ns-eel-int.h:165
char str[1]
Definition ns-eel-int.h:168
char isreg
Definition ns-eel-int.h:167
int refcnt
Definition ns-eel-int.h:166
const char const char const char const char char * fn
Definition swell-functions.h:168
intptr_t INT_PTR
Definition swell-types.h:42
unsigned long long WDL_UINT64
Definition wdltypes.h:12