Initial community commit
This commit is contained in:
parent
537bcbc862
commit
fc06254474
16440 changed files with 4239995 additions and 2 deletions
1041
Src/Plugins/Visualization/vis_milk2/ns-eel2/asm-nseel-ppc-gcc.c
Normal file
1041
Src/Plugins/Visualization/vis_milk2/ns-eel2/asm-nseel-ppc-gcc.c
Normal file
File diff suppressed because it is too large
Load diff
Binary file not shown.
1566
Src/Plugins/Visualization/vis_milk2/ns-eel2/asm-nseel-x86-gcc.c
Normal file
1566
Src/Plugins/Visualization/vis_milk2/ns-eel2/asm-nseel-x86-gcc.c
Normal file
File diff suppressed because it is too large
Load diff
2463
Src/Plugins/Visualization/vis_milk2/ns-eel2/asm-nseel-x86-msvc.c
Normal file
2463
Src/Plugins/Visualization/vis_milk2/ns-eel2/asm-nseel-x86-msvc.c
Normal file
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,74 @@
|
|||
/*
|
||||
Nullsoft Expression Evaluator Library (NS-EEL)
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
ns-eel-addfuncs.h: defines macros useful for adding functions to the compiler
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef __NS_EEL_ADDFUNCS_H__
|
||||
#define __NS_EEL_ADDFUNCS_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct _compileContext;
|
||||
typedef void (*NSEEL_PPPROC)(void *data, int data_size, struct _compileContext *userfunc_data);
|
||||
|
||||
void NSEEL_PProc_RAM(void *data, int data_size, struct _compileContext *ctx);
|
||||
void NSEEL_PProc_THIS(void *data, int data_size, struct _compileContext *ctx);
|
||||
|
||||
|
||||
void _asm_generic3parm(void); // 3 double * parms, returning double *
|
||||
void _asm_generic3parm_end(void);
|
||||
void _asm_generic3parm_retd(void); // 3 double * parms, returning double
|
||||
void _asm_generic3parm_retd_end(void);
|
||||
void _asm_generic2parm(void); // 2 double * parms, returning double *
|
||||
void _asm_generic2parm_end(void);
|
||||
void _asm_generic2parm_retd(void); // 2 double * parms, returning double
|
||||
void _asm_generic2parm_retd_end(void);
|
||||
void _asm_generic1parm(void); // 1 double * parms, returning double *
|
||||
void _asm_generic1parm_end(void);
|
||||
void _asm_generic1parm_retd(void); // 1 double * parms, returning double
|
||||
void _asm_generic1parm_retd_end(void);
|
||||
|
||||
void _asm_megabuf(void);
|
||||
void _asm_megabuf_end(void);
|
||||
|
||||
|
||||
|
||||
#if EEL_F_SIZE == 4
|
||||
#define EEL_F_SSTR "4"
|
||||
#define EEL_F_SUFFIX "s"
|
||||
#else
|
||||
#define EEL_F_SSTR "8"
|
||||
#define EEL_F_SUFFIX "l"
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define NSEEL_CGEN_CALL __cdecl
|
||||
#else
|
||||
#define NSEEL_CGEN_CALL
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif//__NS_EEL_ADDFUNCS_H__
|
227
Src/Plugins/Visualization/vis_milk2/ns-eel2/ns-eel-int.h
Normal file
227
Src/Plugins/Visualization/vis_milk2/ns-eel2/ns-eel-int.h
Normal file
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
Nullsoft Expression Evaluator Library (NS-EEL)
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
ns-eel-int.h: internal code definition header.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#ifndef __NS_EELINT_H__
|
||||
#define __NS_EELINT_H__
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include "../wdltypes.h"
|
||||
#endif
|
||||
|
||||
#include "ns-eel.h"
|
||||
#include "ns-eel-addfuncs.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define FN_ASSIGN 0
|
||||
#define FN_MULTIPLY 1
|
||||
#define FN_DIVIDE 2
|
||||
#define FN_MODULO 3
|
||||
#define FN_ADD 4
|
||||
#define FN_SUB 5
|
||||
#define FN_AND 6
|
||||
#define FN_OR 7
|
||||
#define FN_UMINUS 8
|
||||
#define FN_UPLUS 9
|
||||
|
||||
#define MATH_SIMPLE 0
|
||||
#define MATH_FN 1
|
||||
|
||||
#define YYSTYPE INT_PTR
|
||||
|
||||
#define NSEEL_CLOSEFACTOR 0.00001
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int srcByteCount;
|
||||
int destByteCount;
|
||||
} lineRecItem;
|
||||
|
||||
typedef struct _compileContext
|
||||
{
|
||||
EEL_F **varTable_Values;
|
||||
char **varTable_Names;
|
||||
int varTable_numBlocks;
|
||||
|
||||
int errVar;
|
||||
int colCount;
|
||||
INT_PTR result;
|
||||
char last_error_string[256];
|
||||
YYSTYPE yylval;
|
||||
int yychar; /* the lookahead symbol */
|
||||
int yynerrs; /* number of parse errors so far */
|
||||
char yytext[256];
|
||||
char lastVar[256];
|
||||
|
||||
char *llsave[16]; /* Look ahead buffer */
|
||||
char llbuf[100]; /* work buffer */
|
||||
char *llp1;// = &llbuf[0]; /* pointer to next avail. in token */
|
||||
char *llp2;// = &llbuf[0]; /* pointer to end of lookahead */
|
||||
char *llend;// = &llbuf[0]; /* pointer to end of token */
|
||||
char *llebuf;// = &llbuf[sizeof llbuf];
|
||||
int lleof;
|
||||
int yyline;// = 0;
|
||||
|
||||
void *tmpblocks_head,*blocks_head;
|
||||
int computTableTop; // make it abort on potential overflow =)
|
||||
int l_stats[4]; // source bytes, static code bytes, call code bytes, data bytes
|
||||
|
||||
lineRecItem *compileLineRecs;
|
||||
int compileLineRecs_size;
|
||||
int compileLineRecs_alloc;
|
||||
|
||||
void *ram_blocks; // this needs to be immediately followed by
|
||||
int ram_needfree;
|
||||
|
||||
void *gram_blocks;
|
||||
|
||||
void *caller_this;
|
||||
}
|
||||
compileContext;
|
||||
|
||||
#define NSEEL_VARS_PER_BLOCK 64
|
||||
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void *afunc;
|
||||
void *func_e;
|
||||
int nParams;
|
||||
void *replptrs[4];
|
||||
NSEEL_PPPROC pProc;
|
||||
} functionType;
|
||||
|
||||
|
||||
extern functionType *nseel_getFunctionFromTable(int idx);
|
||||
|
||||
INT_PTR nseel_createCompiledValue(compileContext *ctx, EEL_F value, EEL_F *addrValue);
|
||||
INT_PTR nseel_createCompiledFunction1(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code);
|
||||
INT_PTR nseel_createCompiledFunction2(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code1, INT_PTR code2);
|
||||
INT_PTR nseel_createCompiledFunction3(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code1, INT_PTR code2, INT_PTR code3);
|
||||
|
||||
extern EEL_F nseel_globalregs[100];
|
||||
|
||||
void nseel_resetVars(compileContext *ctx);
|
||||
EEL_F *nseel_getVarPtr(compileContext *ctx, char *varName);
|
||||
EEL_F *nseel_registerVar(compileContext *ctx, char *varName);
|
||||
|
||||
INT_PTR *EEL_GLUE_set_immediate(void *_p, void *newv);
|
||||
|
||||
// other shat
|
||||
|
||||
|
||||
|
||||
INT_PTR nseel_setVar(compileContext *ctx, INT_PTR varNum);
|
||||
INT_PTR nseel_getVar(compileContext *ctx, INT_PTR varNum);
|
||||
void *nseel_compileExpression(compileContext *ctx, char *txt);
|
||||
|
||||
#define VALUE 258
|
||||
#define IDENTIFIER 259
|
||||
#define FUNCTION1 260
|
||||
#define FUNCTION2 261
|
||||
#define FUNCTION3 262
|
||||
#define UMINUS 263
|
||||
#define UPLUS 264
|
||||
|
||||
INT_PTR nseel_translate(compileContext *ctx, int type);
|
||||
void nseel_count(compileContext *ctx);
|
||||
void nseel_setLastVar(compileContext *ctx);
|
||||
INT_PTR nseel_lookup(compileContext *ctx, int *typeOfObject);
|
||||
int nseel_yyerror(compileContext *ctx);
|
||||
int nseel_yylex(compileContext *ctx, char **exp);
|
||||
int nseel_yyparse(compileContext *ctx, char *exp);
|
||||
void nseel_llinit(compileContext *ctx);
|
||||
int nseel_gettoken(compileContext *ctx, char *lltb, int lltbsiz);
|
||||
|
||||
struct lextab {
|
||||
int llendst; /* Last state number */
|
||||
char *lldefault; /* Default state table */
|
||||
char *llnext; /* Next state table */
|
||||
char *llcheck; /* Check table */
|
||||
int *llbase; /* Base table */
|
||||
int llnxtmax; /* Last in next table */
|
||||
int (*llmove)(); /* Move between states */
|
||||
char *llfinal; /* Final state descriptions */
|
||||
int (*llactr)(); /* Action routine */
|
||||
int *lllook; /* Look ahead vector if != NULL */
|
||||
char *llign; /* Ignore char vec if != NULL */
|
||||
char *llbrk; /* Break char vec if != NULL */
|
||||
char *llill; /* Illegal char vec if != NULL */
|
||||
};
|
||||
extern struct lextab nseel_lextab;
|
||||
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAlloc(EEL_F ***blocks, int w);
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAllocGMEM(EEL_F ***blocks, int w);
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemSet(EEL_F ***blocks,EEL_F *dest, EEL_F *v, EEL_F *lenptr);
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemFree(EEL_F ***blocks, EEL_F *which);
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemCpy(EEL_F ***blocks,EEL_F *dest, EEL_F *src, EEL_F *lenptr);
|
||||
|
||||
|
||||
|
||||
#ifndef max
|
||||
#define max(x,y) ((x)<(y)?(y):(x))
|
||||
#define min(x,y) ((x)<(y)?(x):(y))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#ifdef __ppc__
|
||||
|
||||
#define EEL_F2int(x) ((int)(x))
|
||||
|
||||
#elif defined (_WIN64)
|
||||
|
||||
// todo: AMD64 version?
|
||||
#define EEL_F2int(x) ((int)(x))
|
||||
|
||||
#elif defined(_MSC_VER)
|
||||
|
||||
static __inline int EEL_F2int(EEL_F d)
|
||||
{
|
||||
int tmp;
|
||||
__asm {
|
||||
fld d
|
||||
fistp tmp
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static inline int EEL_F2int(EEL_F d)
|
||||
{
|
||||
int tmp;
|
||||
__asm__ __volatile__ ("fistpl %0" : "=m" (tmp) : "t" (d) : "st") ;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif//__NS_EELINT_H__
|
155
Src/Plugins/Visualization/vis_milk2/ns-eel2/ns-eel.h
Normal file
155
Src/Plugins/Visualization/vis_milk2/ns-eel2/ns-eel.h
Normal file
|
@ -0,0 +1,155 @@
|
|||
/*
|
||||
Nullsoft Expression Evaluator Library (NS-EEL)
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
ns-eel.h: main application interface header
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __NS_EEL_H__
|
||||
#define __NS_EEL_H__
|
||||
|
||||
// put standard includes here
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define strcasecmp stricmp
|
||||
#define strncasecmp _strnicmp
|
||||
#endif
|
||||
|
||||
#ifndef EEL_F_SIZE
|
||||
#define EEL_F_SIZE 8
|
||||
#endif
|
||||
|
||||
#if EEL_F_SIZE == 4
|
||||
typedef float EEL_F;
|
||||
#else
|
||||
typedef double EEL_F;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// host should implement these (can be empty stub functions if no VM will execute code in multiple threads at once)
|
||||
|
||||
// implement if you will be running the code in same VM from multiple threads,
|
||||
// or VMs that have the same GRAM pointer from different threads, or multiple
|
||||
// VMs that have a NULL GRAM pointer from multiple threads.
|
||||
// if you give each VM it's own unique GRAM and only run each VM in one thread, then you can leave it blank.
|
||||
|
||||
// or if you're daring....
|
||||
|
||||
void NSEEL_HOSTSTUB_EnterMutex();
|
||||
void NSEEL_HOSTSTUB_LeaveMutex();
|
||||
|
||||
|
||||
int NSEEL_init(); // returns 0 on success. clears any added functions as well
|
||||
|
||||
#define NSEEL_addfunction(name,nparms,code,len) NSEEL_addfunctionex((name),(nparms),(code),(len),0,0)
|
||||
#define NSEEL_addfunctionex(name,nparms,code,len,pproc,fptr) NSEEL_addfunctionex2((name),(nparms),(code),(len),(pproc),(fptr),0)
|
||||
void NSEEL_addfunctionex2(const char *name, int nparms, char *code_startaddr, int code_len, void *pproc, void *fptr, void *fptr2);
|
||||
|
||||
void NSEEL_quit();
|
||||
|
||||
int *NSEEL_getstats(); // returns a pointer to 5 ints... source bytes, static code bytes, call code bytes, data bytes, number of code handles
|
||||
EEL_F *NSEEL_getglobalregs();
|
||||
|
||||
typedef void *NSEEL_VMCTX;
|
||||
typedef void *NSEEL_CODEHANDLE;
|
||||
|
||||
NSEEL_VMCTX NSEEL_VM_alloc(); // return a handle
|
||||
void NSEEL_VM_free(NSEEL_VMCTX ctx); // free when done with a VM and ALL of its code have been freed, as well
|
||||
|
||||
void NSEEL_VM_enumallvars(NSEEL_VMCTX ctx, int (*func)(const char *name, EEL_F *val, void *ctx), void *userctx); // return false from func to stop
|
||||
void NSEEL_VM_resetvars(NSEEL_VMCTX ctx); // clears all vars to 0.0.
|
||||
|
||||
EEL_F *NSEEL_VM_regvar(NSEEL_VMCTX ctx, const char *name); // register a variable (before compilation)
|
||||
|
||||
void NSEEL_VM_freeRAM(NSEEL_VMCTX ctx); // clears and frees all (VM) RAM used
|
||||
void NSEEL_VM_freeRAMIfCodeRequested(NSEEL_VMCTX); // call after code to free the script-requested memory
|
||||
int NSEEL_VM_wantfreeRAM(NSEEL_VMCTX ctx); // want NSEEL_VM_freeRAMIfCodeRequested?
|
||||
|
||||
// if you set this, it uses a local GMEM context.
|
||||
// Must be set before compilation.
|
||||
// void *p=NULL;
|
||||
// NSEEL_VM_SetGRAM(ctx,&p);
|
||||
// .. do stuff
|
||||
// NSEEL_VM_FreeGRAM(&p);
|
||||
void NSEEL_VM_SetGRAM(NSEEL_VMCTX ctx, void **gram);
|
||||
void NSEEL_VM_FreeGRAM(void **ufd); // frees a gmem context.
|
||||
void NSEEL_VM_SetCustomFuncThis(NSEEL_VMCTX ctx, void *thisptr);
|
||||
|
||||
|
||||
// note that you shouldnt pass a C string directly, since it may need to
|
||||
// fudge with the string during the compilation (it will always restore it to the
|
||||
// original value though).
|
||||
#ifdef __cplusplus
|
||||
NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX ctx, char *code, int lineoffs=0);
|
||||
#else
|
||||
NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX ctx, char *code, int lineoffs);
|
||||
#endif
|
||||
|
||||
char *NSEEL_code_getcodeerror(NSEEL_VMCTX ctx);
|
||||
void NSEEL_code_execute(NSEEL_CODEHANDLE code);
|
||||
void NSEEL_code_free(NSEEL_CODEHANDLE code);
|
||||
int *NSEEL_code_getstats(NSEEL_CODEHANDLE code); // 4 ints...source bytes, static code bytes, call code bytes, data bytes
|
||||
|
||||
|
||||
// global memory control/view
|
||||
extern unsigned int NSEEL_RAM_limitmem; // if nonzero, memory limit for user data, in bytes
|
||||
extern unsigned int NSEEL_RAM_memused;
|
||||
extern int NSEEL_RAM_memused_errors;
|
||||
|
||||
|
||||
|
||||
// configuration:
|
||||
|
||||
#define NSEEL_MAX_VARIABLE_NAMELEN 16
|
||||
// define this to override the max variable length (default is 16 bytes)
|
||||
|
||||
//#define NSEEL_MAX_TEMPSPACE_ENTRIES 2048
|
||||
// define this to override the maximum working space in 8 byte units.
|
||||
// 2048 is the default, and is way more than enough for most applications
|
||||
// but in theory you might be able to come up with an expression big enough? maybe?
|
||||
|
||||
|
||||
// maximum loop length
|
||||
#define NSEEL_LOOPFUNC_SUPPORT_MAXLEN 1048576 // scary, we can do a million entries. probably will never want to, though.
|
||||
#define NSEEL_LOOPFUNC_SUPPORT_MAXLEN_STR "1048576"
|
||||
|
||||
|
||||
|
||||
// when a VM ctx doesn't have a GRAM context set, make the global one this big
|
||||
#define NSEEL_SHARED_GRAM_SIZE (1<<20)
|
||||
|
||||
// 128*65536 = ~8million entries. (64MB RAM used)
|
||||
#define NSEEL_RAM_BLOCKS 128
|
||||
#define NSEEL_RAM_ITEMSPERBLOCK 65536
|
||||
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif//__NS_EEL_H__
|
553
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-caltab.c
Normal file
553
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-caltab.c
Normal file
|
@ -0,0 +1,553 @@
|
|||
/*
|
||||
Expression Evaluator Library (NS-EEL) v2
|
||||
Copyright (C) 2004-2008 Cockos Incorporated
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
nseel-caltab.c
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ns-eel-int.h"
|
||||
|
||||
#define VALUE 258
|
||||
#define IDENTIFIER 259
|
||||
#define FUNCTION1 260
|
||||
#define FUNCTION2 261
|
||||
#define FUNCTION3 262
|
||||
#define UMINUS 263
|
||||
#define UPLUS 264
|
||||
|
||||
#define YYERROR(x) nseel_yyerror(ctx)
|
||||
|
||||
#define YYFINAL 51
|
||||
#define YYFLAG -32768
|
||||
#define YYNTBASE 21
|
||||
|
||||
#define YYTRANSLATE(x) ((unsigned)(x) <= 264 ? yytranslate[x] : 26)
|
||||
|
||||
static const char yytranslate[] = { 0,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 14, 9, 2, 18,
|
||||
19, 12, 10, 20, 11, 2, 13, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
17, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 8, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
||||
2, 2, 2, 2, 2, 1, 2, 3, 4, 5,
|
||||
6, 7, 15, 16
|
||||
};
|
||||
|
||||
|
||||
static const short yyr1[] = { 0,
|
||||
21, 21, 22, 23, 23, 23, 24, 24, 24, 24,
|
||||
24, 24, 24, 24, 24, 24, 24, 25, 25, 25
|
||||
};
|
||||
|
||||
static const short yyr2[] = { 0,
|
||||
1, 3, 1, 1, 1, 3, 1, 3, 3, 3,
|
||||
3, 3, 3, 3, 2, 2, 1, 4, 6, 8
|
||||
};
|
||||
|
||||
static const short yydefact[] = { 0,
|
||||
3, 4, 0, 0, 0, 0, 0, 0, 5, 7,
|
||||
1, 17, 0, 0, 0, 0, 4, 16, 15, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 2, 0, 0,
|
||||
0, 6, 14, 13, 11, 12, 8, 9, 10, 18,
|
||||
0, 0, 0, 0, 19, 0, 0, 20, 0, 0,
|
||||
0
|
||||
};
|
||||
|
||||
static const short yydefgoto[] = { 49,
|
||||
9, 10, 11, 12
|
||||
};
|
||||
|
||||
static const short yypact[] = { 19,
|
||||
-32768, -11, -7, -5, -4, 38, 38, 38,-32768,-32768,
|
||||
136,-32768, 38, 38, 38, 38,-32768,-32768,-32768, 88,
|
||||
38, 38, 38, 38, 38, 38, 38, 136, 100, 49,
|
||||
62,-32768, 41, 54, -9, -9,-32768,-32768,-32768,-32768,
|
||||
38, 38, 112, 75,-32768, 38, 124,-32768, 12, 27,
|
||||
-32768
|
||||
};
|
||||
|
||||
static const short yypgoto[] = {-32768,
|
||||
-32768,-32768, -6,-32768
|
||||
};
|
||||
|
||||
|
||||
#define YYLAST 150
|
||||
|
||||
|
||||
static const short yytable[] = { 18,
|
||||
19, 20, 25, 26, 27, 13, 28, 29, 30, 31,
|
||||
14, 50, 15, 16, 33, 34, 35, 36, 37, 38,
|
||||
39, 1, 2, 3, 4, 5, 51, 0, 6, 7,
|
||||
0, 0, 0, 0, 43, 44, 8, 0, 0, 47,
|
||||
1, 17, 3, 4, 5, 0, 0, 6, 7, 22,
|
||||
23, 24, 25, 26, 27, 8, 21, 22, 23, 24,
|
||||
25, 26, 27, 23, 24, 25, 26, 27, 41, 21,
|
||||
22, 23, 24, 25, 26, 27, 0, 0, 0, 0,
|
||||
0, 42, 21, 22, 23, 24, 25, 26, 27, 0,
|
||||
0, 0, 0, 0, 46, 21, 22, 23, 24, 25,
|
||||
26, 27, 0, 0, 0, 0, 32, 21, 22, 23,
|
||||
24, 25, 26, 27, 0, 0, 0, 0, 40, 21,
|
||||
22, 23, 24, 25, 26, 27, 0, 0, 0, 0,
|
||||
45, 21, 22, 23, 24, 25, 26, 27, 0, 0,
|
||||
0, 0, 48, 21, 22, 23, 24, 25, 26, 27
|
||||
};
|
||||
|
||||
static const short yycheck[] = { 6,
|
||||
7, 8, 12, 13, 14, 17, 13, 14, 15, 16,
|
||||
18, 0, 18, 18, 21, 22, 23, 24, 25, 26,
|
||||
27, 3, 4, 5, 6, 7, 0, -1, 10, 11,
|
||||
-1, -1, -1, -1, 41, 42, 18, -1, -1, 46,
|
||||
3, 4, 5, 6, 7, -1, -1, 10, 11, 9,
|
||||
10, 11, 12, 13, 14, 18, 8, 9, 10, 11,
|
||||
12, 13, 14, 10, 11, 12, 13, 14, 20, 8,
|
||||
9, 10, 11, 12, 13, 14, -1, -1, -1, -1,
|
||||
-1, 20, 8, 9, 10, 11, 12, 13, 14, -1,
|
||||
-1, -1, -1, -1, 20, 8, 9, 10, 11, 12,
|
||||
13, 14, -1, -1, -1, -1, 19, 8, 9, 10,
|
||||
11, 12, 13, 14, -1, -1, -1, -1, 19, 8,
|
||||
9, 10, 11, 12, 13, 14, -1, -1, -1, -1,
|
||||
19, 8, 9, 10, 11, 12, 13, 14, -1, -1,
|
||||
-1, -1, 19, 8, 9, 10, 11, 12, 13, 14
|
||||
};
|
||||
|
||||
#define yyerrok (yyerrstatus = 0)
|
||||
#define yyclearin (ctx->yychar = YYEMPTY)
|
||||
#define YYEMPTY -2
|
||||
#define YYEOF 0
|
||||
#define YYACCEPT return(0)
|
||||
#define YYABORT return(1)
|
||||
|
||||
#define YYTERROR 1
|
||||
#define YYERRCODE 256
|
||||
|
||||
#define YYLEX nseel_yylex(ctx,&exp)
|
||||
|
||||
/* If nonreentrant, generate the variables here */
|
||||
|
||||
/* YYINITDEPTH indicates the initial size of the parser's stacks */
|
||||
|
||||
#define YYINITDEPTH 5000
|
||||
#define YYMAXDEPTH 5000
|
||||
|
||||
/* This is the most reliable way to avoid incompatibilities
|
||||
in available built-in functions on various systems. */
|
||||
#define __yy_bcopy(from,to,count) memcpy(to,from,(count)>0?(count):0)
|
||||
|
||||
//#ln 131 "bison.simple"
|
||||
int nseel_yyparse(compileContext *ctx, char *exp)
|
||||
{
|
||||
register int yystate;
|
||||
register int yyn;
|
||||
register short *yyssp;
|
||||
register YYSTYPE *yyvsp;
|
||||
int yyerrstatus; /* number of tokens to shift before error messages enabled */
|
||||
int yychar1; /* lookahead token as an internal (translated) token number */
|
||||
|
||||
short yyssa[YYINITDEPTH]; /* the state stack */
|
||||
YYSTYPE yyvsa[YYINITDEPTH]; /* the semantic value stack */
|
||||
|
||||
short *yyss = yyssa; /* refer to the stacks thru separate pointers */
|
||||
YYSTYPE *yyvs = yyvsa; /* to allow yyoverflow to reallocate them elsewhere */
|
||||
|
||||
int yystacksize = YYINITDEPTH;
|
||||
|
||||
YYSTYPE yyval; /* the variable used to return */
|
||||
/* semantic values from the action */
|
||||
/* routines */
|
||||
|
||||
int yylen;
|
||||
|
||||
ctx->yylval = 0;
|
||||
yystate = 0;
|
||||
yyerrstatus = 0;
|
||||
ctx->yynerrs = 0;
|
||||
ctx->yychar = YYEMPTY; /* Cause a token to be read. */
|
||||
|
||||
/* Initialize stack pointers.
|
||||
Waste one element of value and location stack
|
||||
so that they stay on the same level as the state stack. */
|
||||
|
||||
yyssp = yyss - 1;
|
||||
yyvsp = yyvs;
|
||||
|
||||
/* Push a new state, which is found in yystate . */
|
||||
/* In all cases, when you get here, the value and location stacks
|
||||
have just been pushed. so pushing a state here evens the stacks. */
|
||||
yynewstate:
|
||||
|
||||
*++yyssp = yystate;
|
||||
|
||||
if (yyssp >= yyss + yystacksize - 1)
|
||||
{
|
||||
/* Give user a chance to reallocate the stack */
|
||||
/* Use copies of these so that the &'s don't force the real ones into memory. */
|
||||
// YYSTYPE *yyvs1 = yyvs;
|
||||
// short *yyss1 = yyss;
|
||||
|
||||
/* Get the current used size of the three stacks, in elements. */
|
||||
int size = yyssp - yyss + 1;
|
||||
|
||||
if (yystacksize >= YYMAXDEPTH)
|
||||
{
|
||||
YYERROR("internal error: parser stack overflow");
|
||||
return 2;
|
||||
}
|
||||
|
||||
yyssp = yyss + size - 1;
|
||||
yyvsp = yyvs + size - 1;
|
||||
|
||||
|
||||
if (yyssp >= yyss + yystacksize - 1) YYABORT;
|
||||
}
|
||||
|
||||
|
||||
// yybackup:
|
||||
|
||||
/* Do appropriate processing given the current state. */
|
||||
/* Read a lookahead token if we need one and don't already have one. */
|
||||
/* yyresume: */
|
||||
|
||||
/* First try to decide what to do without reference to lookahead token. */
|
||||
|
||||
yyn = yypact[yystate];
|
||||
if (yyn == YYFLAG)
|
||||
goto yydefault;
|
||||
|
||||
/* Not known => get a lookahead token if don't already have one. */
|
||||
|
||||
/* yychar is either YYEMPTY or YYEOF
|
||||
or a valid token in external form. */
|
||||
|
||||
if (ctx->yychar == YYEMPTY)
|
||||
{
|
||||
// yyStackSize = yyssp - (yyss - 1);
|
||||
ctx->yychar = YYLEX;
|
||||
}
|
||||
|
||||
/* Convert token to internal form (in yychar1) for indexing tables with */
|
||||
|
||||
if (ctx->yychar <= 0) /* This means end of input. */
|
||||
{
|
||||
yychar1 = 0;
|
||||
ctx->yychar = YYEOF; /* Don't call YYLEX any more */
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
yychar1 = YYTRANSLATE(ctx->yychar);
|
||||
|
||||
}
|
||||
|
||||
yyn += yychar1;
|
||||
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != yychar1)
|
||||
goto yydefault;
|
||||
|
||||
yyn = yytable[yyn];
|
||||
|
||||
/* yyn is what to do for this token type in this state.
|
||||
Negative => reduce, -yyn is rule number.
|
||||
Positive => shift, yyn is new state.
|
||||
New state is final state => don't bother to shift,
|
||||
just return success.
|
||||
0, or most negative number => error. */
|
||||
|
||||
if (yyn < 0)
|
||||
{
|
||||
if (yyn == YYFLAG)
|
||||
goto yyerrlab;
|
||||
yyn = -yyn;
|
||||
goto yyreduce;
|
||||
}
|
||||
else if (yyn == 0)
|
||||
goto yyerrlab;
|
||||
|
||||
if (yyn == YYFINAL)
|
||||
YYACCEPT;
|
||||
|
||||
/* Shift the lookahead token. */
|
||||
|
||||
|
||||
/* Discard the token being shifted unless it is eof. */
|
||||
if (ctx->yychar != YYEOF)
|
||||
ctx->yychar = YYEMPTY;
|
||||
|
||||
*++yyvsp = ctx->yylval;
|
||||
|
||||
/* count tokens shifted since error; after three, turn off error status. */
|
||||
if (yyerrstatus) yyerrstatus--;
|
||||
|
||||
yystate = yyn;
|
||||
goto yynewstate;
|
||||
|
||||
/* Do the default action for the current state. */
|
||||
yydefault:
|
||||
|
||||
yyn = yydefact[yystate];
|
||||
if (yyn == 0)
|
||||
goto yyerrlab;
|
||||
|
||||
/* Do a reduction. yyn is the number of a rule to reduce with. */
|
||||
yyreduce:
|
||||
yylen = yyr2[yyn];
|
||||
yyval = yyvsp[1-yylen]; /* implement default value of the action */
|
||||
|
||||
|
||||
switch (yyn) {
|
||||
|
||||
case 1:
|
||||
//#ln 32 "cal.y"
|
||||
{ yyval = yyvsp[0]; ctx->result = yyvsp[0]; ;
|
||||
break;}
|
||||
case 2:
|
||||
//#ln 34 "cal.y"
|
||||
{ {
|
||||
YYSTYPE i = nseel_setVar(ctx,yyvsp[-2]);
|
||||
YYSTYPE v=nseel_getVar(ctx,i);
|
||||
|
||||
yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_ASSIGN, v, yyvsp[0]);
|
||||
ctx->result = yyval;
|
||||
}
|
||||
;
|
||||
break;}
|
||||
case 3:
|
||||
//#ln 50 "cal.y"
|
||||
{ yyval = yyvsp[0] ;
|
||||
break;}
|
||||
case 4:
|
||||
//#ln 55 "cal.y"
|
||||
{ yyval = nseel_getVar(ctx,yyvsp[0]);;
|
||||
break;}
|
||||
case 5:
|
||||
//#ln 57 "cal.y"
|
||||
{ yyval = yyvsp[0];;
|
||||
break;}
|
||||
case 6:
|
||||
//#ln 59 "cal.y"
|
||||
{ yyval = yyvsp[-1];;
|
||||
break;}
|
||||
case 7:
|
||||
//#ln 64 "cal.y"
|
||||
{ yyval = yyvsp[0]; ;
|
||||
break;}
|
||||
case 8:
|
||||
//#ln 66 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_MULTIPLY, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 9:
|
||||
//#ln 72 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_DIVIDE, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 10:
|
||||
//#ln 78 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_MODULO, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 11:
|
||||
//#ln 84 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_ADD, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 12:
|
||||
//#ln 90 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_SUB, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 13:
|
||||
//#ln 96 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_AND, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 14:
|
||||
//#ln 102 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_SIMPLE, FN_OR, yyvsp[-2], yyvsp[0]);
|
||||
break;}
|
||||
case 15:
|
||||
//#ln 108 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction1(ctx,MATH_SIMPLE, FN_UMINUS, yyvsp[0]);
|
||||
break;}
|
||||
case 16:
|
||||
//#ln 114 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction1(ctx,MATH_SIMPLE, FN_UPLUS, yyvsp[0]);
|
||||
break;}
|
||||
case 17:
|
||||
//#ln 120 "cal.y"
|
||||
{ yyval = yyvsp[0];
|
||||
break;}
|
||||
case 18:
|
||||
//#ln 125 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction1(ctx,MATH_FN, yyvsp[-3], yyvsp[-1]);
|
||||
break;}
|
||||
case 19:
|
||||
//#ln 131 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction2(ctx,MATH_FN, yyvsp[-5], yyvsp[-3], yyvsp[-1]);
|
||||
break;}
|
||||
case 20:
|
||||
//#ln 137 "cal.y"
|
||||
{ yyval = nseel_createCompiledFunction3(ctx,MATH_FN, yyvsp[-7], yyvsp[-5], yyvsp[-3], yyvsp[-1]);
|
||||
break;}
|
||||
}
|
||||
/* the action file gets copied in in place of this dollarsign */
|
||||
//#ln 362 "bison.simple"
|
||||
|
||||
yyvsp -= yylen;
|
||||
yyssp -= yylen;
|
||||
|
||||
*++yyvsp = yyval;
|
||||
|
||||
|
||||
/* Now "shift" the result of the reduction.
|
||||
Determine what state that goes to,
|
||||
based on the state we popped back to
|
||||
and the rule number reduced by. */
|
||||
|
||||
yyn = yyr1[yyn];
|
||||
|
||||
yystate = yypgoto[yyn - YYNTBASE] + *yyssp;
|
||||
if (yystate >= 0 && yystate <= YYLAST && yycheck[yystate] == *yyssp)
|
||||
yystate = yytable[yystate];
|
||||
else
|
||||
yystate = yydefgoto[yyn - YYNTBASE];
|
||||
|
||||
goto yynewstate;
|
||||
|
||||
yyerrlab: /* here on detecting error */
|
||||
|
||||
if (! yyerrstatus)
|
||||
/* If not already recovering from an error, report this error. */
|
||||
{
|
||||
++ctx->yynerrs;
|
||||
|
||||
#ifdef YYERROR_VERBOSE
|
||||
yyn = yypact[yystate];
|
||||
|
||||
if (yyn > YYFLAG && yyn < YYLAST)
|
||||
{
|
||||
int size = 0;
|
||||
char *msg;
|
||||
int x, count;
|
||||
|
||||
count = 0;
|
||||
for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
|
||||
if (yycheck[x + yyn] == x)
|
||||
size += strlen(yytname[x]) + 15, count++;
|
||||
#error this should not compile
|
||||
msg = (char *) xmalloc(size + 15);
|
||||
strcpy(msg, "syntax error");
|
||||
|
||||
if (count < 5)
|
||||
{
|
||||
count = 0;
|
||||
for (x = 0; x < (sizeof(yytname) / sizeof(char *)); x++)
|
||||
if (yycheck[x + yyn] == x)
|
||||
{
|
||||
strcat(msg, count == 0 ? ", expecting `" : " or `");
|
||||
strcat(msg, yytname[x]);
|
||||
strcat(msg, "'");
|
||||
count++;
|
||||
}
|
||||
}
|
||||
YYERROR(msg);
|
||||
free(msg);
|
||||
}
|
||||
else
|
||||
#endif /* YYERROR_VERBOSE */
|
||||
YYERROR("syntax error");
|
||||
}
|
||||
|
||||
//yyerrlab1: /* here on error raised explicitly by an action */
|
||||
|
||||
if (yyerrstatus == 3)
|
||||
{
|
||||
/* if just tried and failed to reuse lookahead token after an error, discard it. */
|
||||
|
||||
/* return failure if at end of input */
|
||||
if (ctx->yychar == YYEOF) YYABORT;
|
||||
|
||||
ctx->yychar = YYEMPTY;
|
||||
}
|
||||
|
||||
/* Else will try to reuse lookahead token
|
||||
after shifting the error token. */
|
||||
|
||||
yyerrstatus = 3; /* Each real token shifted decrements this */
|
||||
|
||||
goto yyerrhandle;
|
||||
|
||||
yyerrdefault: /* current state does not do anything special for the error token. */
|
||||
|
||||
#if 0
|
||||
/* This is wrong; only states that explicitly want error tokens
|
||||
should shift them. */
|
||||
yyn = yydefact[yystate]; /* If its default is to accept any token, ok. Otherwise pop it.*/
|
||||
if (yyn) goto yydefault;
|
||||
#endif
|
||||
|
||||
yyerrpop: /* pop the current state because it cannot handle the error token */
|
||||
|
||||
if (yyssp == yyss) YYABORT;
|
||||
yyvsp--;
|
||||
yystate = *--yyssp;
|
||||
|
||||
|
||||
yyerrhandle:
|
||||
|
||||
yyn = yypact[yystate];
|
||||
if (yyn == YYFLAG)
|
||||
goto yyerrdefault;
|
||||
|
||||
yyn += YYTERROR;
|
||||
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
|
||||
goto yyerrdefault;
|
||||
|
||||
yyn = yytable[yyn];
|
||||
if (yyn < 0)
|
||||
{
|
||||
if (yyn == YYFLAG)
|
||||
goto yyerrpop;
|
||||
yyn = -yyn;
|
||||
goto yyreduce;
|
||||
}
|
||||
else if (yyn == 0)
|
||||
goto yyerrpop;
|
||||
|
||||
if (yyn == YYFINAL)
|
||||
YYACCEPT;
|
||||
|
||||
*++yyvsp = ctx->yylval;
|
||||
|
||||
yystate = yyn;
|
||||
goto yynewstate;
|
||||
}
|
131
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-cfunc.c
Normal file
131
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-cfunc.c
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*
|
||||
Expression Evaluator Library (NS-EEL) v2
|
||||
Copyright (C) 2004-2008 Cockos Incorporated
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
nseel-cfunc.c: assembly/C implementation of operator/function templates
|
||||
This file should be ideally compiled with optimizations towards "minimize size"
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "ns-eel-int.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
// these are used by our assembly code
|
||||
|
||||
|
||||
#define N 624
|
||||
#define M 397
|
||||
#define MATRIX_A 0x9908b0dfUL /* constant vector a */
|
||||
#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
|
||||
#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
|
||||
|
||||
static unsigned int genrand_int32(void)
|
||||
{
|
||||
|
||||
unsigned int y;
|
||||
static unsigned int mag01[2]={0x0UL, MATRIX_A};
|
||||
/* mag01[x] = x * MATRIX_A for x=0,1 */
|
||||
|
||||
static unsigned int mt[N]; /* the array for the state vector */
|
||||
static int mti; /* mti==N+1 means mt[N] is not initialized */
|
||||
|
||||
|
||||
if (!mti)
|
||||
{
|
||||
unsigned int s=0x4141f00d;
|
||||
mt[0]= s & 0xffffffffUL;
|
||||
for (mti=1; mti<N; mti++)
|
||||
{
|
||||
mt[mti] =
|
||||
(1812433253UL * (mt[mti-1] ^ (mt[mti-1] >> 30)) + mti);
|
||||
/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */
|
||||
/* In the previous versions, MSBs of the seed affect */
|
||||
/* only MSBs of the array mt[]. */
|
||||
/* 2002/01/09 modified by Makoto Matsumoto */
|
||||
mt[mti] &= 0xffffffffUL;
|
||||
/* for >32 bit machines */
|
||||
}
|
||||
}
|
||||
|
||||
if (mti >= N) { /* generate N words at one time */
|
||||
int kk;
|
||||
|
||||
for (kk=0;kk<N-M;kk++) {
|
||||
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
||||
mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||
}
|
||||
for (;kk<N-1;kk++) {
|
||||
y = (mt[kk]&UPPER_MASK)|(mt[kk+1]&LOWER_MASK);
|
||||
mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||
}
|
||||
y = (mt[N-1]&UPPER_MASK)|(mt[0]&LOWER_MASK);
|
||||
mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
|
||||
|
||||
mti = 0;
|
||||
}
|
||||
|
||||
y = mt[mti++];
|
||||
|
||||
/* Tempering */
|
||||
y ^= (y >> 11);
|
||||
y ^= (y << 7) & 0x9d2c5680UL;
|
||||
y ^= (y << 15) & 0xefc60000UL;
|
||||
y ^= (y >> 18);
|
||||
|
||||
return y;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
EEL_F NSEEL_CGEN_CALL nseel_int_rand(EEL_F *f)
|
||||
{
|
||||
EEL_F x=floor(*f);
|
||||
if (x < 1.0) x=1.0;
|
||||
|
||||
#ifdef NSEEL_EEL1_COMPAT_MODE
|
||||
return (EEL_F)(genrand_int32()%(int)x);
|
||||
#else
|
||||
return (EEL_F) (genrand_int32()*(1.0/(double)0xFFFFFFFF)*x);
|
||||
#endif
|
||||
// return (EEL_F)(rand()%EEL_F2int(x));
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
#ifdef __ppc__
|
||||
#include "asm-nseel-ppc-gcc.c"
|
||||
#else
|
||||
#ifdef _MSC_VER
|
||||
#ifdef _WIN64
|
||||
//nasm
|
||||
#else
|
||||
#include "asm-nseel-x86-msvc.c"
|
||||
#endif
|
||||
#elif !defined(__LP64__)
|
||||
#include "asm-nseel-x86-gcc.c"
|
||||
#endif
|
||||
#endif
|
||||
|
1791
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-compiler.c
Normal file
1791
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-compiler.c
Normal file
File diff suppressed because it is too large
Load diff
321
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-eval.c
Normal file
321
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-eval.c
Normal file
|
@ -0,0 +1,321 @@
|
|||
/*
|
||||
Expression Evaluator Library (NS-EEL) v2
|
||||
Copyright (C) 2004-2008 Cockos Incorporated
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
nseel-eval.c
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include "ns-eel-int.h"
|
||||
|
||||
#define NSEEL_VARS_MALLOC_CHUNKSIZE 8
|
||||
#define NSEEL_GLOBALVAR_BASE (1<<24)
|
||||
|
||||
#ifndef NSEEL_MAX_VARIABLE_NAMELEN
|
||||
#define NSEEL_MAX_VARIABLE_NAMELEN 8
|
||||
#endif
|
||||
|
||||
#define strnicmp(x,y,z) strncasecmp(x,y,z)
|
||||
|
||||
|
||||
#define INTCONST 1
|
||||
#define DBLCONST 2
|
||||
#define HEXCONST 3
|
||||
#define VARIABLE 4
|
||||
#define OTHER 5
|
||||
|
||||
EEL_F nseel_globalregs[100];
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void *nseel_compileExpression(compileContext *ctx, char *exp)
|
||||
{
|
||||
ctx->errVar=0;
|
||||
nseel_llinit(ctx);
|
||||
if (!nseel_yyparse(ctx,exp) && !ctx->errVar)
|
||||
{
|
||||
return (void*)ctx->result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void nseel_setLastVar(compileContext *ctx)
|
||||
{
|
||||
nseel_gettoken(ctx,ctx->lastVar, sizeof(ctx->lastVar));
|
||||
}
|
||||
|
||||
void NSEEL_VM_enumallvars(NSEEL_VMCTX ctx, int (*func)(const char *name, EEL_F *val, void *ctx), void *userctx)
|
||||
{
|
||||
compileContext *tctx = (compileContext *) ctx;
|
||||
int wb;
|
||||
if (!tctx) return;
|
||||
|
||||
for (wb = 0; wb < tctx->varTable_numBlocks; wb ++)
|
||||
{
|
||||
int ti;
|
||||
int namepos=0;
|
||||
for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti ++)
|
||||
{
|
||||
char *p=tctx->varTable_Names[wb]+namepos;
|
||||
if (!*p) break;
|
||||
|
||||
|
||||
if (!func(p,&tctx->varTable_Values[wb][ti],userctx))
|
||||
break;
|
||||
|
||||
namepos += NSEEL_MAX_VARIABLE_NAMELEN;
|
||||
}
|
||||
if (ti < NSEEL_VARS_PER_BLOCK)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static INT_PTR register_var(compileContext *ctx, const char *name, EEL_F **ptr)
|
||||
{
|
||||
int wb;
|
||||
int ti=0;
|
||||
int i=0;
|
||||
char *nameptr;
|
||||
for (wb = 0; wb < ctx->varTable_numBlocks; wb ++)
|
||||
{
|
||||
int namepos=0;
|
||||
for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti ++)
|
||||
{
|
||||
if (!ctx->varTable_Names[wb][namepos] || !strnicmp(ctx->varTable_Names[wb]+namepos,name,NSEEL_MAX_VARIABLE_NAMELEN))
|
||||
{
|
||||
break;
|
||||
}
|
||||
namepos += NSEEL_MAX_VARIABLE_NAMELEN;
|
||||
i++;
|
||||
}
|
||||
if (ti < NSEEL_VARS_PER_BLOCK)
|
||||
break;
|
||||
}
|
||||
if (wb == ctx->varTable_numBlocks)
|
||||
{
|
||||
ti=0;
|
||||
// add new block
|
||||
if (!(ctx->varTable_numBlocks&(NSEEL_VARS_MALLOC_CHUNKSIZE-1)) || !ctx->varTable_Values || !ctx->varTable_Names )
|
||||
{
|
||||
ctx->varTable_Values = (EEL_F **)realloc(ctx->varTable_Values,(ctx->varTable_numBlocks+NSEEL_VARS_MALLOC_CHUNKSIZE) * sizeof(EEL_F *));
|
||||
ctx->varTable_Names = (char **)realloc(ctx->varTable_Names,(ctx->varTable_numBlocks+NSEEL_VARS_MALLOC_CHUNKSIZE) * sizeof(char *));
|
||||
}
|
||||
ctx->varTable_numBlocks++;
|
||||
|
||||
ctx->varTable_Values[wb] = (EEL_F *)calloc(sizeof(EEL_F),NSEEL_VARS_PER_BLOCK);
|
||||
ctx->varTable_Names[wb] = (char *)calloc(NSEEL_MAX_VARIABLE_NAMELEN,NSEEL_VARS_PER_BLOCK);
|
||||
}
|
||||
|
||||
nameptr=ctx->varTable_Names[wb]+ti*NSEEL_MAX_VARIABLE_NAMELEN;
|
||||
if (!nameptr[0])
|
||||
{
|
||||
strncpy(nameptr,name,NSEEL_MAX_VARIABLE_NAMELEN);
|
||||
}
|
||||
if (ptr) *ptr = ctx->varTable_Values[wb] + ti;
|
||||
return i;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
INT_PTR nseel_setVar(compileContext *ctx, INT_PTR varNum)
|
||||
{
|
||||
if (varNum < 0) // adding new var
|
||||
{
|
||||
char *var=ctx->lastVar;
|
||||
if (!strnicmp(var,"reg",3) && strlen(var) == 5 && isdigit(var[3]) && isdigit(var[4]))
|
||||
{
|
||||
int i,x=atoi(var+3);
|
||||
if (x < 0 || x > 99) x=0;
|
||||
i=NSEEL_GLOBALVAR_BASE+x;
|
||||
return i;
|
||||
}
|
||||
|
||||
return register_var(ctx,ctx->lastVar,NULL);
|
||||
|
||||
}
|
||||
|
||||
// setting/getting oldvar
|
||||
|
||||
if (varNum >= NSEEL_GLOBALVAR_BASE && varNum < NSEEL_GLOBALVAR_BASE+100)
|
||||
{
|
||||
return varNum;
|
||||
}
|
||||
|
||||
{
|
||||
int wb,ti;
|
||||
char *nameptr;
|
||||
if (varNum < 0 || varNum >= ctx->varTable_numBlocks*NSEEL_VARS_PER_BLOCK) return -1;
|
||||
|
||||
wb=varNum/NSEEL_VARS_PER_BLOCK;
|
||||
ti=(varNum%NSEEL_VARS_PER_BLOCK);
|
||||
nameptr=ctx->varTable_Names[wb]+ti*NSEEL_MAX_VARIABLE_NAMELEN;
|
||||
if (!nameptr[0])
|
||||
{
|
||||
strncpy(nameptr,ctx->lastVar,NSEEL_MAX_VARIABLE_NAMELEN);
|
||||
}
|
||||
return varNum;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
INT_PTR nseel_getVar(compileContext *ctx, INT_PTR i)
|
||||
{
|
||||
if (i >= 0 && i < (NSEEL_VARS_PER_BLOCK*ctx->varTable_numBlocks))
|
||||
return nseel_createCompiledValue(ctx,0, ctx->varTable_Values[i/NSEEL_VARS_PER_BLOCK] + i%NSEEL_VARS_PER_BLOCK);
|
||||
if (i >= NSEEL_GLOBALVAR_BASE && i < NSEEL_GLOBALVAR_BASE+100)
|
||||
return nseel_createCompiledValue(ctx,0, nseel_globalregs+i-NSEEL_GLOBALVAR_BASE);
|
||||
|
||||
return nseel_createCompiledValue(ctx,0, NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
EEL_F *NSEEL_VM_regvar(NSEEL_VMCTX _ctx, const char *var)
|
||||
{
|
||||
compileContext *ctx = (compileContext *)_ctx;
|
||||
EEL_F *r;
|
||||
if (!ctx) return 0;
|
||||
|
||||
if (!strnicmp(var,"reg",3) && strlen(var) == 5 && isdigit(var[3]) && isdigit(var[4]))
|
||||
{
|
||||
int x=atoi(var+3);
|
||||
if (x < 0 || x > 99) x=0;
|
||||
return nseel_globalregs + x;
|
||||
}
|
||||
|
||||
register_var(ctx,var,&r);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
INT_PTR nseel_translate(compileContext *ctx, int type)
|
||||
{
|
||||
int v;
|
||||
int n;
|
||||
*ctx->yytext = 0;
|
||||
nseel_gettoken(ctx,ctx->yytext, sizeof(ctx->yytext));
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case INTCONST: return nseel_createCompiledValue(ctx,(EEL_F)atoi(ctx->yytext), NULL);
|
||||
case DBLCONST: return nseel_createCompiledValue(ctx,(EEL_F)atof(ctx->yytext), NULL);
|
||||
case HEXCONST:
|
||||
v=0;
|
||||
n=0;
|
||||
while (1)
|
||||
{
|
||||
int a=ctx->yytext[n++];
|
||||
if (a >= '0' && a <= '9') v=(v<<4)+a-'0';
|
||||
else if (a >= 'A' && a <= 'F') v=(v<<4)+10+a-'A';
|
||||
else if (a >= 'a' && a <= 'f') v=(v<<4)+10+a-'a';
|
||||
else break;
|
||||
}
|
||||
return nseel_createCompiledValue(ctx,(EEL_F)v, NULL);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
INT_PTR nseel_lookup(compileContext *ctx, int *typeOfObject)
|
||||
{
|
||||
int i, ti, wb;
|
||||
const char *nptr;
|
||||
nseel_gettoken(ctx,ctx->yytext, sizeof(ctx->yytext));
|
||||
|
||||
if (!strnicmp(ctx->yytext,"reg",3) && strlen(ctx->yytext) == 5 && isdigit(ctx->yytext[3]) && isdigit(ctx->yytext[4]) && (i=atoi(ctx->yytext+3))>=0 && i<100)
|
||||
{
|
||||
*typeOfObject=IDENTIFIER;
|
||||
return i+NSEEL_GLOBALVAR_BASE;
|
||||
}
|
||||
|
||||
i=0;
|
||||
for (wb = 0; wb < ctx->varTable_numBlocks; wb ++)
|
||||
{
|
||||
int namepos=0;
|
||||
for (ti = 0; ti < NSEEL_VARS_PER_BLOCK; ti ++)
|
||||
{
|
||||
if (!ctx->varTable_Names[wb][namepos]) break;
|
||||
|
||||
if (!strnicmp(ctx->varTable_Names[wb]+namepos,ctx->yytext,NSEEL_MAX_VARIABLE_NAMELEN))
|
||||
{
|
||||
*typeOfObject = IDENTIFIER;
|
||||
return i;
|
||||
}
|
||||
|
||||
namepos += NSEEL_MAX_VARIABLE_NAMELEN;
|
||||
i++;
|
||||
}
|
||||
if (ti < NSEEL_VARS_PER_BLOCK) break;
|
||||
}
|
||||
|
||||
|
||||
nptr = ctx->yytext;
|
||||
if (!strcasecmp(nptr,"if")) nptr="_if";
|
||||
else if (!strcasecmp(nptr,"bnot")) nptr="_not";
|
||||
else if (!strcasecmp(nptr,"assign")) nptr="_set";
|
||||
else if (!strcasecmp(nptr,"equal")) nptr="_equal";
|
||||
else if (!strcasecmp(nptr,"below")) nptr="_below";
|
||||
else if (!strcasecmp(nptr,"above")) nptr="_above";
|
||||
else if (!strcasecmp(nptr,"megabuf")) nptr="_mem";
|
||||
else if (!strcasecmp(nptr,"gmegabuf")) nptr="_gmem";
|
||||
else if (!strcasecmp(nptr,"int")) nptr="floor";
|
||||
|
||||
for (i=0;nseel_getFunctionFromTable(i);i++)
|
||||
{
|
||||
functionType *f=nseel_getFunctionFromTable(i);
|
||||
if (!strcasecmp(f->name, nptr))
|
||||
{
|
||||
switch (f->nParams)
|
||||
{
|
||||
case 1: *typeOfObject = FUNCTION1; break;
|
||||
case 2: *typeOfObject = FUNCTION2; break;
|
||||
case 3: *typeOfObject = FUNCTION3; break;
|
||||
default: *typeOfObject = IDENTIFIER; break;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
*typeOfObject = IDENTIFIER;
|
||||
nseel_setLastVar(ctx);
|
||||
return nseel_setVar(ctx,-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
void nseel_count(compileContext *ctx)
|
||||
{
|
||||
nseel_gettoken(ctx,ctx->yytext, sizeof(ctx->yytext));
|
||||
ctx->colCount+=strlen(ctx->yytext);
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------------------
|
||||
int nseel_yyerror(compileContext *ctx)
|
||||
{
|
||||
ctx->errVar = ctx->colCount;
|
||||
return 0;
|
||||
}
|
277
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-lextab.c
Normal file
277
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-lextab.c
Normal file
|
@ -0,0 +1,277 @@
|
|||
/*
|
||||
Expression Evaluator Library (NS-EEL) v2
|
||||
Copyright (C) 2004-2008 Cockos Incorporated
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
nseel-lextab.c
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ns-eel-int.h"
|
||||
|
||||
|
||||
#define LEXSKIP (-1)
|
||||
|
||||
static int _lmovb(struct lextab *lp, int c, int st)
|
||||
{
|
||||
int base;
|
||||
|
||||
while ((base = lp->llbase[st]+c) > lp->llnxtmax ||
|
||||
(lp->llcheck[base] & 0377) != st) {
|
||||
|
||||
if (st != lp->llendst) {
|
||||
base = lp->lldefault[st] & 0377;
|
||||
st = base;
|
||||
}
|
||||
else
|
||||
return(-1);
|
||||
}
|
||||
return(lp->llnext[base]&0377);
|
||||
}
|
||||
|
||||
#define INTCONST 1
|
||||
#define DBLCONST 2
|
||||
#define HEXCONST 3
|
||||
#define VARIABLE 4
|
||||
#define OTHER 5
|
||||
|
||||
static int _Alextab(compileContext *ctx, int __na__)
|
||||
{
|
||||
// fucko: JF> 17 -> 19?
|
||||
|
||||
if (__na__ >= 0 && __na__ <= 17)
|
||||
nseel_count(ctx);
|
||||
switch (__na__)
|
||||
{
|
||||
case 0:
|
||||
*ctx->yytext = 0;
|
||||
nseel_gettoken(ctx,ctx->yytext, sizeof(ctx->yytext));
|
||||
if (ctx->yytext[0] < '0' || ctx->yytext[0] > '9') // not really a hex value, lame
|
||||
{
|
||||
nseel_setLastVar(ctx); ctx->yylval = nseel_lookup(ctx,&__na__); return __na__;
|
||||
}
|
||||
ctx->yylval = nseel_translate(ctx,HEXCONST);
|
||||
return VALUE;
|
||||
case 1: ctx->yylval = nseel_translate(ctx,INTCONST); return VALUE;
|
||||
case 2: ctx->yylval = nseel_translate(ctx,INTCONST); return VALUE;
|
||||
case 3: ctx->yylval = nseel_translate(ctx,DBLCONST); return VALUE;
|
||||
case 4:
|
||||
case 5: nseel_setLastVar(ctx); ctx->yylval = nseel_lookup(ctx,&__na__); return __na__;
|
||||
case 6: return '+';
|
||||
case 7: return '-';
|
||||
case 8: return '*';
|
||||
case 9: return '/';
|
||||
case 10: return '%';
|
||||
case 11: return '&';
|
||||
case 12: return '|';
|
||||
case 13: return '(';
|
||||
case 14: return ')';
|
||||
case 15: return '=';
|
||||
case 16: return ',';
|
||||
case 17: return ';';
|
||||
}
|
||||
return (LEXSKIP);
|
||||
}
|
||||
|
||||
|
||||
static char _Flextab[] =
|
||||
{
|
||||
1, 18, 17, 16, 15, 14, 13, 12,
|
||||
11, 10, 9, 8, 7, 6, 4, 5,
|
||||
5, 4, 4, 3, 3, 3, 3, 4,
|
||||
0, 4, 5, 0, 5, 4, 1, 3,
|
||||
0, 2, -1, 1, -1,
|
||||
};
|
||||
|
||||
|
||||
static char _Nlextab[] =
|
||||
{
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 1, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
1, 36, 36, 36, 36, 9, 8, 36,
|
||||
6, 5, 11, 13, 3, 12, 19, 10,
|
||||
30, 30, 30, 30, 30, 30, 30, 30,
|
||||
30, 30, 36, 2, 36, 4, 36, 36,
|
||||
36, 29, 29, 29, 29, 29, 29, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 36, 36, 36, 36, 18,
|
||||
36, 29, 29, 29, 29, 29, 23, 18,
|
||||
18, 18, 18, 18, 18, 18, 18, 18,
|
||||
18, 18, 18, 18, 18, 18, 14, 18,
|
||||
18, 18, 18, 36, 7, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 36,
|
||||
36, 36, 36, 36, 36, 36, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
36, 36, 36, 36, 17, 36, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
17, 17, 17, 17, 17, 17, 17, 17,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 36, 36, 36, 36, 36, 36,
|
||||
36, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 36, 36, 36, 36, 16,
|
||||
36, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 16, 16, 16, 16, 16,
|
||||
16, 16, 16, 22, 22, 22, 22, 22,
|
||||
22, 22, 22, 22, 22, 21, 21, 21,
|
||||
21, 21, 21, 21, 21, 21, 21, 36,
|
||||
20, 26, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 36, 36, 36, 36, 36,
|
||||
36, 36, 25, 25, 25, 25, 25, 25,
|
||||
36, 24, 36, 36, 36, 36, 36, 36,
|
||||
20, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 25, 25, 25, 25, 25, 25,
|
||||
36, 24, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, 36, 36, 36, 36,
|
||||
36, 36, 36, 28, 28, 28, 28, 28,
|
||||
28, 36, 27, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 28, 28, 28, 28, 28,
|
||||
28, 31, 27, 35, 35, 35, 35, 35,
|
||||
35, 35, 35, 35, 35, 36, 36, 36,
|
||||
36, 36, 36, 36, 34, 34, 34, 33,
|
||||
34, 34, 36, 32, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 34, 34, 34, 33,
|
||||
34, 34, 36, 32, 34, 34, 34, 34,
|
||||
34, 34, 34, 34, 34, 34, 36, 36,
|
||||
36, 36, 36, 36, 36, 34, 34, 34,
|
||||
34, 34, 34, 36, 32, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 34, 34, 34,
|
||||
34, 34, 34, 36, 32,
|
||||
};
|
||||
|
||||
static char _Clextab[] =
|
||||
{
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, 0, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
0, -1, -1, -1, -1, 0, 0, -1,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, -1, 0, -1, 0, -1, -1,
|
||||
-1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, -1, -1, -1, -1, 0,
|
||||
-1, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, -1, 0, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, -1,
|
||||
-1, -1, -1, -1, -1, -1, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14,
|
||||
-1, -1, -1, -1, 14, -1, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14,
|
||||
14, 14, 14, 14, 14, 14, 14, 14,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, -1, -1, -1, -1, -1, -1,
|
||||
-1, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, -1, -1, -1, -1, 15,
|
||||
-1, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 15, 15, 15, 15, 15,
|
||||
15, 15, 15, 19, 19, 19, 19, 19,
|
||||
19, 19, 19, 19, 19, 20, 20, 20,
|
||||
20, 20, 20, 20, 20, 20, 20, -1,
|
||||
19, 23, 23, 23, 23, 23, 23, 23,
|
||||
23, 23, 23, -1, -1, -1, -1, -1,
|
||||
-1, -1, 23, 23, 23, 23, 23, 23,
|
||||
-1, 23, -1, -1, -1, -1, -1, -1,
|
||||
19, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, 23, 23, 23, 23, 23, 23,
|
||||
-1, 23, 26, 26, 26, 26, 26, 26,
|
||||
26, 26, 26, 26, -1, -1, -1, -1,
|
||||
-1, -1, -1, 26, 26, 26, 26, 26,
|
||||
26, -1, 26, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, 26, 26, 26, 26, 26,
|
||||
26, 30, 26, 30, 30, 30, 30, 30,
|
||||
30, 30, 30, 30, 30, -1, -1, -1,
|
||||
-1, -1, -1, -1, 30, 30, 30, 30,
|
||||
30, 30, -1, 30, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, 30, 30, 30, 30,
|
||||
30, 30, -1, 30, 33, 33, 33, 33,
|
||||
33, 33, 33, 33, 33, 33, -1, -1,
|
||||
-1, -1, -1, -1, -1, 33, 33, 33,
|
||||
33, 33, 33, -1, 33, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, 33, 33, 33,
|
||||
33, 33, 33, -1, 33,
|
||||
};
|
||||
|
||||
static char _Dlextab[] =
|
||||
{
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
36, 36, 36, 36, 36, 36, 36, 36,
|
||||
15, 14, 14, 36, 36, 20, 19, 14,
|
||||
14, 23, 15, 15, 26, 23, 36, 19,
|
||||
36, 36, 33, 30,
|
||||
};
|
||||
|
||||
static int _Blextab[] =
|
||||
{
|
||||
0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 77, 152,
|
||||
0, 0, 0, 227, 237, 0, 0, 249,
|
||||
0, 0, 306, 0, 0, 0, 363, 0,
|
||||
0, 420, 0, 0, 0,
|
||||
};
|
||||
|
||||
struct lextab nseel_lextab = {
|
||||
36,
|
||||
_Dlextab,
|
||||
_Nlextab,
|
||||
_Clextab,
|
||||
_Blextab,
|
||||
524,
|
||||
_lmovb,
|
||||
_Flextab,
|
||||
_Alextab,
|
||||
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
};
|
||||
|
||||
|
320
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-ram.c
Normal file
320
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-ram.c
Normal file
|
@ -0,0 +1,320 @@
|
|||
/*
|
||||
Expression Evaluator Library (NS-EEL) v2
|
||||
Copyright (C) 2004-2008 Cockos Incorporated
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include "ns-eel.h"
|
||||
#include "ns-eel-int.h"
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#endif
|
||||
|
||||
unsigned int NSEEL_RAM_limitmem=0;
|
||||
unsigned int NSEEL_RAM_memused=0;
|
||||
int NSEEL_RAM_memused_errors=0;
|
||||
|
||||
|
||||
|
||||
int NSEEL_VM_wantfreeRAM(NSEEL_VMCTX ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
compileContext *c=(compileContext*)ctx;
|
||||
if (c->ram_needfree)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void NSEEL_VM_freeRAMIfCodeRequested(NSEEL_VMCTX ctx) // check to see if our free flag was set
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
compileContext *c=(compileContext*)ctx;
|
||||
if (c->ram_needfree)
|
||||
{
|
||||
NSEEL_HOSTSTUB_EnterMutex();
|
||||
if (c->ram_blocks)
|
||||
{
|
||||
INT_PTR startpos=((INT_PTR)c->ram_needfree)-1;
|
||||
EEL_F **blocks = (EEL_F **)c->ram_blocks;
|
||||
INT_PTR pos=0;
|
||||
int x;
|
||||
for (x = 0; x < NSEEL_RAM_BLOCKS; x ++)
|
||||
{
|
||||
if (pos >= startpos)
|
||||
{
|
||||
if (blocks[x])
|
||||
{
|
||||
if (NSEEL_RAM_memused >= sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK)
|
||||
NSEEL_RAM_memused -= sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK;
|
||||
else NSEEL_RAM_memused_errors++;
|
||||
}
|
||||
free(blocks[x]);
|
||||
blocks[x]=0;
|
||||
}
|
||||
pos+=NSEEL_RAM_ITEMSPERBLOCK;
|
||||
}
|
||||
if (!startpos)
|
||||
{
|
||||
free(blocks);
|
||||
c->ram_blocks=0;
|
||||
}
|
||||
}
|
||||
c->ram_needfree=0;
|
||||
NSEEL_HOSTSTUB_LeaveMutex();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAllocGMEM(EEL_F ***blocks, int w)
|
||||
{
|
||||
static EEL_F * volatile gmembuf;
|
||||
if (blocks) return __NSEEL_RAMAlloc(blocks,w);
|
||||
|
||||
if (!gmembuf)
|
||||
{
|
||||
NSEEL_HOSTSTUB_EnterMutex();
|
||||
if (!gmembuf) gmembuf=(EEL_F*)calloc(sizeof(EEL_F),NSEEL_SHARED_GRAM_SIZE);
|
||||
NSEEL_HOSTSTUB_LeaveMutex();
|
||||
|
||||
if (!gmembuf) return 0;
|
||||
}
|
||||
|
||||
return gmembuf+(((unsigned int)w)&((NSEEL_SHARED_GRAM_SIZE)-1));
|
||||
}
|
||||
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAMAlloc(EEL_F ***blocks, int w)
|
||||
{
|
||||
int whichblock;
|
||||
EEL_F **pblocks=*blocks;
|
||||
|
||||
int is_locked=0;
|
||||
|
||||
if (!pblocks)
|
||||
{
|
||||
if (!is_locked) { is_locked=1; NSEEL_HOSTSTUB_EnterMutex(); }
|
||||
|
||||
if (!(pblocks=*blocks))
|
||||
{
|
||||
pblocks = *blocks = (EEL_F **)calloc(sizeof(EEL_F *),NSEEL_RAM_BLOCKS);
|
||||
if (!pblocks) {
|
||||
if (is_locked) NSEEL_HOSTSTUB_LeaveMutex();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fprintf(stderr,"got request at %d, %d\n",w/NSEEL_RAM_ITEMSPERBLOCK, w&(NSEEL_RAM_ITEMSPERBLOCK-1));
|
||||
if (w >= 0 && (whichblock = w/NSEEL_RAM_ITEMSPERBLOCK) < NSEEL_RAM_BLOCKS)
|
||||
{
|
||||
EEL_F *p=pblocks[whichblock];
|
||||
if (!p)
|
||||
{
|
||||
if (!is_locked) { is_locked=1; NSEEL_HOSTSTUB_EnterMutex(); }
|
||||
|
||||
if (!(p=pblocks[whichblock]))
|
||||
{
|
||||
|
||||
const int msize=sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK;
|
||||
if (!NSEEL_RAM_limitmem || NSEEL_RAM_memused+msize < NSEEL_RAM_limitmem)
|
||||
{
|
||||
p=pblocks[whichblock]=(EEL_F *)calloc(sizeof(EEL_F),NSEEL_RAM_ITEMSPERBLOCK);
|
||||
if (p) NSEEL_RAM_memused+=msize;
|
||||
}
|
||||
if (!p) w=0;
|
||||
}
|
||||
}
|
||||
if (is_locked) NSEEL_HOSTSTUB_LeaveMutex();
|
||||
return p + (w&(NSEEL_RAM_ITEMSPERBLOCK-1));
|
||||
}
|
||||
if (is_locked) NSEEL_HOSTSTUB_LeaveMutex();
|
||||
// fprintf(stderr,"ret 0\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemFree(EEL_F ***blocks, EEL_F *which)
|
||||
{
|
||||
int d=EEL_F2int(*which);
|
||||
if (d < 0) d=0;
|
||||
if (d < NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK) ((INT_PTR *)blocks)[1]=1+d;
|
||||
return which;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemCpy(EEL_F ***blocks,EEL_F *dest, EEL_F *src, EEL_F *lenptr)
|
||||
{
|
||||
int dest_offs = EEL_F2int(*dest + 0.0001);
|
||||
int src_offs = EEL_F2int(*src + 0.0001);
|
||||
int len = EEL_F2int(*lenptr + 0.0001);
|
||||
|
||||
// trim to front
|
||||
if (src_offs<0)
|
||||
{
|
||||
len += src_offs;
|
||||
dest_offs -= src_offs;
|
||||
src_offs=0;
|
||||
}
|
||||
if (dest_offs<0)
|
||||
{
|
||||
len += dest_offs;
|
||||
src_offs -= dest_offs;
|
||||
dest_offs=0;
|
||||
}
|
||||
|
||||
while (len > 0)
|
||||
{
|
||||
EEL_F *srcptr,*destptr;
|
||||
int copy_len = len;
|
||||
int maxdlen=NSEEL_RAM_ITEMSPERBLOCK - (dest_offs&(NSEEL_RAM_ITEMSPERBLOCK-1));
|
||||
int maxslen=NSEEL_RAM_ITEMSPERBLOCK - (src_offs&(NSEEL_RAM_ITEMSPERBLOCK-1));
|
||||
|
||||
if (dest_offs >= NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK ||
|
||||
src_offs >= NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK) break;
|
||||
|
||||
if (copy_len > maxdlen) copy_len=maxdlen;
|
||||
if (copy_len > maxslen) copy_len=maxslen;
|
||||
|
||||
if (copy_len<1) break;
|
||||
|
||||
srcptr = __NSEEL_RAMAlloc(blocks,src_offs);
|
||||
destptr = __NSEEL_RAMAlloc(blocks,dest_offs);
|
||||
if (!srcptr || !destptr) break;
|
||||
|
||||
memmove(destptr,srcptr,sizeof(EEL_F)*copy_len);
|
||||
src_offs+=copy_len;
|
||||
dest_offs+=copy_len;
|
||||
len-=copy_len;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
EEL_F * NSEEL_CGEN_CALL __NSEEL_RAM_MemSet(EEL_F ***blocks,EEL_F *dest, EEL_F *v, EEL_F *lenptr)
|
||||
{
|
||||
int offs = EEL_F2int(*dest + 0.0001);
|
||||
int len = EEL_F2int(*lenptr + 0.0001);
|
||||
EEL_F t;
|
||||
if (offs<0)
|
||||
{
|
||||
len += offs;
|
||||
offs=0;
|
||||
}
|
||||
if (offs >= NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK) return dest;
|
||||
|
||||
if (offs+len > NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK) len = NSEEL_RAM_BLOCKS*NSEEL_RAM_ITEMSPERBLOCK - offs;
|
||||
|
||||
if (len < 1) return dest;
|
||||
|
||||
|
||||
t=*v; // set value
|
||||
|
||||
// int lastBlock=-1;
|
||||
while (len > 0)
|
||||
{
|
||||
int lcnt;
|
||||
EEL_F *ptr=__NSEEL_RAMAlloc(blocks,offs);
|
||||
if (!ptr) break;
|
||||
|
||||
lcnt=NSEEL_RAM_ITEMSPERBLOCK-(offs&(NSEEL_RAM_ITEMSPERBLOCK-1));
|
||||
if (lcnt > len) lcnt=len;
|
||||
|
||||
len -= lcnt;
|
||||
offs += lcnt;
|
||||
|
||||
while (lcnt--)
|
||||
{
|
||||
*ptr++=t;
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
||||
void NSEEL_VM_SetGRAM(NSEEL_VMCTX ctx, void **gram)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
compileContext *c=(compileContext*)ctx;
|
||||
c->gram_blocks = gram;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void NSEEL_VM_freeRAM(NSEEL_VMCTX ctx)
|
||||
{
|
||||
if (ctx)
|
||||
{
|
||||
int x;
|
||||
compileContext *c=(compileContext*)ctx;
|
||||
if (c->ram_blocks)
|
||||
{
|
||||
EEL_F **blocks = (EEL_F **)c->ram_blocks;
|
||||
for (x = 0; x < NSEEL_RAM_BLOCKS; x ++)
|
||||
{
|
||||
if (blocks[x])
|
||||
{
|
||||
if (NSEEL_RAM_memused >= sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK)
|
||||
NSEEL_RAM_memused -= sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK;
|
||||
else NSEEL_RAM_memused_errors++;
|
||||
}
|
||||
free(blocks[x]);
|
||||
blocks[x]=0;
|
||||
}
|
||||
free(blocks);
|
||||
c->ram_blocks=0;
|
||||
}
|
||||
c->ram_needfree=0; // no need to free anymore
|
||||
}
|
||||
}
|
||||
|
||||
void NSEEL_VM_FreeGRAM(void **ufd)
|
||||
{
|
||||
if (ufd[0])
|
||||
{
|
||||
EEL_F **blocks = (EEL_F **)ufd[0];
|
||||
int x;
|
||||
for (x = 0; x < NSEEL_RAM_BLOCKS; x ++)
|
||||
{
|
||||
if (blocks[x])
|
||||
{
|
||||
if (NSEEL_RAM_memused >= sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK)
|
||||
NSEEL_RAM_memused -= sizeof(EEL_F) * NSEEL_RAM_ITEMSPERBLOCK;
|
||||
else NSEEL_RAM_memused_errors++;
|
||||
}
|
||||
free(blocks[x]);
|
||||
blocks[x]=0;
|
||||
}
|
||||
free(blocks);
|
||||
ufd[0]=0;
|
||||
}
|
||||
}
|
163
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-yylex.c
Normal file
163
Src/Plugins/Visualization/vis_milk2/ns-eel2/nseel-yylex.c
Normal file
|
@ -0,0 +1,163 @@
|
|||
/*
|
||||
Expression Evaluator Library (NS-EEL)
|
||||
Copyright (C) 2004-2008 Cockos Incorporated
|
||||
Copyright (C) 1999-2003 Nullsoft, Inc.
|
||||
|
||||
nseel-yylex.c
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
|
||||
#include "ns-eel-int.h"
|
||||
|
||||
|
||||
#define NBPW 16
|
||||
#define EOF (-1)
|
||||
|
||||
|
||||
#define YYERRORVAL 256 /* yacc's value */
|
||||
|
||||
static int llset(compileContext *ctx);
|
||||
static int llinp(compileContext *ctx, char **exp);
|
||||
static int lexgetc(char **exp)
|
||||
{
|
||||
char c= **exp;
|
||||
if (c) (*exp)++;
|
||||
return( c != 0 ? c : -1);
|
||||
}
|
||||
static int tst__b(register int c, char tab[])
|
||||
{
|
||||
return (tab[(c >> 3) & 037] & (1 << (c & 07)) );
|
||||
}
|
||||
|
||||
int nseel_gettoken(compileContext *ctx, char *lltb, int lltbsiz)
|
||||
{
|
||||
register char *lp, *tp, *ep;
|
||||
|
||||
tp = lltb;
|
||||
ep = tp+lltbsiz-1;
|
||||
for (lp = ctx->llbuf; lp < ctx->llend && tp < ep;)
|
||||
*tp++ = *lp++;
|
||||
*tp = 0;
|
||||
return(tp-lltb);
|
||||
}
|
||||
|
||||
|
||||
int nseel_yylex(compileContext *ctx, char **exp)
|
||||
{
|
||||
register int c, st;
|
||||
int final, l, llk, i;
|
||||
register struct lextab *lp;
|
||||
char *cp;
|
||||
|
||||
while (1)
|
||||
{
|
||||
llk = 0;
|
||||
if (llset(ctx)) return(0);
|
||||
st = 0;
|
||||
final = -1;
|
||||
lp = &nseel_lextab;
|
||||
|
||||
do {
|
||||
if (lp->lllook && (l = lp->lllook[st])) {
|
||||
for (c=0; c<NBPW; c++)
|
||||
if (l&(1<<c))
|
||||
ctx->llsave[c] = ctx->llp1;
|
||||
llk++;
|
||||
}
|
||||
if ((i = lp->llfinal[st]) != -1) {
|
||||
final = i;
|
||||
ctx->llend = ctx->llp1;
|
||||
}
|
||||
if ((c = llinp(ctx,exp)) < 0)
|
||||
break;
|
||||
if ((cp = lp->llbrk) && llk==0 && tst__b(c, cp)) {
|
||||
ctx->llp1--;
|
||||
break;
|
||||
}
|
||||
} while ((st = (*lp->llmove)(lp, c, st)) != -1);
|
||||
|
||||
|
||||
if (ctx->llp2 < ctx->llp1)
|
||||
ctx->llp2 = ctx->llp1;
|
||||
if (final == -1) {
|
||||
ctx->llend = ctx->llp1;
|
||||
if (st == 0 && c < 0)
|
||||
return(0);
|
||||
if ((cp = lp->llill) && tst__b(c, cp)) {
|
||||
continue;
|
||||
}
|
||||
return(YYERRORVAL);
|
||||
}
|
||||
if ((c = (final >> 11) & 037))
|
||||
ctx->llend = ctx->llsave[c-1];
|
||||
if ((c = (*lp->llactr)(ctx,final&03777)) >= 0)
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
void nseel_llinit(compileContext *ctx)
|
||||
{
|
||||
ctx->llp1 = ctx->llp2 = ctx->llend = ctx->llbuf;
|
||||
ctx->llebuf = ctx->llbuf + sizeof(ctx->llbuf);
|
||||
ctx->lleof = ctx->yyline = 0;
|
||||
}
|
||||
|
||||
|
||||
static int llinp(compileContext *ctx, char **exp)
|
||||
{
|
||||
register int c;
|
||||
register struct lextab *lp;
|
||||
register char *cp;
|
||||
|
||||
lp = &nseel_lextab;
|
||||
cp = lp->llign; /* Ignore class */
|
||||
for (;;) {
|
||||
/*
|
||||
* Get the next character from the save buffer (if possible)
|
||||
* If the save buffer's empty, then return EOF or the next
|
||||
* input character. Ignore the character if it's in the
|
||||
* ignore class.
|
||||
*/
|
||||
c = (ctx->llp1 < ctx->llp2) ? *ctx->llp1 & 0377 : (ctx->lleof) ? EOF : lexgetc(exp);
|
||||
if (c >= 0) { /* Got a character? */
|
||||
if (cp && tst__b(c, cp))
|
||||
continue; /* Ignore it */
|
||||
if (ctx->llp1 >= ctx->llebuf) { /* No, is there room? */
|
||||
return -1;
|
||||
}
|
||||
*ctx->llp1++ = c; /* Store in token buff */
|
||||
} else
|
||||
ctx->lleof = 1; /* Set EOF signal */
|
||||
return(c);
|
||||
}
|
||||
}
|
||||
|
||||
static int llset(compileContext *ctx)
|
||||
/*
|
||||
* Return TRUE if EOF and nothing was moved in the look-ahead buffer
|
||||
*/
|
||||
{
|
||||
register char *lp1, *lp2;
|
||||
|
||||
for (lp1 = ctx->llbuf, lp2 = ctx->llend; lp2 < ctx->llp2;)
|
||||
*lp1++ = *lp2++;
|
||||
ctx->llend = ctx->llp1 = ctx->llbuf;
|
||||
ctx->llp2 = lp1;
|
||||
return(ctx->lleof && lp1 == ctx->llbuf);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue