From fa670f5f7d41ac14932163e49d22832f6c94b61f Mon Sep 17 00:00:00 2001 From: Anton Fedchin Date: Fri, 22 Dec 2017 11:45:36 +0300 Subject: [PATCH 1/3] update to ns-eel2 --- depends/windows/nasmw/CMakeLists.txt | 7 + depends/windows/nasmw/nasmw.txt | 1 + lib/vis_milkdrop/CMakeLists.txt | 4 +- lib/vis_milkdrop/milkdropfs.cpp | 47 +- lib/vis_milkdrop/ns-eel2/CMakeLists.txt | 26 + lib/vis_milkdrop/ns-eel2/asm-nseel-arm-gcc.c | 1382 +++++++++ lib/vis_milkdrop/ns-eel2/asm-nseel-arm.asm | 1381 +++++++++ lib/vis_milkdrop/ns-eel2/asm-nseel-ppc-gcc.c | 1041 +++++++ .../ns-eel2/asm-nseel-x64-macho.o | Bin 0 -> 7505 bytes lib/vis_milkdrop/ns-eel2/asm-nseel-x64.asm | 1686 +++++++++++ lib/vis_milkdrop/ns-eel2/asm-nseel-x86-gcc.c | 1566 +++++++++++ lib/vis_milkdrop/ns-eel2/asm-nseel-x86-msvc.c | 2463 +++++++++++++++++ lib/vis_milkdrop/ns-eel2/ns-eel-addfuncs.h | 74 + lib/vis_milkdrop/ns-eel2/ns-eel-int.h | 227 ++ lib/vis_milkdrop/ns-eel2/ns-eel.h | 155 ++ lib/vis_milkdrop/ns-eel2/nseel-caltab.c | 553 ++++ lib/vis_milkdrop/ns-eel2/nseel-cfunc.c | 131 + lib/vis_milkdrop/ns-eel2/nseel-compiler.c | 1809 ++++++++++++ lib/vis_milkdrop/ns-eel2/nseel-eval.c | 321 +++ lib/vis_milkdrop/ns-eel2/nseel-lextab.c | 277 ++ lib/vis_milkdrop/ns-eel2/nseel-ram.c | 320 +++ lib/vis_milkdrop/ns-eel2/nseel-yylex.c | 163 ++ lib/vis_milkdrop/plugin.cpp | 5 +- lib/vis_milkdrop/state.cpp | 661 +++-- lib/vis_milkdrop/state.h | 23 +- lib/vis_milkdrop/utility.cpp | 297 +- 26 files changed, 13949 insertions(+), 671 deletions(-) create mode 100644 depends/windows/nasmw/CMakeLists.txt create mode 100644 depends/windows/nasmw/nasmw.txt create mode 100644 lib/vis_milkdrop/ns-eel2/CMakeLists.txt create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-arm-gcc.c create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-arm.asm create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-ppc-gcc.c create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-x64-macho.o create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-x64.asm create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-x86-gcc.c create mode 100644 lib/vis_milkdrop/ns-eel2/asm-nseel-x86-msvc.c create mode 100644 lib/vis_milkdrop/ns-eel2/ns-eel-addfuncs.h create mode 100644 lib/vis_milkdrop/ns-eel2/ns-eel-int.h create mode 100644 lib/vis_milkdrop/ns-eel2/ns-eel.h create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-caltab.c create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-cfunc.c create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-compiler.c create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-eval.c create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-lextab.c create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-ram.c create mode 100644 lib/vis_milkdrop/ns-eel2/nseel-yylex.c diff --git a/depends/windows/nasmw/CMakeLists.txt b/depends/windows/nasmw/CMakeLists.txt new file mode 100644 index 0000000..141fae8 --- /dev/null +++ b/depends/windows/nasmw/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8) +project(nasmw) + +install( + DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/ + DESTINATION ${CMAKE_INSTALL_PREFIX}/bin +) diff --git a/depends/windows/nasmw/nasmw.txt b/depends/windows/nasmw/nasmw.txt new file mode 100644 index 0000000..2b643ca --- /dev/null +++ b/depends/windows/nasmw/nasmw.txt @@ -0,0 +1 @@ +nasmw http://www.nasm.us/pub/nasm/releasebuilds/2.12.02/win32/nasm-2.12.02-win32.zip diff --git a/lib/vis_milkdrop/CMakeLists.txt b/lib/vis_milkdrop/CMakeLists.txt index 7e00b2e..0673511 100644 --- a/lib/vis_milkdrop/CMakeLists.txt +++ b/lib/vis_milkdrop/CMakeLists.txt @@ -43,7 +43,7 @@ set(SOURCES dx11/CommonStates.cpp state.cpp support.cpp) -add_subdirectory(evallib) +add_subdirectory(ns-eel2) if(CORE_SYSTEM_NAME STREQUAL windowsstore) add_definitions(-D_WIN32_WINNT=0x0A00 -D_WINDOWS) @@ -53,4 +53,4 @@ endif() remove_definitions(-D_USE_32BIT_TIME_T) add_library(vis_milkdrop STATIC ${SOURCES} ${SHADER_INCLUDES}) -target_link_libraries(vis_milkdrop evallib) +target_link_libraries(vis_milkdrop ns-eel2) diff --git a/lib/vis_milkdrop/milkdropfs.cpp b/lib/vis_milkdrop/milkdropfs.cpp index 725e451..af93bd8 100644 --- a/lib/vis_milkdrop/milkdropfs.cpp +++ b/lib/vis_milkdrop/milkdropfs.cpp @@ -30,8 +30,9 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "plugin.h" //#include "resource.h" #include "support.h" -#include "evallib\eval.h" // for math. expr. eval - thanks Francis! (in SourceOffSite, it's the 'vis_avs\evallib' project.) -#include "evallib\compiler.h" +//#include "evallib\eval.h" // for math. expr. eval - thanks Francis! (in SourceOffSite, it's the 'vis_avs\evallib' project.) +//#include "evallib\compiler.h" +#include "ns-eel2/ns-eel.h" #include "utility.h" #include @@ -79,9 +80,10 @@ int g_title_font_sizes[] = // function changes the control Word to set them and returns // TRUE, putting the old control Word value in the passback // location pointed to by pwOldCW. -BOOL MungeFPCW( WORD *pwOldCW ) +void MungeFPCW( WORD *pwOldCW ) { - BOOL ret = FALSE; +#if 0 + BOOL ret = FALSE; WORD wTemp, wSave; __asm fstcw wSave @@ -102,13 +104,21 @@ BOOL MungeFPCW( WORD *pwOldCW ) } if (pwOldCW) *pwOldCW = wSave; return ret; +#else +#ifndef _WIN64 + _controlfp(_PC_24, _MCW_PC); // single precision (not supported on x64 see MSDN) +#endif // !_WIN64 + _controlfp(_RC_NEAR, _MCW_RC); // round to nearest mode + _controlfp(_EM_ZERODIVIDE, _EM_ZERODIVIDE); // disable divide-by-zero +#endif } - +#if 0 void RestoreFPCW(WORD wSave) { - __asm fldcw wSave + __asm fldcw wSave } +#endif // 0 int GetNumToSpawn(float fTime, float fDeltaT, float fRate, float fRegularity, int iNumSpawnedSoFar) { @@ -596,12 +606,10 @@ void CPlugin::RunPerFrameEquations() #ifndef _NO_EXPR_ if (pState->m_pf_codehandle) { - resetVars(pState->m_pf_vars); if (pState->m_pf_codehandle) { - executeCode(pState->m_pf_codehandle); + NSEEL_code_execute(pState->m_pf_codehandle); } - resetVars(NULL); } #endif @@ -1435,8 +1443,6 @@ void CPlugin::WarpedBlitFromVS0ToVS1() else pState = m_pOldState; - resetVars(pState->m_pv_vars); - // cache the doubles as floats so that computations are a bit faster float fZoom = (float)(*pState->var_pf_zoom); float fZoomExp = (float)(*pState->var_pf_zoomexp); @@ -1499,7 +1505,7 @@ void CPlugin::WarpedBlitFromVS0ToVS1() //*pState->var_pv_treb_att = *pState->var_pv_treb_att; #ifndef _NO_EXPR_ - executeCode(pState->m_pp_codehandle); + NSEEL_code_execute(pState->m_pp_codehandle); #endif fZoom = (float)(*pState->var_pv_zoom); @@ -1584,7 +1590,6 @@ void CPlugin::WarpedBlitFromVS0ToVS1() pState->q_values_after_init_code[7] = *pState->var_pv_q8; */ - resetVars(NULL); } @@ -1676,9 +1681,7 @@ void CPlugin::DrawCustomShapes() #ifndef _NO_EXPR_ if (pState->m_shape[i].m_pf_codehandle) { - resetVars(pState->m_shape[i].m_pf_vars); - executeCode(pState->m_shape[i].m_pf_codehandle); - resetVars(NULL); + NSEEL_code_execute(pState->m_shape[i].m_pf_codehandle); } #endif @@ -1980,7 +1983,7 @@ void CPlugin::DrawCustomWaves() *pState->m_wave[i].var_pp_mid_att = *pState->m_wave[i].var_pf_mid_att; *pState->m_wave[i].var_pp_treb_att = *pState->m_wave[i].var_pf_treb_att; - executeCode(pState->m_wave[i].m_pf_codehandle); + NSEEL_code_execute(pState->m_wave[i].m_pf_codehandle); *pState->m_wave[i].var_pp_q1 = *pState->m_wave[i].var_pf_q1; *pState->m_wave[i].var_pp_q2 = *pState->m_wave[i].var_pf_q2; @@ -2001,10 +2004,6 @@ void CPlugin::DrawCustomWaves() // 2. for each point, execute per-point code - #ifndef _NO_EXPR_ - resetVars(pState->m_wave[i].m_pp_vars); - #endif - // to do: // -add any of the m_wave[i].xxx menu-accessible vars to the code? WFVERTEX v[512]; @@ -2025,7 +2024,7 @@ void CPlugin::DrawCustomWaves() *pState->m_wave[i].var_pp_a = *pState->m_wave[i].var_pf_a; #ifndef _NO_EXPR_ - executeCode(pState->m_wave[i].m_pp_codehandle); + NSEEL_code_execute(pState->m_wave[i].m_pp_codehandle); #endif v[j].x = (float)(*pState->m_wave[i].var_pp_x* 2-1);//*ASPECT; @@ -2037,10 +2036,6 @@ void CPlugin::DrawCustomWaves() v[j].b = COLOR_NORM(*pState->m_wave[i].var_pp_b); } - #ifndef _NO_EXPR_ - resetVars(NULL); - #endif - // save changes to t1-t8 this frame /* pState->m_wave[i].t_values_after_init_code[0] = *pState->m_wave[i].var_pp_t1; diff --git a/lib/vis_milkdrop/ns-eel2/CMakeLists.txt b/lib/vis_milkdrop/ns-eel2/CMakeLists.txt new file mode 100644 index 0000000..31a560c --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/CMakeLists.txt @@ -0,0 +1,26 @@ +project(ns-eel2) + +enable_language(C) + +cmake_minimum_required(VERSION 2.6) + +set(SOURCES ns-eel.h + ns-eel-addfuncs.h + ns-eel-int.h + nseel-caltab.c + nseel-cfunc.c + nseel-compiler.c + nseel-eval.c + nseel-lextab.c + nseel-ram.c + nseel-yylex.c) + +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + find_program(CMAKE_ASM_NASM_COMPILER NAMES nasm nasmw) + enable_language(ASM_NASM) + set(SOURCES ${SOURCES} + asm-nseel-x64.asm + ) +endif() + +add_library(ns-eel2 STATIC ${SOURCES}) diff --git a/lib/vis_milkdrop/ns-eel2/asm-nseel-arm-gcc.c b/lib/vis_milkdrop/ns-eel2/asm-nseel-arm-gcc.c new file mode 100644 index 0000000..7425de8 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/asm-nseel-arm-gcc.c @@ -0,0 +1,1382 @@ +#define FUNCTION_MARKER "mov r0, r0\n" \ + "mov r1, r1\n" \ + "mov r2, r2\n" + +#if EEL_F_SIZE == 8 + +void nseel_asm_1pdd(void) +{ + + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "str lr, [sp, #-8]!\n" + "blx r3\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: ); +} +void nseel_asm_1pdd_end(void){} + +void nseel_asm_2pdd(void) +{ + + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "fcpyd d1, d0\n" + "fldd d0, [r1]\n" + "str lr, [sp, #-8]!\n" + "blx r3\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: ); +}; +void nseel_asm_2pdd_end(void){} + +void nseel_asm_2pdds(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "push {r1, lr}\n" + "fcpyd d1, d0\n" + "fldd d0, [r1]\n" + "blx r3\n" + "pop {r0, lr}\n" + "fstd d0, [r0]\n" + FUNCTION_MARKER + :: ); +} +void nseel_asm_2pdds_end(void){} + +#else // 32 bit floating point calls + +#error no 32 bit float support + +#endif + +//--------------------------------------------------------------------------------------------------------------- + + + +// do nothing, eh +void nseel_asm_exec2(void) +{ + __asm__( + FUNCTION_MARKER + FUNCTION_MARKER + ); +} +void nseel_asm_exec2_end(void) { } + + + +void nseel_asm_invsqrt(void) +{ + __asm__( + FUNCTION_MARKER + "movw r0, 0x59df\n" + "movt r0, 0x5f37\n" + "fcvtsd s2, d0\n" + "fldd d3, [r6, #32]\n" + "fmrs r1, s2\n" + "fmuld d0, d0, d3\n" + "mov r1, r1, asr #1\n" + + "sub r0, r0, r1\n" + + "fmsr s4, r0\n" + "fcvtds d1, s4\n" + + "fldd d2, [r6, #40]\n" + "fmuld d0, d0, d1\n" + "fmuld d0, d0, d1\n" + "faddd d0, d0, d2\n" + "fmuld d0, d0, d1\n" + FUNCTION_MARKER + ); +} +void nseel_asm_invsqrt_end(void) {} + +void nseel_asm_dbg_getstackptr(void) +{ + __asm__( + FUNCTION_MARKER + "fmsr s0, sp\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_dbg_getstackptr_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_sqr(void) +{ + __asm__( + FUNCTION_MARKER + "fmuld d0, d0, d0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_sqr_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_abs(void) +{ + __asm__( + FUNCTION_MARKER + "fabsd d0, d0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_abs_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_assign(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d0, [r0]\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_assign_end(void) {} +// +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_assign_fromfp(void) +{ + __asm__( + FUNCTION_MARKER + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_assign_fromfp_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_assign_fast(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d0, [r0]\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_assign_fast_end(void) {} +// +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_assign_fast_fromfp(void) +{ + __asm__( + FUNCTION_MARKER + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_assign_fast_fromfp_end(void) {} + + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_add(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "faddd d0, d1, d0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_add_end(void) {} + +void nseel_asm_add_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "faddd d0, d1, d0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_add_op_end(void) {} + +void nseel_asm_add_op_fast(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "faddd d0, d1, d0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_add_op_fast_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_sub(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fsubd d0, d1, d0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_sub_end(void) {} + +void nseel_asm_sub_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fsubd d0, d1, d0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_sub_op_end(void) {} + +void nseel_asm_sub_op_fast(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fsubd d0, d1, d0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_sub_op_fast_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_mul(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fmuld d0, d0, d1\n" + FUNCTION_MARKER + ); +} +void nseel_asm_mul_end(void) {} + +void nseel_asm_mul_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fmuld d0, d0, d1\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_mul_op_end(void) {} + +void nseel_asm_mul_op_fast(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fmuld d0, d0, d1\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_mul_op_fast_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_div(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fdivd d0, d1, d0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_div_end(void) {} + +void nseel_asm_div_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fdivd d0, d1, d0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_div_op_end(void) {} + +void nseel_asm_div_op_fast(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fdivd d0, d1, d0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_div_op_fast_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_mod(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftouizd s0, d0\n" // round to unsigned integers + "fmrs r3, s0\n" + "fuitod d0, s0\n" // divisor + "ftouizd s2, d1\n" + + "cmp r3, #0\n" + "beq 0f\n" + + "fuitod d1, s2\n" // value + "fdivd d2, d1, d0\n" + "ftouizd s4, d2\n" + "fuitod d2, s4\n" + "fmuld d2, d2, d0\n" + "fsubd d0, d1, d2\n" + "0:\n" + FUNCTION_MARKER + ); +} +void nseel_asm_mod_end(void) {} + +void nseel_asm_shl(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "mov r3, r2, asl r3\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_shl_end(void) {} + +void nseel_asm_shr(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "mov r3, r2, asr r3\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_shr_end(void) {} + +void nseel_asm_mod_op(void) +{ + + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftouizd s0, d0\n" // round to unsigned integers + "fmrs r3, s0\n" + "fuitod d0, s0\n" // divisor + "ftouizd s2, d1\n" + + "cmp r3, #0\n" + "beq 0f\n" + + "fuitod d1, s2\n" // value + "fdivd d2, d1, d0\n" + "ftouizd s4, d2\n" + "fuitod d2, s4\n" + "fmuld d2, d2, d0\n" + "fsubd d0, d1, d2\n" + "0:\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); + +} +void nseel_asm_mod_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_or(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "orr r3, r3, r2\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_or_end(void) {} + +void nseel_asm_or0(void) +{ + __asm__( + FUNCTION_MARKER + "ftosizd s0, d0\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_or0_end(void) {} + +void nseel_asm_or_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "orr r3, r3, r2\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_or_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_xor(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "eor r3, r3, r2\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_xor_end(void) {} + +void nseel_asm_xor_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "eor r3, r3, r2\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_xor_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_and(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "and r3, r3, r2\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + FUNCTION_MARKER + );} +void nseel_asm_and_end(void) {} + +void nseel_asm_and_op(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "ftosizd s0, d0\n" + "ftosizd s1, d1\n" + "fmrs r3, s0\n" + "fmrs r2, s1\n" + "and r3, r3, r2\n" + "fmsr s0, r3\n" + "fsitod d0, s0\n" + "mov r0, r1\n" + "fstd d0, [r1]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_and_op_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_uplus(void) // this is the same as doing nothing, it seems +{ + __asm__( + FUNCTION_MARKER + FUNCTION_MARKER + ); +} +void nseel_asm_uplus_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_uminus(void) +{ + __asm__( + FUNCTION_MARKER + "fnegd d0, d0\n" + FUNCTION_MARKER + ); +} +void nseel_asm_uminus_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_sign(void) +{ + __asm__( + FUNCTION_MARKER + "fcmpzd d0\n" + "fmstat\n" + "flddgt d0, [r6, #16]\n" + "flddlt d0, [r6, #24]\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_sign_end(void) {} + + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_bnot(void) +{ + __asm__( + FUNCTION_MARKER + "cmp r0, #0\n" + "movne r0, #0\n" + "moveq r0, #1\n" + FUNCTION_MARKER + ); +} +void nseel_asm_bnot_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_if(void) +{ + __asm__( + FUNCTION_MARKER + "str lr, [sp, #-8]!\n" + "movw r1, 0xdead\n" + "movt r1, 0xbeef\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "cmp r0, #0\n" + "moveq r1, r2\n" + "blx r1\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: ); +} +void nseel_asm_if_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_repeat(void) +{ +#if NSEEL_LOOPFUNC_SUPPORT_MAXLEN > 0 + __asm__( + FUNCTION_MARKER + "ftosizd s0, d0\n" + "fmrs r3, s0\n" + "cmp r3, #0\n" + "ble 0f\n" + "movw r2, %0\n" + "movt r2, %1\n" + "cmp r3, r2\n" + "movgt r3, r2\n" + "push {r10,lr}\n" + + "movw r10, 0xdead\n" + "movt r10, 0xbeef\n" + "1:\n" + "push {r3,r5}\n" // save counter + worktable + "blx r10\n" + "pop {r3,r5}\n" + "sub r3, r3, #1\n" + "cmp r3, #0\n" + "bgt 1b\n" + "pop {r10,lr}\n" + + "0:\n" + FUNCTION_MARKER + ::"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN&65535), + "g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN>>16) + ); +#else + __asm__( + FUNCTION_MARKER + "ftosizd s0, d0\n" + "fmrs r3, s0\n" + "cmp r3, #0\n" + "ble 0f\n" + "push {r10,lr}\n" + + "movw r10, 0xdead\n" + "movt r10, 0xbeef\n" + "1:\n" + "push {r3,r5}\n" // save counter + worktable + "blx r10\n" + "pop {r3,r5}\n" + "sub r3, r3, #1\n" + "cmp r3, #0\n" + "bgt 1b\n" + "pop {r10,lr}\n" + + "0:\n" + FUNCTION_MARKER + ); +#endif +} +void nseel_asm_repeat_end(void) {} + +void nseel_asm_repeatwhile(void) +{ +#if NSEEL_LOOPFUNC_SUPPORT_MAXLEN > 0 + __asm__( + FUNCTION_MARKER + "movw r3, %0\n" + "movt r3, %1\n" + "push {r10,lr}\n" + + "movw r10, 0xdead\n" + "movt r10, 0xbeef\n" + "0:\n" + "push {r3,r5}\n" // save counter + worktable + "blx r10\n" + "pop {r3,r5}\n" + "sub r3, r3, #1\n" + "cmp r0, #0\n" + "cmpne r3, #0\n" + "bne 0b\n" + "pop {r10,lr}\n" + + FUNCTION_MARKER + ::"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN&65535), + "g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN>>16) + ); +#else + __asm__( + FUNCTION_MARKER + "push {r10,lr}\n" + + "movw r10, 0xdead\n" + "movt r10, 0xbeef\n" + "0:\n" + "push {r3,r5}\n" // save worktable (r3 just for alignment) + "blx r10\n" + "pop {r3,r5}\n" + "cmp r0, #0\n" + "bne 0b\n" + "pop {r10,lr}\n" + + "0:\n" + FUNCTION_MARKER + ); +#endif +} +void nseel_asm_repeatwhile_end(void) {} + + +void nseel_asm_band(void) +{ + __asm__( + FUNCTION_MARKER + "cmp r0, #0\n" + "beq 0f\n" + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "push {r3, lr}\n" + "blx r3\n" + "pop {r3, lr}\n" + "0:\n" + FUNCTION_MARKER + :: ); +} +void nseel_asm_band_end(void) {} + +void nseel_asm_bor(void) +{ + __asm__( + FUNCTION_MARKER + "cmp r0, #0\n" + "bne 0f\n" + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "push {r3, lr}\n" + "blx r3\n" + "pop {r3, lr}\n" + "0:\n" + FUNCTION_MARKER + :: ); +} +void nseel_asm_bor_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_equal(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fldd d2, [r6]\n" + "fsubd d0, d0, d1\n" + "fabsd d0, d0\n" + "fcmpd d2, d0\n" + "fmstat\n" + "movlt r0, #0\n" + "movge r0, #1\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_equal_end(void) {} +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_equal_exact(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d0, d1\n" + "fmstat\n" + "movne r0, #0\n" + "moveq r0, #1\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_equal_exact_end(void) {} +// +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_notequal_exact(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d0, d1\n" + "fmstat\n" + "moveq r0, #0\n" + "movne r0, #1\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_notequal_exact_end(void) {} +// +// +// +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_notequal(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fldd d2, [r6]\n" + "fsubd d0, d0, d1\n" + "fabsd d0, d0\n" + "fcmpd d2, d0\n" + "fmstat\n" + "movlt r0, #1\n" + "movge r0, #0\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_notequal_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_below(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "movlt r0, #1\n" + "movge r0, #0\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_below_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_beloweq(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "movle r0, #1\n" + "movgt r0, #0\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_beloweq_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_above(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "movgt r0, #1\n" + "movle r0, #0\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_above_end(void) {} + +void nseel_asm_aboveeq(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "movge r0, #1\n" + "movlt r0, #0\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_aboveeq_end(void) {} + + + +void nseel_asm_min(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d0, [r0]\n" + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "movlt r0, r1\n" + FUNCTION_MARKER + ); +} +void nseel_asm_min_end(void) {} + +void nseel_asm_max(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d0, [r0]\n" + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "movge r0, r1\n" + FUNCTION_MARKER + ); +} + +void nseel_asm_max_end(void) {} + + +void nseel_asm_min_fp(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "fcpydlt d0, d1\n" + FUNCTION_MARKER + ); +} +void nseel_asm_min_fp_end(void) {} + +void nseel_asm_max_fp(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r1]\n" + "fcmpd d1, d0\n" + "fmstat\n" + "fcpydge d0, d1\n" + FUNCTION_MARKER + ); +} + +void nseel_asm_max_fp_end(void) {} + + + + + + +void _asm_generic3parm(void) +{ + __asm__( + FUNCTION_MARKER + "push {r4, lr}\n" // input: r0 last, r1=second to last, r2=third to last + // output: r0=context, r1=r2, r2=r1, r3=r0 + "mov r3, r0\n" // r0 (last parameter) -> r3 + "mov r4, r1\n" // r1 (second to last parameter) r1->r4->r2 + + "movw r0, 0xdead\n" // r0 is first parm (context) + "movt r0, 0xbeef\n" + + "mov r1, r2\n" // r2->r1 + "mov r2, r4\n" // r1->r2 + + "movw r4, 0xdead\n" + "movt r4, 0xbeef\n" + + "blx r4\n" + "pop {r4, lr}\n" + FUNCTION_MARKER + :: + ); +} +void _asm_generic3parm_end(void) {} + +void _asm_generic3parm_retd(void) +{ + __asm__( + FUNCTION_MARKER + "push {r4, lr}\n" // input: r0 last, r1=second to last, r2=third to last + // output: r0=context, r1=r2, r2=r1, r3=r0 + "mov r3, r0\n" // r0 (last parameter) -> r3 + "mov r4, r1\n" // r1 (second to last parameter) r1->r4->r2 + + "movw r0, 0xdead\n" // r0 is first parm (context) + "movt r0, 0xbeef\n" + + "mov r1, r2\n" // r2->r1 + "mov r2, r4\n" // r1->r2 + + "movw r4, 0xdead\n" + "movt r4, 0xbeef\n" + + "blx r4\n" + "pop {r4, lr}\n" + FUNCTION_MARKER + :: + ); +} +void _asm_generic3parm_retd_end(void) {} + + +void _asm_generic2parm(void) +{ + __asm__( + FUNCTION_MARKER + "str lr, [sp, #-8]!\n" + "mov r2, r0\n" // r0 -> r2, r1-r1, + "movw r0, 0xdead\n" // r0 is first parm + "movt r0, 0xbeef\n" + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "blx r3\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: + ); +} +void _asm_generic2parm_end(void) {} + + +void _asm_generic2parm_retd(void) +{ + __asm__( + FUNCTION_MARKER + "str lr, [sp, #-8]!\n" + "mov r2, r0\n" // r0 -> r2, r1-r1, + "movw r0, 0xdead\n" // r0 is first parm + "movt r0, 0xbeef\n" + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "blx r3\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: + ); +} +void _asm_generic2parm_retd_end(void) {} + +void _asm_generic1parm(void) +{ + __asm__( + FUNCTION_MARKER + "str lr, [sp, #-8]!\n" + "mov r1, r0\n" // r0 -> r1 + "movw r0, 0xdead\n" // r0 is first parm + "movt r0, 0xbeef\n" + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "blx r3\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: + ); +} +void _asm_generic1parm_end(void) {} + + + +void _asm_generic1parm_retd(void) +{ + __asm__( + FUNCTION_MARKER + "str lr, [sp, #-8]!\n" + "mov r1, r0\n" // r0 -> r1 + "movw r0, 0xdead\n" // r0 is first parm + "movt r0, 0xbeef\n" + "movw r3, 0xdead\n" + "movt r3, 0xbeef\n" + "blx r3\n" + "ldr lr, [sp], #8\n" + FUNCTION_MARKER + :: + ); +} +void _asm_generic1parm_retd_end(void) {} + + + + +void _asm_megabuf(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r7, #-8]\n" + "faddd d0, d0, d1\n" + "ftouizd s0, d0\n" + "fmrs r3, s0\n" // r3 is slot index + "mov r2, r3, asr %0\n" + "bic r2, r2, #7\n" // r2 is page index*8 + "cmp r2, %1\n" + "bge 0f\n" + + "add r2, r2, r7\n" + "ldr r2, [r2]\n" + "cmp r2, #0\n" + "beq 0f\n" + + "movw r0, %2\n" + "and r3, r3, r0\n" // r3 mask item in slot + "add r0, r2, r3, asl #3\n" // set result + "b 1f\n" + "0:\n" + + // failed, call stub function + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "str lr, [sp, #-8]!\n" + "mov r0, r7\n" // first parameter: blocks + "mov r1, r3\n" // second parameter: slot index + "blx r2\n" + "ldr lr, [sp], #8\n" + + "1:\n" + + FUNCTION_MARKER + :: + "i" (NSEEL_RAM_ITEMSPERBLOCK_LOG2 - 3/*log2(sizeof(EEL_F))*/), + "i" (NSEEL_RAM_BLOCKS*8), + "i" (NSEEL_RAM_ITEMSPERBLOCK-1) + ); +} + +void _asm_megabuf_end(void) {} + +void _asm_gmegabuf(void) +{ + __asm__( + FUNCTION_MARKER + "movw r0, 0xdead\n" + "movt r0, 0xbeef\n" + + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + + "fldd d1, [r7, #-8]\n" + "faddd d0, d0, d1\n" + "ftouizd s0, d0\n" + "fmrs r1, s0\n" // r1 is slot index + + "push {r4, lr}\n" + + "blx r2\n" + + "pop {r4, lr}\n" + + FUNCTION_MARKER + :: + ); +} + +void _asm_gmegabuf_end(void) {} + +void nseel_asm_fcall(void) +{ + __asm__( + FUNCTION_MARKER + "movw r0, 0xdead\n" + "movt r0, 0xbeef\n" + "push {r4, lr}\n" + "blx r0\n" + "pop {r4, lr}\n" + FUNCTION_MARKER + ); +} +void nseel_asm_fcall_end(void) {} + + + +void nseel_asm_stack_push(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d0, [r0]\n" + + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + "ldr r0, [r3]\n" + + "add r0, r0, #8\n" + + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "and r0, r0, r2\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "orr r0, r0, r2\n" + + "str r0, [r3]\n" + "fstd d0, [r0]\n" + + FUNCTION_MARKER + ); +} +void nseel_asm_stack_push_end(void) {} + +void nseel_asm_stack_pop(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + "ldr r1, [r3]\n" + "fldd d0, [r1]\n" + "sub r1, r1, #8\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "fstd d0, [r0]\n" + "and r1, r1, r2\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "orr r1, r1, r2\n" + + "str r1, [r3]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_stack_pop_end(void) {} + + + +void nseel_asm_stack_pop_fast(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + "ldr r1, [r3]\n" + "mov r0, r1\n" + "sub r1, r1, #8\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "and r1, r1, r2\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "orr r1, r1, r2\n" + "str r1, [r3]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_stack_pop_fast_end(void) {} + +void nseel_asm_stack_peek(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + + "ftosizd s0, d0\n" + "fmrs r2, s0\n" // r2 is index in stack + + "ldr r1, [r3]\n" + "sub r1, r1, r2, asl #3\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "and r1, r1, r2\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "orr r0, r1, r2\n" + FUNCTION_MARKER + ); +} +void nseel_asm_stack_peek_end(void) {} + + +void nseel_asm_stack_peek_top(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + "ldr r0, [r3]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_stack_peek_top_end(void) {} + + +void nseel_asm_stack_peek_int(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + + "movw r2, 0xdead\n" // r3 is stack + "movt r2, 0xbeef\n" + + "ldr r1, [r3]\n" + "sub r1, r1, r2\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "and r1, r1, r2\n" + "movw r2, 0xdead\n" + "movt r2, 0xbeef\n" + "orr r0, r1, r2\n" + FUNCTION_MARKER + ); +} +void nseel_asm_stack_peek_int_end(void) {} + +void nseel_asm_stack_exch(void) +{ + __asm__( + FUNCTION_MARKER + "movw r3, 0xdead\n" // r3 is stack + "movt r3, 0xbeef\n" + "ldr r1, [r3]\n" + "fldd d0, [r0]\n" + "fldd d1, [r1]\n" + "fstd d0, [r1]\n" + "fstd d1, [r0]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_stack_exch_end(void) {} + + +void nseel_asm_booltofp(void) +{ + __asm__( + FUNCTION_MARKER + "cmp r0, #0\n" + "flddne d0, [r6, #16]\n" + "flddeq d0, [r6, #8]\n" + FUNCTION_MARKER + ); +} +void nseel_asm_booltofp_end(void){ } + +void nseel_asm_fptobool(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r6]\n" + "fabsd d0, d0\n" + "fcmpd d0, d1\n" + "fmstat\n" + "movgt r0, #1\n" + "movlt r0, #0\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_fptobool_end(void){ } + +void nseel_asm_fptobool_rev(void) +{ + __asm__( + FUNCTION_MARKER + "fldd d1, [r6]\n" + "fabsd d0, d0\n" + "fcmpd d0, d1\n" + "fmstat\n" + "movgt r0, #0\n" + "movlt r0, #1\n" + FUNCTION_MARKER + :: + ); +} +void nseel_asm_fptobool_rev_end(void){ } + diff --git a/lib/vis_milkdrop/ns-eel2/asm-nseel-arm.asm b/lib/vis_milkdrop/ns-eel2/asm-nseel-arm.asm new file mode 100644 index 0000000..007f156 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/asm-nseel-arm.asm @@ -0,0 +1,1381 @@ +%define FUNCTION_MARKER "mov r0, r0\nmov r1, r1\nmov r2, r2 + +global nseel_asm_1pdd +nseel_asm_1pdd: + FUNCTION_MARKER + movw r3, 0xdead + movt r3, 0xbeef + str lr, [sp, #-8]! + blx r3 + ldr lr, [sp], #8 + FUNCTION_MARKER + +global nseel_asm_1pdd_end +nseel_asm_1pdd_end: + + +global nseel_asm_2pdd +nseel_asm_2pdd: + FUNCTION_MARKER + movw r3, 0xdead + movt r3, 0xbeef + fcpyd d1, d0 + fldd d0, [r1] + str lr, [sp, #-8]! + blx r3 + ldr lr, [sp], #8 + FUNCTION_MARKER + +global nseel_asm_2pdd_end +nseel_asm_2pdd_end: + + +global nseel_asm_2pdds +nseel_asm_2pdds: + + FUNCTION_MARKER + movw r3, 0xdead + movt r3, 0xbeef + push r1, lr + fcpyd d1, d0 + fldd d0, [r1] + blx r3 + pop r0, lr + fstd d0, [r0] + FUNCTION_MARKER + +global nseel_asm_2pdds_end +nseel_asm_2pdds_end: + + +//--------------------------------------------------------------------------------------------------------------- + + +// do nothing, eh +global nseel_asm_exec2 +nseel_asm_exec2: + FUNCTION_MARKER + FUNCTION_MARKER + +global nseel_asm_exec2_end +nseel_asm_exec2_end: + + +global nseel_asm_invsqrt +nseel_asm_invsqrt: + FUNCTION_MARKER + movw r0, 0x59df + movt r0, 0x5f37 + fcvtsd s2, d0 + fldd d3, [r6, #32] + fmrs r1, s2 + fmuld d0, d0, d3 + mov r1, r1, asr #1 + + sub r0, r0, r1 + + fmsr s4, r0 + fcvtds d1, s4 + + fldd d2, [r6, #40] + fmuld d0, d0, d1 + fmuld d0, d0, d1 + faddd d0, d0, d2 + fmuld d0, d0, d1 + FUNCTION_MARKER + +global nseel_asm_invsqrt_end +nseel_asm_invsqrt_end: + + +global nseel_asm_dbg_getstackptr +nseel_asm_dbg_getstackptr: + FUNCTION_MARKER + fmsr s0, sp + fsitod d0, s0 + FUNCTION_MARKER + +global nseel_asm_dbg_getstackptr_end +nseel_asm_dbg_getstackptr_end: + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_sqr +nseel_asm_sqr: + FUNCTION_MARKER + fmuld d0, d0, d0 + FUNCTION_MARKER + +global nseel_asm_sqr_end +nseel_asm_sqr_end: + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_abs +nseel_asm_abs: + FUNCTION_MARKER + fabsd d0, d0 + FUNCTION_MARKER + +global nseel_asm_abs_end +nseel_asm_abs_end: + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_assign + FUNCTION_MARKER + fldd d0, [r0] + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + +global nseel_asm_assign_end +nseel_asm_assign_end: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_assign_fromfp +nseel_asm_assign_fromfp: + FUNCTION_MARKER + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + +global nseel_asm_assign_fromfp_end +nseel_asm_assign_fromfp_end: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_assign_fast +nseel_asm_assign_fast: + + FUNCTION_MARKER + fldd d0, [r0] + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + +global nseel_asm_assign_fast_endglobal +nseel_asm_assign_fast_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_assign_fast_fromfp +nseel_asm_assign_fast_fromfp: + + FUNCTION_MARKER + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_assign_fast_fromfp_endglobal +nseel_asm_assign_fast_fromfp_endglobal: + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_add +nseel_asm_add: + + FUNCTION_MARKER + fldd d1, [r1] + faddd d0, d1, d0 + FUNCTION_MARKER + + +global nseel_asm_add_endglobal +nseel_asm_add_endglobal: + +global nseel_asm_add_op +nseel_asm_add_op: + + FUNCTION_MARKER + fldd d1, [r1] + faddd d0, d1, d0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_add_op_endglobal +nseel_asm_add_op_endglobal: + +global nseel_asm_add_op_fast +nseel_asm_add_op_fast: + + FUNCTION_MARKER + fldd d1, [r1] + faddd d0, d1, d0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_add_op_fast_endglobal +nseel_asm_add_op_fast_endglobal: + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_sub +nseel_asm_sub: + + FUNCTION_MARKER + fldd d1, [r1] + fsubd d0, d1, d0 + FUNCTION_MARKER + + +global nseel_asm_sub_endglobal +nseel_asm_sub_endglobal: + +global nseel_asm_sub_op +nseel_asm_sub_op: + + FUNCTION_MARKER + fldd d1, [r1] + fsubd d0, d1, d0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_sub_op_endglobal +nseel_asm_sub_op_endglobal: + +global nseel_asm_sub_op_fast +nseel_asm_sub_op_fast: + + FUNCTION_MARKER + fldd d1, [r1] + fsubd d0, d1, d0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_sub_op_fast_endglobal +nseel_asm_sub_op_fast_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_mul +nseel_asm_mul: + + FUNCTION_MARKER + fldd d1, [r1] + fmuld d0, d0, d1 + FUNCTION_MARKER + + +global nseel_asm_mul_endglobal +nseel_asm_mul_endglobal: + +global nseel_asm_mul_op +nseel_asm_mul_op: + + FUNCTION_MARKER + fldd d1, [r1] + fmuld d0, d0, d1 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_mul_op_endglobal +nseel_asm_mul_op_endglobal: + +global nseel_asm_mul_op_fast +nseel_asm_mul_op_fast: + + FUNCTION_MARKER + fldd d1, [r1] + fmuld d0, d0, d1 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_mul_op_fast_endglobal +nseel_asm_mul_op_fast_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_div +nseel_asm_div: + + FUNCTION_MARKER + fldd d1, [r1] + fdivd d0, d1, d0 + FUNCTION_MARKER + + +global nseel_asm_div_endglobal +nseel_asm_div_endglobal: + +global nseel_asm_div_op +nseel_asm_div_op: + + FUNCTION_MARKER + fldd d1, [r1] + fdivd d0, d1, d0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + +global nseel_asm_div_op_endglobal +nseel_asm_div_op_endglobal: + +global nseel_asm_div_op_fast +nseel_asm_div_op_fast: + + FUNCTION_MARKER + fldd d1, [r1] + fdivd d0, d1, d0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_div_op_fast_endglobal +nseel_asm_div_op_fast_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_mod +nseel_asm_mod: + + FUNCTION_MARKER + fldd d1, [r1] + ftouizd s0, d0 // round to unsigned integers + fmrs r3, s0 + fuitod d0, s0 // divisor + ftouizd s2, d1 + + cmp r3, #0 + beq 0f + + fuitod d1, s2 // value + fdivd d2, d1, d0 + ftouizd s4, d2 + fuitod d2, s4 + fmuld d2, d2, d0 + fsubd d0, d1, d2 + 0: + FUNCTION_MARKER + + +global nseel_asm_mod_endglobal +nseel_asm_mod_endglobal: + +global nseel_asm_shl +nseel_asm_shl: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + mov r3, r2, asl r3 + fmsr s0, r3 + fsitod d0, s0 + FUNCTION_MARKER + + +global nseel_asm_shl_endglobal +nseel_asm_shl_endglobal: + +global nseel_asm_shr +nseel_asm_shr: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + mov r3, r2, asr r3 + fmsr s0, r3 + fsitod d0, s0 + FUNCTION_MARKER + + +global nseel_asm_shr_endglobal +nseel_asm_shr_endglobal: + +global nseel_asm_mod_op +nseel_asm_mod_op: + + FUNCTION_MARKER + fldd d1, [r1] + ftouizd s0, d0 // round to unsigned integers + fmrs r3, s0 + fuitod d0, s0 // divisor + ftouizd s2, d1 + + cmp r3, #0 + beq 0f + + fuitod d1, s2 // value + fdivd d2, d1, d0 + ftouizd s4, d2 + fuitod d2, s4 + fmuld d2, d2, d0 + fsubd d0, d1, d2 + 0: + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_mod_op_endglobal +nseel_asm_mod_op_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_or +nseel_asm_or: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + orr r3, r3, r2 + fmsr s0, r3 + fsitod d0, s0 + FUNCTION_MARKER + + +global nseel_asm_or_endglobal +nseel_asm_or_endglobal: + +global nseel_asm_or0 +nseel_asm_or0: + + FUNCTION_MARKER + ftosizd s0, d0 + fsitod d0, s0 + FUNCTION_MARKER + + +global nseel_asm_or0_endglobal +nseel_asm_or0_endglobal: + +global nseel_asm_or_op +nseel_asm_or_op: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + orr r3, r3, r2 + fmsr s0, r3 + fsitod d0, s0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_or_op_endglobal +nseel_asm_or_op_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_xor +nseel_asm_xor: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + eor r3, r3, r2 + fmsr s0, r3 + fsitod d0, s0 + FUNCTION_MARKER + + +global nseel_asm_xor_endglobal +nseel_asm_xor_endglobal: + +global nseel_asm_xor_op +nseel_asm_xor_op: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + eor r3, r3, r2 + fmsr s0, r3 + fsitod d0, s0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_xor_op_endglobal +nseel_asm_xor_op_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_and +nseel_asm_and: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + and r3, r3, r2 + fmsr s0, r3 + fsitod d0, s0 + FUNCTION_MARKER + +global nseel_asm_and_endglobal +nseel_asm_and_endglobal: + +global nseel_asm_and_op +nseel_asm_and_op: + + FUNCTION_MARKER + fldd d1, [r1] + ftosizd s0, d0 + ftosizd s1, d1 + fmrs r3, s0 + fmrs r2, s1 + and r3, r3, r2 + fmsr s0, r3 + fsitod d0, s0 + mov r0, r1 + fstd d0, [r1] + FUNCTION_MARKER + + +global nseel_asm_and_op_endglobal +nseel_asm_and_op_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_uplus // this is the same as doing nothing, it seems +nseel_asm_uplus: + + FUNCTION_MARKER + FUNCTION_MARKER + + +global nseel_asm_uplus_endglobal +nseel_asm_uplus_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_uminus +nseel_asm_uminus: + + FUNCTION_MARKER + fnegd d0, d0 + FUNCTION_MARKER + + +global nseel_asm_uminus_endglobal +nseel_asm_uminus_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_sign +nseel_asm_sign: + + FUNCTION_MARKER + fcmpzd d0 + fmstat + flddgt d0, [r6, #16] + flddlt d0, [r6, #24] + FUNCTION_MARKER + + +global nseel_asm_sign_endglobal +nseel_asm_sign_endglobal: + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_bnot +nseel_asm_bnot: + + FUNCTION_MARKER + cmp r0, #0 + movne r0, #0 + moveq r0, #1 + FUNCTION_MARKER + +global nseel_asm_bnot_endglobal +nseel_asm_bnot_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_if +nseel_asm_if: + + FUNCTION_MARKER + str lr, [sp, #-8]! + movw r1, 0xdead + movt r1, 0xbeef + movw r2, 0xdead + movt r2, 0xbeef + cmp r0, #0 + moveq r1, r2 + blx r1 + ldr lr, [sp], #8 + FUNCTION_MARKER + +global nseel_asm_if_endglobal +nseel_asm_if_endglobal: + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_repeat +nseel_asm_repeat: +%if NSEEL_LOOPFUNC_SUPPORT_MAXLEN > 0 + + FUNCTION_MARKER + ftosizd s0, d0 + fmrs r3, s0 + cmp r3, #0 + ble 0f + movw r2, %0 + movt r2, %1 + cmp r3, r2 + movgt r3, r2 + push r10,lr + + movw r10, 0xdead + movt r10, 0xbeef + 1: + push r3,r5 // save counter + worktable + blx r10 + pop r3,r5 + sub r3, r3, #1 + cmp r3, #0 + bgt 1b + pop r10,lr + + 0: + FUNCTION_MARKER +"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN&65535), + g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN>>16) + +%else + + FUNCTION_MARKER + ftosizd s0, d0 + fmrs r3, s0 + cmp r3, #0 + ble 0f + push r10,lr + + movw r10, 0xdead + movt r10, 0xbeef + 1: + push r3,r5 // save counter + worktable + blx r10 + pop r3,r5 + sub r3, r3, #1 + cmp r3, #0 + bgt 1b + pop r10,lr + + 0: + FUNCTION_MARKER + +%endif + +global nseel_asm_repeat_endglobal + +global nseel_asm_repeatwhile + +%if NSEEL_LOOPFUNC_SUPPORT_MAXLEN > 0 + + FUNCTION_MARKER + movw r3, %0 + movt r3, %1 + push r10,lr + + movw r10, 0xdead + movt r10, 0xbeef + 0: + push r3,r5 // save counter + worktable + blx r10 + pop r3,r5 + sub r3, r3, #1 + cmp r0, #0 + cmpne r3, #0 + bne 0b + pop r10,lr + + FUNCTION_MARKER +"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN&65535), + g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN>>16) + +%else + + FUNCTION_MARKER + push r10,lr + + movw r10, 0xdead + movt r10, 0xbeef + 0: + push r3,r5 // save worktable (r3 just for alignment) + blx r10 + pop r3,r5 + cmp r0, #0 + bne 0b + pop r10,lr + + 0: + FUNCTION_MARKER + +%endif + +global nseel_asm_repeatwhile_endglobal + + +global nseel_asm_band + + + FUNCTION_MARKER + cmp r0, #0 + beq 0f + movw r3, 0xdead + movt r3, 0xbeef + push r3, lr + blx r3 + pop r3, lr + 0: + FUNCTION_MARKER + + +global nseel_asm_band_endglobal + +global nseel_asm_bor + + + FUNCTION_MARKER + cmp r0, #0 + bne 0f + movw r3, 0xdead + movt r3, 0xbeef + push r3, lr + blx r3 + pop r3, lr + 0: + FUNCTION_MARKER + + +global nseel_asm_bor_endglobal + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_equal + + + FUNCTION_MARKER + fldd d1, [r1] + fldd d2, [r6] + fsubd d0, d0, d1 + fabsd d0, d0 + fcmpd d2, d0 + fmstat + movlt r0, #0 + movge r0, #1 + FUNCTION_MARKER + + + +global nseel_asm_equal_endglobal +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_equal_exact + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d0, d1 + fmstat + movne r0, #0 + moveq r0, #1 + FUNCTION_MARKER + + + +global nseel_asm_equal_exact_endglobal +// +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_notequal_exact + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d0, d1 + fmstat + moveq r0, #0 + movne r0, #1 + FUNCTION_MARKER + + + +global nseel_asm_notequal_exact_endglobal +// +// +// +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_notequal + + + FUNCTION_MARKER + fldd d1, [r1] + fldd d2, [r6] + fsubd d0, d0, d1 + fabsd d0, d0 + fcmpd d2, d0 + fmstat + movlt r0, #1 + movge r0, #0 + FUNCTION_MARKER + + + +global nseel_asm_notequal_endglobal + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_below + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d1, d0 + fmstat + movlt r0, #1 + movge r0, #0 + FUNCTION_MARKER + + + +global nseel_asm_below_endglobal + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_beloweq + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d1, d0 + fmstat + movle r0, #1 + movgt r0, #0 + FUNCTION_MARKER + + + +global nseel_asm_beloweq_endglobal + + +//--------------------------------------------------------------------------------------------------------------- +global nseel_asm_above + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d1, d0 + fmstat + movgt r0, #1 + movle r0, #0 + FUNCTION_MARKER + + + +global nseel_asm_above_endglobal + +global nseel_asm_aboveeq + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d1, d0 + fmstat + movge r0, #1 + movlt r0, #0 + FUNCTION_MARKER + + + +global nseel_asm_aboveeq_endglobal + + + +global nseel_asm_min + + + FUNCTION_MARKER + fldd d0, [r0] + fldd d1, [r1] + fcmpd d1, d0 + fmstat + movlt r0, r1 + FUNCTION_MARKER + + +global nseel_asm_min_endglobal + +global nseel_asm_max + + + FUNCTION_MARKER + fldd d0, [r0] + fldd d1, [r1] + fcmpd d1, d0 + fmstat + movge r0, r1 + FUNCTION_MARKER + + + +global nseel_asm_max_endglobal + + +global nseel_asm_min_fp + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d1, d0 + fmstat + fcpydlt d0, d1 + FUNCTION_MARKER + + +global nseel_asm_min_fp_endglobal + +global nseel_asm_max_fp + + + FUNCTION_MARKER + fldd d1, [r1] + fcmpd d1, d0 + fmstat + fcpydge d0, d1 + FUNCTION_MARKER + + + +global nseel_asm_max_fp_endglobal + + + + + + +global _asm_generic3parm + + + FUNCTION_MARKER + push r4, lr // input: r0 last, r1=second to last, r2=third to last + // output: r0=context, r1=r2, r2=r1, r3=r0 + mov r3, r0 // r0 (last parameter) -> r3 + mov r4, r1 // r1 (second to last parameter) r1->r4->r2 + + movw r0, 0xdead // r0 is first parm (context) + movt r0, 0xbeef + + mov r1, r2 // r2->r1 + mov r2, r4 // r1->r2 + + movw r4, 0xdead + movt r4, 0xbeef + + blx r4 + pop r4, lr + FUNCTION_MARKER + :: + ); + +global _asm_generic3parm_endglobal + +global _asm_generic3parm_retd + + + FUNCTION_MARKER + push r4, lr // input: r0 last, r1=second to last, r2=third to last + // output: r0=context, r1=r2, r2=r1, r3=r0 + mov r3, r0 // r0 (last parameter) -> r3 + mov r4, r1 // r1 (second to last parameter) r1->r4->r2 + + movw r0, 0xdead // r0 is first parm (context) + movt r0, 0xbeef + + mov r1, r2 // r2->r1 + mov r2, r4 // r1->r2 + + movw r4, 0xdead + movt r4, 0xbeef + + blx r4 + pop r4, lr + FUNCTION_MARKER + :: + ); + +global _asm_generic3parm_retd_endglobal + + +global _asm_generic2parm + + + FUNCTION_MARKER + str lr, [sp, #-8]! + mov r2, r0 // r0 -> r2, r1-r1, + movw r0, 0xdead // r0 is first parm + movt r0, 0xbeef + movw r3, 0xdead + movt r3, 0xbeef + blx r3 + ldr lr, [sp], #8 + FUNCTION_MARKER + :: + ); + +global _asm_generic2parm_endglobal + + +global _asm_generic2parm_retd + + + FUNCTION_MARKER + str lr, [sp, #-8]! + mov r2, r0 // r0 -> r2, r1-r1, + movw r0, 0xdead // r0 is first parm + movt r0, 0xbeef + movw r3, 0xdead + movt r3, 0xbeef + blx r3 + ldr lr, [sp], #8 + FUNCTION_MARKER + :: + ); + +global _asm_generic2parm_retd_endglobal + +global _asm_generic1parm + + + FUNCTION_MARKER + str lr, [sp, #-8]! + mov r1, r0 // r0 -> r1 + movw r0, 0xdead // r0 is first parm + movt r0, 0xbeef + movw r3, 0xdead + movt r3, 0xbeef + blx r3 + ldr lr, [sp], #8 + FUNCTION_MARKER + :: + ); + +global _asm_generic1parm_endglobal + + + +global _asm_generic1parm_retd + + + FUNCTION_MARKER + str lr, [sp, #-8]! + mov r1, r0 // r0 -> r1 + movw r0, 0xdead // r0 is first parm + movt r0, 0xbeef + movw r3, 0xdead + movt r3, 0xbeef + blx r3 + ldr lr, [sp], #8 + FUNCTION_MARKER + :: + ); + +global _asm_generic1parm_retd_endglobal + + + + +global _asm_megabuf + + + FUNCTION_MARKER + fldd d1, [r7, #-8] + faddd d0, d0, d1 + ftouizd s0, d0 + fmrs r3, s0 // r3 is slot index + mov r2, r3, asr %0 + bic r2, r2, #7 // r2 is page index*8 + cmp r2, %1 + bge 0f + + add r2, r2, r7 + ldr r2, [r2] + cmp r2, #0 + beq 0f + + movw r0, %2 + and r3, r3, r0 // r3 mask item in slot + add r0, r2, r3, asl #3 // set result + b 1f + 0: + + // failed, call stub function + movw r2, 0xdead + movt r2, 0xbeef + str lr, [sp, #-8]! + mov r0, r7 // first parameter: blocks + mov r1, r3 // second parameter: slot index + blx r2 + ldr lr, [sp], #8 + + 1: + + FUNCTION_MARKER + :: + i" (NSEEL_RAM_ITEMSPERBLOCK_LOG2 - 3/*log2(sizeof(EEL_F))*/), + i" (NSEEL_RAM_BLOCKS*8), + i" (NSEEL_RAM_ITEMSPERBLOCK-1) + ); + + +global _asm_megabuf_endglobal + +global _asm_gmegabuf + + + FUNCTION_MARKER + movw r0, 0xdead + movt r0, 0xbeef + + movw r2, 0xdead + movt r2, 0xbeef + + fldd d1, [r7, #-8] + faddd d0, d0, d1 + ftouizd s0, d0 + fmrs r1, s0 // r1 is slot index + + push r4, lr + + blx r2 + + pop r4, lr + + FUNCTION_MARKER + :: + ); + + +global _asm_gmegabuf_endglobal + +global nseel_asm_fcall + + + FUNCTION_MARKER + movw r0, 0xdead + movt r0, 0xbeef + push r4, lr + blx r0 + pop r4, lr + FUNCTION_MARKER + + +global nseel_asm_fcall_endglobal + + + +global nseel_asm_stack_push + + + FUNCTION_MARKER + fldd d0, [r0] + + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + ldr r0, [r3] + + add r0, r0, #8 + + movw r2, 0xdead + movt r2, 0xbeef + and r0, r0, r2 + movw r2, 0xdead + movt r2, 0xbeef + orr r0, r0, r2 + + str r0, [r3] + fstd d0, [r0] + + FUNCTION_MARKER + + +global nseel_asm_stack_push_endglobal + +global nseel_asm_stack_pop + + + FUNCTION_MARKER + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + ldr r1, [r3] + fldd d0, [r1] + sub r1, r1, #8 + movw r2, 0xdead + movt r2, 0xbeef + fstd d0, [r0] + and r1, r1, r2 + movw r2, 0xdead + movt r2, 0xbeef + orr r1, r1, r2 + + str r1, [r3] + FUNCTION_MARKER + + +global nseel_asm_stack_pop_endglobal + + + +global nseel_asm_stack_pop_fast + + + FUNCTION_MARKER + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + ldr r1, [r3] + mov r0, r1 + sub r1, r1, #8 + movw r2, 0xdead + movt r2, 0xbeef + and r1, r1, r2 + movw r2, 0xdead + movt r2, 0xbeef + orr r1, r1, r2 + str r1, [r3] + FUNCTION_MARKER + + +global nseel_asm_stack_pop_fast_endglobal + +global nseel_asm_stack_peek + + + FUNCTION_MARKER + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + + ftosizd s0, d0 + fmrs r2, s0 // r2 is index in stack + + ldr r1, [r3] + sub r1, r1, r2, asl #3 + movw r2, 0xdead + movt r2, 0xbeef + and r1, r1, r2 + movw r2, 0xdead + movt r2, 0xbeef + orr r0, r1, r2 + FUNCTION_MARKER + + +global nseel_asm_stack_peek_endglobal + + +global nseel_asm_stack_peek_top + + + FUNCTION_MARKER + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + ldr r0, [r3] + FUNCTION_MARKER + + +global nseel_asm_stack_peek_top_endglobal + + +global nseel_asm_stack_peek_int + + + FUNCTION_MARKER + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + + movw r2, 0xdead // r3 is stack + movt r2, 0xbeef + + ldr r1, [r3] + sub r1, r1, r2 + movw r2, 0xdead + movt r2, 0xbeef + and r1, r1, r2 + movw r2, 0xdead + movt r2, 0xbeef + orr r0, r1, r2 + FUNCTION_MARKER + + +global nseel_asm_stack_peek_int_endglobal + +global nseel_asm_stack_exch + + + FUNCTION_MARKER + movw r3, 0xdead // r3 is stack + movt r3, 0xbeef + ldr r1, [r3] + fldd d0, [r0] + fldd d1, [r1] + fstd d0, [r1] + fstd d1, [r0] + FUNCTION_MARKER + + +global nseel_asm_stack_exch_endglobal + + +global nseel_asm_booltofp + + + FUNCTION_MARKER + cmp r0, #0 + flddne d0, [r6, #16] + flddeq d0, [r6, #8] + FUNCTION_MARKER + + +global nseel_asm_booltofp_end + +global nseel_asm_fptobool + + + FUNCTION_MARKER + fldd d1, [r6] + fabsd d0, d0 + fcmpd d0, d1 + fmstat + movgt r0, #1 + movlt r0, #0 + FUNCTION_MARKER + + + +global nseel_asm_fptobool_end + +global nseel_asm_fptobool_rev + + + FUNCTION_MARKER + fldd d1, [r6] + fabsd d0, d0 + fcmpd d0, d1 + fmstat + movgt r0, #0 + movlt r0, #1 + FUNCTION_MARKER + + + +global nseel_asm_fptobool_rev_end + diff --git a/lib/vis_milkdrop/ns-eel2/asm-nseel-ppc-gcc.c b/lib/vis_milkdrop/ns-eel2/asm-nseel-ppc-gcc.c new file mode 100644 index 0000000..19a09ba --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/asm-nseel-ppc-gcc.c @@ -0,0 +1,1041 @@ +#if EEL_F_SIZE == 8 + +void nseel_asm_1pdd(void) +{ + + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r3)\n" + "mtctr r5\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: ); +} +void nseel_asm_1pdd_end(void){} + +void nseel_asm_2pdd(void) +{ + + __asm__( + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "lfd f2, 0(r3)\n" + "lfd f1, 0(r14)\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: ); +}; +void nseel_asm_2pdd_end(void){} + +void nseel_asm_2pdds(void) +{ + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f2, 0(r3)\n" + "lfd f1, 0(r14)\n" + "mtctr r5\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + :: ); +} +void nseel_asm_2pdds_end(void){} + +#else // 32 bit floating point calls + +#error mac only can do 64 bit floats for now + +#endif + + +void nseel_asm_2pp(void) +{ +// r3=firstparm, r4=second parm, returns in f1 + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "mtctr r5\n" + "mr r4, r3\n" + "mr r3, r14\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: ); +}; +void nseel_asm_2pp_end(void){} + +void nseel_asm_1pp(void) +{ + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "mtctr r5\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: ); +}; +void nseel_asm_1pp_end(void){} + + +//--------------------------------------------------------------------------------------------------------------- + + + +// do nothing, eh +void nseel_asm_exec2(void) +{ +} +void nseel_asm_exec2_end(void) { } + + + +void nseel_asm_invsqrt(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "frsqrte f1, f1\n" // less accurate than our x86 equivilent, but invsqrt() is inherently inaccurate anyway + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_invsqrt_end(void) {} + + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_sqr(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "fmul f1, f1, f1\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_sqr_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_abs(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "fabs f1, f1\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_abs_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_assign(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "stfd f1, 0(r14)\n" + ); +} +void nseel_asm_assign_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_add(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fadd f1, f1, f2\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_add_end(void) {} + +void nseel_asm_add_op(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fadd f1, f1, f2\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); +} +void nseel_asm_add_op_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_sub(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fsub f1, f2, f1\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_sub_end(void) {} + +void nseel_asm_sub_op(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fsub f1, f2, f1\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); +} +void nseel_asm_sub_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_mul(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fmul f1, f2, f1\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_mul_end(void) {} + +void nseel_asm_mul_op(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fmul f1, f2, f1\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); +} +void nseel_asm_mul_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_div(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fdiv f1, f2, f1\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_div_end(void) {} + +void nseel_asm_div_op(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fdiv f1, f2, f1\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); +} +void nseel_asm_div_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_mod(void) +{ + __asm__( + + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fabs f1, f1\n" + "fabs f2, f2\n" + "fctiwz f1, f1\n" + "fctiwz f2, f2\n" + "stfd f1, 8(r16)\n" + "stfd f2, 16(r16)\n" + "lwz r10, 12(r16)\n" + "lwz r11, 20(r16)\n" //r11 and r12 have the integers + + "divw r12, r11, r10\n" + "mullw r12, r12, r10\n" + "subf r10, r12, r11\n" + + "addis r11, 0, 0x4330\n" + "addis r12, 0, 0x8000\n" + "xoris r10, r10, 0x8000\n" + "stw r11, 8(r16)\n" // 0x43300000 + "stw r10, 12(r16)\n" // our integer sign flipped + "stw r11, 16(r16)\n" // 0x43300000 + "stw r12, 20(r16)\n" // 0x80000000 + "lfd f1, 8(r16)\n" + "lfd f2, 16(r16)\n" + "fsub f1, f1, f2\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + + + ); +} +void nseel_asm_mod_end(void) {} + +void nseel_asm_mod_op(void) +{ + + __asm__( + + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fabs f1, f1\n" + "fabs f2, f2\n" + "fctiwz f1, f1\n" + "fctiwz f2, f2\n" + "stfd f1, 8(r16)\n" + "stfd f2, 16(r16)\n" + "lwz r10, 12(r16)\n" + "lwz r11, 20(r16)\n" //r11 and r12 have the integers + + "divw r12, r11, r10\n" + "mullw r12, r12, r10\n" + "subf r10, r12, r11\n" + + "addis r11, 0, 0x4330\n" + "addis r12, 0, 0x8000\n" + "xoris r10, r10, 0x8000\n" + "stw r11, 8(r16)\n" // 0x43300000 + "stw r10, 12(r16)\n" // our integer sign flipped + "stw r11, 16(r16)\n" // 0x43300000 + "stw r12, 20(r16)\n" // 0x80000000 + "lfd f1, 8(r16)\n" + "lfd f2, 16(r16)\n" + "fsub f1, f1, f2\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); + +} +void nseel_asm_mod_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_or(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fctiwz f1, f1\n" + "fctiwz f2, f2\n" + "stfd f1, 8(r16)\n" + "stfd f2, 16(r16)\n" + "lwz r10, 12(r16)\n" + "lwz r11, 20(r16)\n" //r11 and r12 have the integers + "or r10, r10, r11\n" // r10 has the result + "addis r11, 0, 0x4330\n" + "addis r12, 0, 0x8000\n" + "xoris r10, r10, 0x8000\n" + "stw r11, 8(r16)\n" // 0x43300000 + "stw r10, 12(r16)\n" // our integer sign flipped + "stw r11, 16(r16)\n" // 0x43300000 + "stw r12, 20(r16)\n" // 0x80000000 + "lfd f1, 8(r16)\n" + "lfd f2, 16(r16)\n" + "fsub f1, f1, f2\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_or_end(void) {} + +void nseel_asm_or_op(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fctiwz f1, f1\n" + "fctiwz f2, f2\n" + "stfd f1, 8(r16)\n" + "stfd f2, 16(r16)\n" + "lwz r10, 12(r16)\n" + "lwz r11, 20(r16)\n" //r11 and r12 have the integers + "or r10, r10, r11\n" // r10 has the result + "addis r11, 0, 0x4330\n" + "addis r12, 0, 0x8000\n" + "xoris r10, r10, 0x8000\n" + "stw r11, 8(r16)\n" // 0x43300000 + "stw r10, 12(r16)\n" // our integer sign flipped + "stw r11, 16(r16)\n" // 0x43300000 + "stw r12, 20(r16)\n" // 0x80000000 + "lfd f1, 8(r16)\n" + "lfd f2, 16(r16)\n" + "fsub f1, f1, f2\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); +} +void nseel_asm_or_op_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_and(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fctiwz f1, f1\n" + "fctiwz f2, f2\n" + "stfd f1, 8(r16)\n" + "stfd f2, 16(r16)\n" + "lwz r10, 12(r16)\n" + "lwz r11, 20(r16)\n" //r11 and r12 have the integers + "and r10, r10, r11\n" // r10 has the result + "addis r11, 0, 0x4330\n" + "addis r12, 0, 0x8000\n" + "xoris r10, r10, 0x8000\n" + "stw r11, 8(r16)\n" // 0x43300000 + "stw r10, 12(r16)\n" // our integer sign flipped + "stw r11, 16(r16)\n" // 0x43300000 + "stw r12, 20(r16)\n" // 0x80000000 + "lfd f1, 8(r16)\n" + "lfd f2, 16(r16)\n" + "fsub f1, f1, f2\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + );} +void nseel_asm_and_end(void) {} + +void nseel_asm_and_op(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fctiwz f1, f1\n" + "fctiwz f2, f2\n" + "stfd f1, 8(r16)\n" + "stfd f2, 16(r16)\n" + "lwz r10, 12(r16)\n" + "lwz r11, 20(r16)\n" //r11 and r12 have the integers + "and r10, r10, r11\n" // r10 has the result + "addis r11, 0, 0x4330\n" + "addis r12, 0, 0x8000\n" + "xoris r10, r10, 0x8000\n" + "stw r11, 8(r16)\n" // 0x43300000 + "stw r10, 12(r16)\n" // our integer sign flipped + "stw r11, 16(r16)\n" // 0x43300000 + "stw r12, 20(r16)\n" // 0x80000000 + "lfd f1, 8(r16)\n" + "lfd f2, 16(r16)\n" + "fsub f1, f1, f2\n" + "stfd f1, 0(r14)\n" + "mr r3, r14\n" + ); +} +void nseel_asm_and_op_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_uplus(void) // this is the same as doing nothing, it seems +{ +} +void nseel_asm_uplus_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_uminus(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "fneg f1, f1\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + ); +} +void nseel_asm_uminus_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_sign(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f2, 0(r5)\n" + "lis r9, 0xbff0\n" + "fcmpu cr7, f1, f2\n" + "blt- cr7, 0f\n" + "ble- cr7, 1f\n" + " lis r9, 0x3ff0\n" + "0:\n" + " li r10, 0\n" + " stwu r9, 8(r16)\n" + " stw r10, 4(r16)\n" + " b 2f\n" + "1:\n" + " stfdu f1, 8(r16)\n" + "2:\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_sign_end(void) {} + + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_bnot(void) +{ + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f2, 0(r5)\n" + "lfd f1, 0(r3)\n" + "fabs f1, f1\n" + "fcmpu cr7, f1, f2\n" + "blt cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "1:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_bnot_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_if(void) +{ + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f2, 0(r5)\n" + "lfd f1, 0(r3)\n" + "addis r6, 0, 0xdead\n" + "ori r6, r6, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "fabs f1, f1\n" + "fcmpu cr7, f1, f2\n" + "blt cr7, 0f\n" + " mtctr r6\n" + "b 1f\n" + "0:\n" + " mtctr r7\n" + "1:\n" + "bctrl\n" + :: ); +} +void nseel_asm_if_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_repeat(void) +{ + __asm__( + "addis r6, 0, 0xdead\n" + "ori r6, r6, 0xbeef\n" + "addis r7, 0, ha16(%0)\n" + "addi r7, r7, lo16(%0)\n" + "lfd f1, 0(r3)\n" + "fctiwz f1, f1\n" + "stfd f1, 8(r16)\n" + "lwz r5, 12(r16)\n" // r5 has count now + "cmpwi cr0, r5, 0\n" + "ble cr0, 1f\n" + "cmpw cr0, r7, r5\n" + "bge cr0, 0f\n" + "mr r5, r7\n" // set r5 to max if we have to +"0:\n" + "stw r5, -4(r1)\n" + "stw r6, -8(r1)\n" + "stwu r16, -12(r1)\n" + + "mtctr r6\n" + "bctrl\n" + + "lwz r16, 0(r1)\n" + "lwz r6, 4(r1)\n" + "lwz r5, 8(r1)\n" + "addi r1, r1, 12\n" + "addi r5, r5, -1\n" + + "cmpwi cr0, r5, 0\n" + "bgt cr0, 0b\n" + "1:\n" + ::"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN) + ); +} +void nseel_asm_repeat_end(void) {} + +void nseel_asm_repeatwhile(void) +{ + __asm__( + "addis r6, 0, 0xdead\n" + "ori r6, r6, 0xbeef\n" + "addis r5, 0, ha16(%0)\n" + "addi r5, r5, lo16(%0)\n" +"0:\n" + "stw r5, -4(r1)\n" + "stw r6, -8(r1)\n" + "stwu r16, -12(r1)\n" + + "mtctr r6\n" + "bctrl\n" + + "lwz r16, 0(r1)\n" + "lwz r6, 4(r1)\n" + "lwz r5, 8(r1)\n" + "addi r1, r1, 12\n" + "addi r5, r5, -1\n" + + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "lfd f2, 0(r7)\n" + + "lfd f1, 0(r3)\n" + "fabs f1, f1\n" + "fcmpu cr7, f1, f2\n" + "blt cr7, 1f\n" + + "cmpwi cr0, r5, 0\n" + "bgt cr0, 0b\n" + "1:\n" + ::"g" (NSEEL_LOOPFUNC_SUPPORT_MAXLEN) + ); +} +void nseel_asm_repeatwhile_end(void) {} + + +void nseel_asm_band(void) +{ + __asm__( + + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f2, 0(r5)\n" + "lfd f1, 0(r3)\n" + "fabs f1, f1\n" + "fcmpu cr7, f1, f2\n" + "blt cr7, 0f\n" + "addis r6, 0, 0xdead\n" + "ori r6, r6, 0xbeef\n" + " mtctr r6\n" + " bctrl\n" + " addis r5, 0, 0xdead\n" + " ori r5, r5, 0xbeef\n" + " lfd f2, 0(r5)\n" + " lfd f1, 0(r3)\n" + " fabs f1, f1\n" + " fcmpu cr7, f1, f2\n" + " bge cr7, 1f\n" + "0:\n" + " fsub f1, f1, f1\n" // set f1 to 0! + " b 2f\n" + "1:\n" + " addis r5, 0, 0xdead\n" // set f1 to 1 + " ori r5, r5, 0xbeef\n" + " lfd f1, 0(r5)\n" + "2:\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: ); +} +void nseel_asm_band_end(void) {} + +void nseel_asm_bor(void) +{ + __asm__( + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f2, 0(r5)\n" + "lfd f1, 0(r3)\n" + "fabs f1, f1\n" + "fcmpu cr7, f1, f2\n" + "bge cr7, 0f\n" + "addis r6, 0, 0xdead\n" + "ori r6, r6, 0xbeef\n" + " mtctr r6\n" + " bctrl\n" + " addis r5, 0, 0xdead\n" + " ori r5, r5, 0xbeef\n" + " lfd f2, 0(r5)\n" + " lfd f1, 0(r3)\n" + " fabs f1, f1\n" + " fcmpu cr7, f1, f2\n" + " blt cr7, 1f\n" + "0:\n" + " addis r5, 0, 0xdead\n" // set f1 to 1 + " ori r5, r5, 0xbeef\n" + " lfd f1, 0(r5)\n" + " b 2f\n" + "1:\n" + " fsub f1, f1, f1\n" // set f1 to 0! + "2:\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: ); +} +void nseel_asm_bor_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_equal(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "fsub f1, f1, f2\n" + "fabs f1, f1\n" + "lfd f2, 0(r5)\n" + "fcmpu cr7, f1, f2\n" + "blt cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "1:\n" + "lfd f1, 0(r5)\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_equal_end(void) {} +// +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_notequal(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "fsub f1, f1, f2\n" + "fabs f1, f1\n" + "lfd f2, 0(r5)\n" + "fcmpu cr7, f1, f2\n" + "blt cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "1:\n" + "lfd f1, 0(r5)\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_notequal_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_below(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fcmpu cr7, f2, f1\n" + "blt cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "1:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_below_end(void) {} + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_beloweq(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fcmpu cr7, f2, f1\n" + "ble cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "1:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_beloweq_end(void) {} + + +//--------------------------------------------------------------------------------------------------------------- +void nseel_asm_above(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fcmpu cr7, f2, f1\n" + "bgt cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "1:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_above_end(void) {} + +void nseel_asm_aboveeq(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fcmpu cr7, f2, f1\n" + "bge cr7, 0f\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "b 1f\n" + "0:\n" + "addis r5, 0, 0xdead\n" + "ori r5, r5, 0xbeef\n" + "lfd f1, 0(r5)\n" + "1:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + :: + ); +} +void nseel_asm_aboveeq_end(void) {} + + + +void nseel_asm_min(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fcmpu cr7, f2, f1\n" + "bgt cr7, 0f\n" + "fmr f1, f2\n" + "0:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + ); +} +void nseel_asm_min_end(void) {} + +void nseel_asm_max(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "lfd f2, 0(r14)\n" + "fcmpu cr7, f2, f1\n" + "blt cr7, 0f\n" + "fmr f1, f2\n" + "0:\n" + " stfdu f1, 8(r16)\n" + " mr r3, r16\n" + ); +} + +void nseel_asm_max_end(void) {} + + + + + + + + + +void _asm_generic3parm(void) +{ + __asm__( + "mr r6, r3\n" + "addis r3, 0, 0xdead\n" + "ori r3, r3, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mr r4, r15\n" + "mr r5, r14\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + :: + ); +} +void _asm_generic3parm_end(void) {} + +void _asm_generic3parm_retd(void) +{ + __asm__( + "mr r6, r3\n" + "addis r3, 0, 0xdead\n" + "ori r3, r3, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mr r4, r15\n" + "mr r5, r14\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: + ); +} +void _asm_generic3parm_retd_end(void) {} + + +void _asm_generic2parm(void) // this prob neds to be fixed for ppc +{ + __asm__( + "mr r5, r3\n" + "addis r3, 0, 0xdead\n" + "ori r3, r3, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mr r4, r14\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + :: + ); +} +void _asm_generic2parm_end(void) {} + + +void _asm_generic2parm_retd(void) +{ + __asm__( + "mr r5, r3\n" + "addis r3, 0, 0xdead\n" + "ori r3, r3, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mr r4, r14\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: + ); +} +void _asm_generic2parm_retd_end(void) {} + +void _asm_generic1parm(void) // this prob neds to be fixed for ppc +{ + __asm__( + "mr r4, r3\n" + "addis r3, 0, 0xdead\n" + "ori r3, r3, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + :: + ); +} +void _asm_generic1parm_end(void) {} + + + +void _asm_generic1parm_retd(void) +{ + __asm__( + "mr r4, r3\n" + "addis r3, 0, 0xdead\n" + "ori r3, r3, 0xbeef\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mtctr r7\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "stfdu f1, 8(r16)\n" + "mr r3, r16\n" + :: + ); +} +void _asm_generic1parm_retd_end(void) {} + + + + +void _asm_megabuf(void) +{ + __asm__( + "lfd f1, 0(r3)\n" + "addis r3, 0, 0xdead\n" // set up context pointer + "ori r3, r3, 0xbeef\n" + "addis r4, 0, 0xdead\n" + "ori r4, r4, 0xbeef\n" + "lfd f2, 0(r4)\n" + "fadd f1, f2, f1\n" + "addis r7, 0, 0xdead\n" + "ori r7, r7, 0xbeef\n" + "mtctr r7\n" + "fctiwz f1, f1\n" + "stfd f1, 8(r16)\n" + "lwz r4, 12(r16)\n" + "subi r1, r1, 64\n" + "bctrl\n" + "addi r1, r1, 64\n" + "cmpi cr0, r3, 0\n" + "bne cr0, 0f\n" + "sub r5, r5, r5\n" + "stwu r5, 8(r16)\n" + "stw r5, 4(r16)\n" + "mr r3, r16\n" + "0:\n" + :: + ); +} + +void _asm_megabuf_end(void) {} diff --git a/lib/vis_milkdrop/ns-eel2/asm-nseel-x64-macho.o b/lib/vis_milkdrop/ns-eel2/asm-nseel-x64-macho.o new file mode 100644 index 0000000000000000000000000000000000000000..76e918ed866f7b34a1018229f812a12a2fc1c650 GIT binary patch literal 7505 zcmb`M4{RIN9mkJ0i5=Ktil)+vsU;Fs6;N4hm$VgsI%^udNEKqVD=<_nC%G0&PMpMc z8#G8`q)i;RX;eZ8ia<=2Hb7J`p&&qrHmsxTBp_)us8w5`6=Ka=P+({w6~z1fp1;q& zdv|sN+LJDKpWplazVG+`-dXwJ!ebs-fAP|aaT0Zk zNz>qqHMzv&S#u;?d9LubpWnT$#_CDMD?Md5nvAjPGd*ygE9e@#%rI=acmBvQ+FK3d zKcP`W^Y7|89`{tjB7F!h>{?)BjE4bw?K6 z)l~$ zpxq{>=0(RptmP-$PPWx5iw2Q3TUzBav?Zgk(4el|pzceqJ6T7y`1b~prwbSA)fPUZ zE?TpNFMM?i=Nr{hUryK4753%Ani3QLzFOqZ7{=`0Y@5hmkPpo>yv=9?g%xs-bumy+ zu4HiC*QM32fI#u;x&gAz8xX7;U=%}sEp*lm2o$N#(*h65sW!T9ZxZ3-qT_J>7G6Br zX8YErxh`w@sh0YJGB(8V6i3nd%`&vfZkgL)U3toH1mygb+Df+vg*_S+t+z~H?>m#F zK*=bDN^Qb!5v_sgpZI3ZnN_9Q7bDf~C*_`lVj=xj_b$m$*~u6TO-WAOqXz7&)V6wc1@ zd0F_}e}H%~J7R0k!fJ8CtwENZINL1N$dv4+PC9A$u{=qqDnGb$qS*`|qq8DE&#!?8 zyXax;i6@N*FBNa_olCXHWk_xRMfvzW_d!mSkL5~E&BX@R9gkcyYrezNQ9Jb?tM7i3 zctf4vs;^T>u6|H$z^R=@jd^vxvfrmcn&HnYGkmswgT=M(X|6W8s3p=UI#=tje`f>V zbwL(aJF~l}zTx)2=z`bsxu`z*-%(BI?(9-JLR_oIU7yqIy-U=|TP`k%oeGKYe`EHBno(&VuMLc7Kb%{} zojckh4>Iq^BrTJzzl?2<-Bq59#bfvFxc9HlY2_fpSV^a58=Z~^_<*L;4*nCk1N;R(8@bc7uNp-V6Q%_z~~| zcpq5)7@(B)gE#Y!11bl=G4M;^hrr|Dz2LXO2f;_dFM}t+C2#>e4L$?@A>Fy01Bbw0 zfo}$X3*HQFq2CxhU-yGUVD2}U72q-aF0!fJ5cxk(b}r9?PlLxbeh=J%_;q0ZZNufK z;2q$*G){w6dmqp|aQlxVzcb(y;CYRgY3y6NJ2#lHeia3z&AU0knt6s+325&ip$^5(Jyd=2`a z&^Qa;hWa_uX8oPmk1ceU`G8~Kaqu1BDR8gGIq;{bpQnAydQt4(Al;dFfUnYc9e5P= zE1~x=^sWP|e74d)X1y-z7nfe}pTXzAk7Ink0UrS`!+0pZ2CT+&9Qn*4pTB{lq{C&8 z*4}TyE1ErM34WcstsEmD=R?)p|Sv z?ne6stv~+)+oZ##Ko`d=|MTGeh<};xTz@U*X9_I9XTWNGy{*+B#CT`19^V41{cMBP zdfl)2C$;ey0gq#RY>l4*pGEyYv7W93e*%tz=QM6byqd2=+IaJOhQ~v#w^!k>+M57h zLF3GY-*fD*_!F?&FZ0@bTn7DV%ul<<8^LNn>_hxt(B2=xYCSK-e5m=n0<6|+5kD!qWLiU`DC0z?3D3(4Z3{>b&v3% z%Y#t&Fh|VZh*L!xbg$&V?#$3|*69b6?wLsrIK2pUkKVMaXN0;(HsR7B)IBH}S1Uuq zJ|3=gIepzHmEPr4A@uPGcWOT2PTecfwkB6qjPHE2y>CdH{N`$%+o7_27EV^G`a<@~7(8ohlVke)R(ylGlpZ4q^ zHfcFYi{4_|wUE-Dbwn1oj5O#f3HKH!^zqPy*vZ?o++Zr_T20cRtL6HW1Dcz(=zjXD zW7d6o2GXvb!mRrwcRD97xl^wnHV4gwOQmA*_uF%SGG#giE6&oaNAzez%k1%SPhyXE z7R{kt!nKN}LD!* +#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__ diff --git a/lib/vis_milkdrop/ns-eel2/ns-eel.h b/lib/vis_milkdrop/ns-eel2/ns-eel.h new file mode 100644 index 0000000..d20aaeb --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/ns-eel.h @@ -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 +#include + +#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__ diff --git a/lib/vis_milkdrop/ns-eel2/nseel-caltab.c b/lib/vis_milkdrop/ns-eel2/nseel-caltab.c new file mode 100644 index 0000000..1d8a6d3 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-caltab.c @@ -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; +} diff --git a/lib/vis_milkdrop/ns-eel2/nseel-cfunc.c b/lib/vis_milkdrop/ns-eel2/nseel-cfunc.c new file mode 100644 index 0000000..57cb7c0 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-cfunc.c @@ -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 +#include + + + +// 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> 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> 1) ^ mag01[y & 0x1UL]; + } + for (;kk> 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 + diff --git a/lib/vis_milkdrop/ns-eel2/nseel-compiler.c b/lib/vis_milkdrop/ns-eel2/nseel-compiler.c new file mode 100644 index 0000000..61af0a3 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-compiler.c @@ -0,0 +1,1809 @@ +/* + Expression Evaluator Library (NS-EEL) v2 + Copyright (C) 2004-2008 Cockos Incorporated + Copyright (C) 1999-2003 Nullsoft, Inc. + + nseel-compiler.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. +*/ + + +// for VirtualProtect + +#include "ns-eel-int.h" + + +#include +#include +#include +#include + +#ifndef _WIN64 + #ifndef __ppc__ + #include + #endif +#endif + +#ifdef __APPLE__ + #ifdef __LP64__ + #define EEL_USE_MPROTECT + #endif +#endif + +#ifdef EEL_USE_MPROTECT +#include +#include +#include +#endif + +#ifdef NSEEL_EEL1_COMPAT_MODE + +#ifndef EEL_NO_CHANGE_FPFLAGS +#define EEL_NO_CHANGE_FPFLAGS +#endif + +#endif + +#ifndef _WIN64 +#if !defined(_RC_CHOP) && !defined(EEL_NO_CHANGE_FPFLAGS) + +#include +#define _RC_CHOP _FPU_RC_ZERO +#define _MCW_RC _FPU_RC_ZERO +static unsigned int _controlfp(unsigned int val, unsigned int mask) +{ + unsigned int ret; + _FPU_GETCW(ret); + if (mask) + { + ret&=~mask; + ret|=val; + _FPU_SETCW(ret); + } + return ret; +} + +#endif +#endif + + +#ifdef __ppc__ + +#define GLUE_MOV_EAX_DIRECTVALUE_SIZE 8 +static void GLUE_MOV_EAX_DIRECTVALUE_GEN(void *b, INT_PTR v) +{ + unsigned int uv=(unsigned int)v; + unsigned short *p=(unsigned short *)b; + + *p++ = 0x3C60; // addis r3, r0, hw + *p++ = (uv>>16)&0xffff; + *p++ = 0x6063; // ori r3, r3, lw + *p++ = uv&0xffff; +} + + +// mflr r5 +// stwu r5, -4(r1) +const static unsigned int GLUE_FUNC_ENTER[2] = { 0x7CA802A6, 0x94A1FFFC }; + +// lwz r5, 0(r1) +// addi r1, r1, 4 +// mtlr r5 +const static unsigned int GLUE_FUNC_LEAVE[3] = { 0x80A10000, 0x38210004, 0x7CA803A6 }; +#define GLUE_FUNC_ENTER_SIZE sizeof(GLUE_FUNC_ENTER) +#define GLUE_FUNC_LEAVE_SIZE sizeof(GLUE_FUNC_LEAVE) + +const static unsigned int GLUE_RET[]={0x4E800020}; // blr + +const static unsigned int GLUE_MOV_ESI_EDI=0x7E308B78; // mr r16, r17 + +static int GLUE_RESET_ESI(char *out, void *ptr) +{ + if (out) memcpy(out,&GLUE_MOV_ESI_EDI,sizeof(GLUE_MOV_ESI_EDI)); + return sizeof(GLUE_MOV_ESI_EDI); + +} + + + +// stwu r3, -4(r1) +const static unsigned int GLUE_PUSH_EAX[1]={ 0x9461FFFC}; + +// lwz r14, 0(r1) +// addi r1, r1, 4 +const static unsigned int GLUE_POP_EBX[2]={ 0x81C10000, 0x38210004, }; + +// lwz r15, 0(r1) +// addi r1, r1, 4 +const static unsigned int GLUE_POP_ECX[2]={ 0x81E10000, 0x38210004 }; + + +static void GLUE_CALL_CODE(INT_PTR bp, INT_PTR cp) +{ + __asm__( + "stmw r14, -80(r1)\n" + "mtctr %0\n" + "mr r17, %1\n" + "subi r17, r17, 8\n" + "mflr r5\n" + "stw r5, -84(r1)\n" + "subi r1, r1, 88\n" + "bctrl\n" + "addi r1, r1, 88\n" + "lwz r5, -84(r1)\n" + "lmw r14, -80(r1)\n" + "mtlr r5\n" + ::"r" (cp), "r" (bp)); +}; + +INT_PTR *EEL_GLUE_set_immediate(void *_p, void *newv) +{ +// todo 64 bit ppc will take some work + unsigned int *p=(unsigned int *)_p; + while ((p[0]&0x0000FFFF) != 0x0000dead && + (p[1]&0x0000FFFF) != 0x0000beef) p++; + p[0] = (p[0]&0xFFFF0000) | (((unsigned int)newv)>>16); + p[1] = (p[1]&0xFFFF0000) | (((unsigned int)newv)&0xFFFF); + + return (INT_PTR*)++p; +} + + +#else + +//x86 specific code + +#define GLUE_FUNC_ENTER_SIZE 0 +#define GLUE_FUNC_LEAVE_SIZE 0 +const static unsigned int GLUE_FUNC_ENTER[1]; +const static unsigned int GLUE_FUNC_LEAVE[1]; + +#if defined(_WIN64) || defined(__LP64__) +#define GLUE_MOV_EAX_DIRECTVALUE_SIZE 10 +static void GLUE_MOV_EAX_DIRECTVALUE_GEN(void *b, INT_PTR v) { + unsigned short *bb = (unsigned short *)b; + *bb++ =0xB848; + *(INT_PTR *)bb = v; +} +const static unsigned char GLUE_PUSH_EAX[2]={ 0x50,0x50}; // push rax ; push rax (push twice to preserve alignment) +const static unsigned char GLUE_POP_EBX[2]={0x5F, 0x5f}; //pop rdi ; twice +const static unsigned char GLUE_POP_ECX[2]={0x59, 0x59 }; // pop rcx ; twice +#else +#define GLUE_MOV_EAX_DIRECTVALUE_SIZE 5 +static void GLUE_MOV_EAX_DIRECTVALUE_GEN(void *b, int v) +{ + *((unsigned char *)b) =0xB8; + b= ((unsigned char *)b)+1; + *(int *)b = v; +} +const static unsigned char GLUE_PUSH_EAX[4]={0x83, 0xEC, 12, 0x50}; // sub esp, 12, push eax +const static unsigned char GLUE_POP_EBX[4]={0x5F, 0x83, 0xC4, 12}; //pop ebx, add esp, 12 // DI=5F, BX=0x5B; +const static unsigned char GLUE_POP_ECX[4]={0x59, 0x83, 0xC4, 12}; // pop ecx, add esp, 12 + +#endif + +//const static unsigned short GLUE_MOV_ESI_EDI=0xF78B; +const static unsigned char GLUE_RET=0xC3; + +static int GLUE_RESET_ESI(unsigned char *out, void *ptr) +{ +#if defined(_WIN64) || defined(__LP64__) + if (out) + { + *out++ = 0x48; + *out++ = 0xBE; // mov rsi, constant64 + *(void **)out = ptr; + out+=sizeof(void *); + } + return 2+sizeof(void *); +#else + if (out) + { + *out++ = 0xBE; // mov esi, constant + memcpy(out,&ptr,sizeof(void *)); + out+=sizeof(void *); + } + return 1+sizeof(void *); +#endif +} + +static void GLUE_CALL_CODE(INT_PTR bp, INT_PTR cp) +{ + #if defined(_WIN64) || defined(__LP64__) + extern void win64_callcode(INT_PTR code); + win64_callcode(cp); + #else // non-64 bit + #ifdef _MSC_VER + #ifndef EEL_NO_CHANGE_FPFLAGS + unsigned int old_v=_controlfp(0,0); + _controlfp(_RC_CHOP,_MCW_RC); + #endif + + __asm + { + mov eax, cp + pushad + call eax + popad + }; + + #ifndef EEL_NO_CHANGE_FPFLAGS + _controlfp(old_v,_MCW_RC); + #endif + +#else // gcc x86 + #ifndef EEL_NO_CHANGE_FPFLAGS + unsigned int old_v=_controlfp(0,0); + _controlfp(_RC_CHOP,_MCW_RC); + #endif + __asm__("call *%%eax"::"a" (cp): "%ecx","%edx","%esi","%edi"); + #ifndef EEL_NO_CHANGE_FPFLAGS + _controlfp(old_v,_MCW_RC); + #endif + #endif //gcc x86 + #endif // 32bit +} + +INT_PTR *EEL_GLUE_set_immediate(void *_p, void *newv) +{ + char *p=(char*)_p; +#ifdef _WIN64 + INT_PTR scan = 0xFEFEFEFEFEFEFEFE; +#else + INT_PTR scan = ~(INT_PTR)0; +#endif + while (*(INT_PTR *)p != scan) p++; + *(INT_PTR *)p = (INT_PTR)newv; + return ((INT_PTR*)p)+1; +} + +#endif + + +static void *GLUE_realAddress(void *fn, void *fn_e, int *size) +{ +#if defined(_MSC_VER) || defined(__LP64__) + + unsigned char *p; + +#if defined(_DEBUG) && !defined(__LP64__) + if (*(unsigned char *)fn == 0xE9) // this means jump to the following address + { + fn = ((unsigned char *)fn) + *(int *)((char *)fn+1) + 5; + } +#endif + + // this may not work in debug mode + p=(unsigned char *)fn; + for (;;) + { + int a; + for (a=0;a<12;a++) + { + if (p[a] != (a?0x90:0x89)) break; + } + if (a>=12) + { + *size = (char *)p - (char *)fn; + // if (*size<0) MessageBox(NULL,"expect poof","a",0); + return fn; + } + p++; + } +#else + char *p=(char *)fn_e - sizeof(GLUE_RET); + if (p <= (char *)fn) *size=0; + else + { + while (p > (char *)fn && memcmp(p,&GLUE_RET,sizeof(GLUE_RET))) p-=sizeof(GLUE_RET); + *size = p - (char *)fn; + } + return fn; +#endif +} + + + +static int nseel_evallib_stats[5]; // source bytes, static code bytes, call code bytes, data bytes, segments +int *NSEEL_getstats() +{ + return nseel_evallib_stats; +} +EEL_F *NSEEL_getglobalregs() +{ + return nseel_globalregs; +} + +// this stuff almost works +static int findByteOffsetInSource(compileContext *ctx, int byteoffs,int *destoffs) +{ + int x; + if (!ctx->compileLineRecs || !ctx->compileLineRecs_size) return *destoffs=0; + if (byteoffs < ctx->compileLineRecs[0].destByteCount) + { + *destoffs=0; + return 1; + } + for (x = 0; x < ctx->compileLineRecs_size-1; x ++) + { + if (byteoffs >= ctx->compileLineRecs[x].destByteCount && + byteoffs < ctx->compileLineRecs[x+1].destByteCount) break; + } + *destoffs=ctx->compileLineRecs[(x&&x==ctx->compileLineRecs_size-1)?x-1:x].srcByteCount; + + return x+2; +} + + +static void onCompileNewLine(compileContext *ctx, int srcBytes, int destBytes) +{ + if (!ctx->compileLineRecs || ctx->compileLineRecs_size >= ctx->compileLineRecs_alloc) + { + ctx->compileLineRecs_alloc = ctx->compileLineRecs_size+1024; + ctx->compileLineRecs = (lineRecItem *)realloc(ctx->compileLineRecs,sizeof(lineRecItem)*ctx->compileLineRecs_alloc); + } + if (ctx->compileLineRecs) + { + ctx->compileLineRecs[ctx->compileLineRecs_size].srcByteCount=srcBytes; + ctx->compileLineRecs[ctx->compileLineRecs_size++].destByteCount=destBytes; + } +} + + + +#define LLB_DSIZE (65536-64) +typedef struct _llBlock { + struct _llBlock *next; + int sizeused; + char block[LLB_DSIZE]; +} llBlock; + +typedef struct _startPtr { + struct _startPtr *next; + void *startptr; +} startPtr; + +typedef struct { + void *workTable; + + llBlock *blocks; + void *code; + int code_stats[4]; +} codeHandleType; + +#ifndef NSEEL_MAX_TEMPSPACE_ENTRIES +#define NSEEL_MAX_TEMPSPACE_ENTRIES 2048 +#endif + +static void *__newBlock(llBlock **start,int size); + +#define newTmpBlock(x) __newTmpBlock((llBlock **)&ctx->tmpblocks_head,x) +#define newBlock(x,a) __newBlock_align(ctx,x,a) + +static void *__newTmpBlock(llBlock **start, int size) +{ + void *p=__newBlock(start,size+4); + if (p && size>=0) *((int *)p) = size; + return p; +} + +static void *__newBlock_align(compileContext *ctx, int size, int align) // makes sure block is aligned to 32 byte boundary, for code +{ + int a1=align-1; + char *p=(char*)__newBlock((llBlock **)&ctx->blocks_head,size+a1); + return p+((align-(((INT_PTR)p)&a1))&a1); +} + +static void freeBlocks(llBlock **start); + +#define DECL_ASMFUNC(x) \ + void nseel_asm_##x(void); \ + void nseel_asm_##x##_end(void); \ + + DECL_ASMFUNC(sin) + DECL_ASMFUNC(cos) + DECL_ASMFUNC(tan) + DECL_ASMFUNC(1pdd) + DECL_ASMFUNC(2pdd) + DECL_ASMFUNC(2pdds) + DECL_ASMFUNC(1pp) + DECL_ASMFUNC(2pp) + DECL_ASMFUNC(sqr) + DECL_ASMFUNC(sqrt) + DECL_ASMFUNC(log) + DECL_ASMFUNC(log10) + DECL_ASMFUNC(abs) + DECL_ASMFUNC(min) + DECL_ASMFUNC(max) + DECL_ASMFUNC(sig) + DECL_ASMFUNC(sign) + DECL_ASMFUNC(band) + DECL_ASMFUNC(bor) + DECL_ASMFUNC(bnot) + DECL_ASMFUNC(if) + DECL_ASMFUNC(repeat) + DECL_ASMFUNC(repeatwhile) + DECL_ASMFUNC(equal) + DECL_ASMFUNC(notequal) + DECL_ASMFUNC(below) + DECL_ASMFUNC(above) + DECL_ASMFUNC(beloweq) + DECL_ASMFUNC(aboveeq) + DECL_ASMFUNC(assign) + DECL_ASMFUNC(add) + DECL_ASMFUNC(sub) + DECL_ASMFUNC(add_op) + DECL_ASMFUNC(sub_op) + DECL_ASMFUNC(mul) + DECL_ASMFUNC(div) + DECL_ASMFUNC(mul_op) + DECL_ASMFUNC(div_op) + DECL_ASMFUNC(mod) + DECL_ASMFUNC(mod_op) + DECL_ASMFUNC(or) + DECL_ASMFUNC(and) + DECL_ASMFUNC(or_op) + DECL_ASMFUNC(and_op) + DECL_ASMFUNC(uplus) + DECL_ASMFUNC(uminus) + DECL_ASMFUNC(invsqrt) + DECL_ASMFUNC(exec2) + +static void NSEEL_PProc_GRAM(void *data, int data_size, compileContext *ctx) +{ + if (data_size>0) EEL_GLUE_set_immediate(data, ctx->gram_blocks); +} + + +static EEL_F g_signs[2]={1.0,-1.0}; +static EEL_F negativezeropointfive=-0.5f; +static EEL_F onepointfive=1.5f; +static EEL_F g_closefact = NSEEL_CLOSEFACTOR; +static const EEL_F eel_zero=0.0, eel_one=1.0; + +#if defined(_MSC_VER) && _MSC_VER >= 1400 +static double __floor(double a) { return floor(a); } +static double __ceil(double a) { return ceil(a); } +#endif + +static double eel1band(double a, double b) +{ + return (fabs(a)>g_closefact && fabs(b) > g_closefact) ? 1.0 : 0.0; +} +static double eel1bor(double a, double b) +{ + return (fabs(a)>g_closefact || fabs(b) > g_closefact) ? 1.0 : 0.0; +} + +static double eel1sigmoid(double x, double constraint) +{ + double t = (1+exp(-x * (constraint))); + return fabs(t)>g_closefact ? 1.0/t : 0; +} + + +EEL_F NSEEL_CGEN_CALL nseel_int_rand(EEL_F *f); + +static functionType fnTable1[] = { + { "_if", nseel_asm_if,nseel_asm_if_end, 3, {&g_closefact} }, + { "_and", nseel_asm_band,nseel_asm_band_end, 2 } , + { "_or", nseel_asm_bor,nseel_asm_bor_end, 2 } , + { "loop", nseel_asm_repeat,nseel_asm_repeat_end, 2 }, + { "while", nseel_asm_repeatwhile,nseel_asm_repeatwhile_end, 1 }, + +#ifdef __ppc__ + { "_not", nseel_asm_bnot,nseel_asm_bnot_end, 1, {&g_closefact,&eel_zero,&eel_one} } , + { "_equal", nseel_asm_equal,nseel_asm_equal_end, 2, {&g_closefact,&eel_zero, &eel_one} }, + { "_noteq", nseel_asm_notequal,nseel_asm_notequal_end, 2, {&g_closefact,&eel_one,&eel_zero} }, + { "_below", nseel_asm_below,nseel_asm_below_end, 2, {&eel_zero, &eel_one} }, + { "_above", nseel_asm_above,nseel_asm_above_end, 2, {&eel_zero, &eel_one} }, + { "_beleq", nseel_asm_beloweq,nseel_asm_beloweq_end, 2, {&eel_zero, &eel_one} }, + { "_aboeq", nseel_asm_aboveeq,nseel_asm_aboveeq_end, 2, {&eel_zero, &eel_one} }, +#else + { "_not", nseel_asm_bnot,nseel_asm_bnot_end, 1, {&g_closefact} } , + { "_equal", nseel_asm_equal,nseel_asm_equal_end, 2, {&g_closefact} }, + { "_noteq", nseel_asm_notequal,nseel_asm_notequal_end, 2, {&g_closefact} }, + { "_below", nseel_asm_below,nseel_asm_below_end, 2 }, + { "_above", nseel_asm_above,nseel_asm_above_end, 2 }, + { "_beleq", nseel_asm_beloweq,nseel_asm_beloweq_end, 2 }, + { "_aboeq", nseel_asm_aboveeq,nseel_asm_aboveeq_end, 2 }, +#endif + + { "_set",nseel_asm_assign,nseel_asm_assign_end,2}, + { "_mod",nseel_asm_mod,nseel_asm_mod_end,2}, + { "_mulop",nseel_asm_mul_op,nseel_asm_mul_op_end,2}, + { "_divop",nseel_asm_div_op,nseel_asm_div_op_end,2}, + { "_orop",nseel_asm_or_op,nseel_asm_or_op_end,2}, + { "_andop",nseel_asm_and_op,nseel_asm_and_op_end,2}, + { "_addop",nseel_asm_add_op,nseel_asm_add_op_end,2}, + { "_subop",nseel_asm_sub_op,nseel_asm_sub_op_end,2}, + { "_modop",nseel_asm_mod_op,nseel_asm_mod_op_end,2}, + + +#ifdef __ppc__ + { "sin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&sin} }, + { "cos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&cos} }, + { "tan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&tan} }, +#else + { "sin", nseel_asm_sin,nseel_asm_sin_end, 1 }, + { "cos", nseel_asm_cos,nseel_asm_cos_end, 1 }, + { "tan", nseel_asm_tan,nseel_asm_tan_end, 1 }, +#endif + { "asin", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&asin}, }, + { "acos", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&acos}, }, + { "atan", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&atan}, }, + { "atan2", nseel_asm_2pdd,nseel_asm_2pdd_end, 2, {&atan2}, }, + { "sqr", nseel_asm_sqr,nseel_asm_sqr_end, 1 }, +#ifdef __ppc__ + { "sqrt", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&sqrt}, }, +#else + { "sqrt", nseel_asm_sqrt,nseel_asm_sqrt_end, 1 }, +#endif + { "pow", nseel_asm_2pdd,nseel_asm_2pdd_end, 2, {&pow}, }, + { "_powop", nseel_asm_2pdds,nseel_asm_2pdds_end, 2, {&pow}, }, + { "exp", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&exp}, }, +#ifdef __ppc__ + { "log", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&log} }, + { "log10", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&log10} }, +#else + { "log", nseel_asm_log,nseel_asm_log_end, 1, }, + { "log10", nseel_asm_log10,nseel_asm_log10_end, 1, }, +#endif + { "abs", nseel_asm_abs,nseel_asm_abs_end, 1 }, + { "min", nseel_asm_min,nseel_asm_min_end, 2 }, + { "max", nseel_asm_max,nseel_asm_max_end, 2 }, +#ifdef __ppc__ + { "sign", nseel_asm_sign,nseel_asm_sign_end, 1, {&eel_zero}} , +#else + { "sign", nseel_asm_sign,nseel_asm_sign_end, 1, {&g_signs}} , +#endif + { "rand", nseel_asm_1pp,nseel_asm_1pp_end, 1, {&nseel_int_rand}, } , + +#if defined(_MSC_VER) && _MSC_VER >= 1400 + { "floor", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&__floor} }, + { "ceil", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&__ceil} }, +#else + { "floor", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&floor} }, + { "ceil", nseel_asm_1pdd,nseel_asm_1pdd_end, 1, {&ceil} }, +#endif +#ifdef __ppc__ + { "invsqrt", nseel_asm_invsqrt,nseel_asm_invsqrt_end, 1, }, +#else + { "invsqrt", nseel_asm_invsqrt,nseel_asm_invsqrt_end, 1, {&negativezeropointfive, &onepointfive} }, +#endif + + { "sigmoid", nseel_asm_2pdd,nseel_asm_2pdd_end, 2, {&eel1sigmoid}, }, + + // these differ from _and/_or, they always evaluate both... + { "band", nseel_asm_2pdd,nseel_asm_2pdd_end, 2, {&eel1band}, }, + { "bor", nseel_asm_2pdd,nseel_asm_2pdd_end, 2, {&eel1bor}, }, + + {"exec2",nseel_asm_exec2,nseel_asm_exec2_end,2}, + {"exec3",nseel_asm_exec2,nseel_asm_exec2_end,3}, + {"_mem",_asm_megabuf,_asm_megabuf_end,1,{&g_closefact,&__NSEEL_RAMAlloc},NSEEL_PProc_RAM}, + {"_gmem",_asm_megabuf,_asm_megabuf_end,1,{&g_closefact,&__NSEEL_RAMAllocGMEM},NSEEL_PProc_GRAM}, + {"freembuf",_asm_generic1parm,_asm_generic1parm_end,1,{&__NSEEL_RAM_MemFree},NSEEL_PProc_RAM}, + {"memcpy",_asm_generic3parm,_asm_generic3parm_end,3,{&__NSEEL_RAM_MemCpy},NSEEL_PProc_RAM}, + {"memset",_asm_generic3parm,_asm_generic3parm_end,3,{&__NSEEL_RAM_MemSet},NSEEL_PProc_RAM}, +}; + +static functionType *fnTableUser; +static int fnTableUser_size; + +functionType *nseel_getFunctionFromTable(int idx) +{ + if (idx<0) return 0; + if (idx>=sizeof(fnTable1)/sizeof(fnTable1[0])) + { + idx -= sizeof(fnTable1)/sizeof(fnTable1[0]); + if (!fnTableUser || idx >= fnTableUser_size) return 0; + return fnTableUser+idx; + } + return fnTable1+idx; +} + +int NSEEL_init() // returns 0 on success +{ + NSEEL_quit(); + return 0; +} + +void NSEEL_addfunctionex2(const char *name, int nparms, char *code_startaddr, int code_len, void *pproc, void *fptr, void *fptr2) +{ + if (!fnTableUser || !(fnTableUser_size&7)) + { + fnTableUser=(functionType *)realloc(fnTableUser,(fnTableUser_size+8)*sizeof(functionType)); + } + if (fnTableUser) + { + memset(&fnTableUser[fnTableUser_size],0,sizeof(functionType)); + fnTableUser[fnTableUser_size].nParams = nparms; + fnTableUser[fnTableUser_size].name = name; + fnTableUser[fnTableUser_size].afunc = code_startaddr; + fnTableUser[fnTableUser_size].func_e = code_startaddr + code_len; + fnTableUser[fnTableUser_size].pProc = (NSEEL_PPPROC) pproc; + fnTableUser[fnTableUser_size].replptrs[0]=fptr; + fnTableUser[fnTableUser_size].replptrs[1]=fptr2; + fnTableUser_size++; + } +} + +void NSEEL_quit() +{ + free(fnTableUser); + fnTableUser_size=0; + fnTableUser=0; +} + +//--------------------------------------------------------------------------------------------------------------- +static void freeBlocks(llBlock **start) +{ + llBlock *s=*start; + *start=0; + while (s) + { + llBlock *llB = s->next; +#ifdef _WIN32 + VirtualFree(s, 0 /*LLB_DSIZE*/, MEM_RELEASE); +#else + free(s); +#endif + s=llB; + } +} + +//--------------------------------------------------------------------------------------------------------------- +static void *__newBlock(llBlock **start, int size) +{ + llBlock *llb; + int alloc_size; + if (*start && (LLB_DSIZE - (*start)->sizeused) >= size) + { + void *t=(*start)->block+(*start)->sizeused; + (*start)->sizeused+=(size+7)&~7; + return t; + } + + alloc_size=sizeof(llBlock); + if ((int)size > LLB_DSIZE) alloc_size += size - LLB_DSIZE; + +#ifdef _WIN32 +#ifdef WINAPI_FAMILY && (WINAPI_FAMILY == WINAPI_FAMILY_APP) + DWORD ov; + UINT_PTR offs, eoffs; + + llb = (llBlock *)VirtualAlloc(NULL, alloc_size, MEM_COMMIT, PAGE_READWRITE); + + offs = ((UINT_PTR)llb)&~4095; + eoffs = ((UINT_PTR)llb + alloc_size + 4095)&~4095; + VirtualProtect((LPVOID)offs, eoffs - offs, PAGE_EXECUTE_READWRITE, &ov); +#else + llb = (llBlock *)VirtualAlloc(NULL, alloc_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); +#endif +#else + llb = (llBlock *)malloc(alloc_size); // grab bigger block if absolutely necessary (heh) +#endif +#if defined(EEL_USE_MPROTECT) + { + static int pagesize = 0; + if (!pagesize) + { + pagesize=sysconf(_SC_PAGESIZE); + if (!pagesize) pagesize=4096; + } + uintptr_t offs,eoffs; + offs=((uintptr_t)llb)&~(pagesize-1); + eoffs=((uintptr_t)llb + alloc_size + pagesize-1)&~(pagesize-1); + mprotect((void*)offs,eoffs-offs,PROT_WRITE|PROT_READ|PROT_EXEC); + } +#endif + llb->sizeused=(size+7)&~7; + llb->next = *start; + *start = llb; + return llb->block; +} + + +//--------------------------------------------------------------------------------------------------------------- +INT_PTR nseel_createCompiledValue(compileContext *ctx, EEL_F value, EEL_F *addrValue) +{ + unsigned char *block; + + block=(unsigned char *)newTmpBlock(GLUE_MOV_EAX_DIRECTVALUE_SIZE); + + if (addrValue == NULL) + { + *(addrValue = (EEL_F *)newBlock(sizeof(EEL_F),sizeof(EEL_F))) = value; + ctx->l_stats[3]+=sizeof(EEL_F); + } + + GLUE_MOV_EAX_DIRECTVALUE_GEN(block+4,(INT_PTR)addrValue); + + return ((INT_PTR)(block)); + +} + +//--------------------------------------------------------------------------------------------------------------- +static void *nseel_getFunctionAddress(int fntype, int fn, int *size, NSEEL_PPPROC *pProc, void ***replList) +{ + *replList=0; + switch (fntype) + { + case MATH_SIMPLE: + switch (fn) + { + case FN_ASSIGN: + return GLUE_realAddress(nseel_asm_assign,nseel_asm_assign_end,size); + case FN_ADD: + return GLUE_realAddress(nseel_asm_add,nseel_asm_add_end,size); + case FN_SUB: + return GLUE_realAddress(nseel_asm_sub,nseel_asm_sub_end,size); + case FN_MULTIPLY: + return GLUE_realAddress(nseel_asm_mul,nseel_asm_mul_end,size); + case FN_DIVIDE: + return GLUE_realAddress(nseel_asm_div,nseel_asm_div_end,size); + case FN_MODULO: + return GLUE_realAddress(nseel_asm_exec2,nseel_asm_exec2_end,size); + case FN_AND: + return GLUE_realAddress(nseel_asm_and,nseel_asm_and_end,size); + case FN_OR: + return GLUE_realAddress(nseel_asm_or,nseel_asm_or_end,size); + case FN_UPLUS: + return GLUE_realAddress(nseel_asm_uplus,nseel_asm_uplus_end,size); + case FN_UMINUS: + return GLUE_realAddress(nseel_asm_uminus,nseel_asm_uminus_end,size); + } + case MATH_FN: + { + functionType *p=nseel_getFunctionFromTable(fn); + if (p) + { + *replList=p->replptrs; + *pProc=p->pProc; + return GLUE_realAddress(p->afunc,p->func_e,size); + } + } + } + + *size=0; + return 0; +} + + +//--------------------------------------------------------------------------------------------------------------- +INT_PTR nseel_createCompiledFunction3(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code1, INT_PTR code2, INT_PTR code3) +{ + int sizes1=((int *)code1)[0]; + int sizes2=((int *)code2)[0]; + int sizes3=((int *)code3)[0]; + + if (fntype == MATH_FN && fn == 0) // special case: IF + { + void *func3; + int size; + INT_PTR *ptr; + char *block; + + unsigned char *newblock2,*newblock3; + unsigned char *p; + + p=newblock2=newBlock(sizes2+sizeof(GLUE_RET)+GLUE_FUNC_ENTER_SIZE+GLUE_FUNC_LEAVE_SIZE,32); + memcpy(p,&GLUE_FUNC_ENTER,GLUE_FUNC_ENTER_SIZE); p+=GLUE_FUNC_ENTER_SIZE; + memcpy(p,(char*)code2+4,sizes2); p+=sizes2; + memcpy(p,&GLUE_FUNC_LEAVE,GLUE_FUNC_LEAVE_SIZE); p+=GLUE_FUNC_LEAVE_SIZE; + memcpy(p,&GLUE_RET,sizeof(GLUE_RET)); p+=sizeof(GLUE_RET); + + p=newblock3=newBlock(sizes3+sizeof(GLUE_RET)+GLUE_FUNC_ENTER_SIZE+GLUE_FUNC_LEAVE_SIZE,32); + memcpy(p,&GLUE_FUNC_ENTER,GLUE_FUNC_ENTER_SIZE); p+=GLUE_FUNC_ENTER_SIZE; + memcpy(p,(char*)code3+4,sizes3); p+=sizes3; + memcpy(p,&GLUE_FUNC_LEAVE,GLUE_FUNC_LEAVE_SIZE); p+=GLUE_FUNC_LEAVE_SIZE; + memcpy(p,&GLUE_RET,sizeof(GLUE_RET)); p+=sizeof(GLUE_RET); + + ctx->l_stats[2]+=sizes2+sizes3+sizeof(GLUE_RET)*2; + + func3 = GLUE_realAddress(nseel_asm_if,nseel_asm_if_end,&size); + + block=(char *)newTmpBlock(sizes1+size); + + memcpy(block+4,(char*)code1+4,sizes1); + ptr=(INT_PTR *)(block+4+sizes1); + memcpy(ptr,func3,size); + + ptr=EEL_GLUE_set_immediate(ptr,&g_closefact); + ptr=EEL_GLUE_set_immediate(ptr,newblock2); + EEL_GLUE_set_immediate(ptr,newblock3); + + ctx->computTableTop++; + + return (INT_PTR)block; + + } + else + { + int size2; + unsigned char *block; + unsigned char *outp; + + void *myfunc; + NSEEL_PPPROC preProc=0; + void **repl; + + myfunc = nseel_getFunctionAddress(fntype, fn, &size2, &preProc,&repl); + + block=(unsigned char *)newTmpBlock(size2+sizes1+sizes2+sizes3+ + sizeof(GLUE_PUSH_EAX) + + sizeof(GLUE_PUSH_EAX) + + sizeof(GLUE_POP_EBX) + + sizeof(GLUE_POP_ECX)); + + outp=block+4; + memcpy(outp,(char*)code1+4,sizes1); + outp+=sizes1; + memcpy(outp,&GLUE_PUSH_EAX,sizeof(GLUE_PUSH_EAX)); outp+=sizeof(GLUE_PUSH_EAX); + memcpy(outp,(char*)code2+4,sizes2); + outp+=sizes2; + memcpy(outp,&GLUE_PUSH_EAX,sizeof(GLUE_PUSH_EAX)); outp+=sizeof(GLUE_PUSH_EAX); + memcpy(outp,(char*)code3+4,sizes3); + outp+=sizes3; + memcpy(outp,&GLUE_POP_EBX,sizeof(GLUE_POP_EBX)); outp+=sizeof(GLUE_POP_EBX); + memcpy(outp,&GLUE_POP_ECX,sizeof(GLUE_POP_ECX)); outp+=sizeof(GLUE_POP_ECX); + + memcpy(outp,myfunc,size2); + if (preProc) preProc(outp,size2,ctx); + if (repl) + { + if (repl[0]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[0]); + if (repl[1]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[1]); + if (repl[2]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[2]); + if (repl[3]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[3]); + } + + ctx->computTableTop++; + + return ((INT_PTR)(block)); + } +} + +//--------------------------------------------------------------------------------------------------------------- +INT_PTR nseel_createCompiledFunction2(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code1, INT_PTR code2) +{ + int size2; + unsigned char *outp; + void *myfunc; + int sizes1=((int *)code1)[0]; + int sizes2=((int *)code2)[0]; + if (fntype == MATH_FN && (fn == 1 || fn == 2 || fn == 3)) // special case: LOOP/BOR/BAND + { + void *func3; + int size; + INT_PTR *ptr; + char *block; + + unsigned char *newblock2, *p; + + p=newblock2=newBlock(sizes2+sizeof(GLUE_RET)+GLUE_FUNC_ENTER_SIZE+GLUE_FUNC_LEAVE_SIZE,32); + memcpy(p,&GLUE_FUNC_ENTER,GLUE_FUNC_ENTER_SIZE); p+=GLUE_FUNC_ENTER_SIZE; + memcpy(p,(char*)code2+4,sizes2); p+=sizes2; + memcpy(p,&GLUE_FUNC_LEAVE,GLUE_FUNC_LEAVE_SIZE); p+=GLUE_FUNC_LEAVE_SIZE; + memcpy(p,&GLUE_RET,sizeof(GLUE_RET)); p+=sizeof(GLUE_RET); + + ctx->l_stats[2]+=sizes2+2; + + if (fn == 1) func3 = GLUE_realAddress(nseel_asm_band,nseel_asm_band_end,&size); + else if (fn == 3) func3 = GLUE_realAddress(nseel_asm_repeat,nseel_asm_repeat_end,&size); + else func3 = GLUE_realAddress(nseel_asm_bor,nseel_asm_bor_end,&size); + + block=(char *)newTmpBlock(sizes1+size); + memcpy(block+4,(char*)code1+4,sizes1); + ptr=(INT_PTR *)(block+4+sizes1); + memcpy(ptr,func3,size); + + if (fn!=3) ptr=EEL_GLUE_set_immediate(ptr,&g_closefact); // for or/and + ptr=EEL_GLUE_set_immediate(ptr,newblock2); + if (fn!=3) ptr=EEL_GLUE_set_immediate(ptr,&g_closefact); // for or/and +#ifdef __ppc__ + if (fn!=3) // for or/and on ppc we need a one + { + ptr=EEL_GLUE_set_immediate(ptr,&eel_one); + } +#endif + + ctx->computTableTop++; + return (INT_PTR)block; + } + + { + NSEEL_PPPROC preProc=0; + unsigned char *block; + void **repl; + myfunc = nseel_getFunctionAddress(fntype, fn, &size2,&preProc,&repl); + + block=(unsigned char *)newTmpBlock(size2+sizes1+sizes2+sizeof(GLUE_PUSH_EAX)+sizeof(GLUE_POP_EBX)); + + outp=block+4; + memcpy(outp,(char*)code1+4,sizes1); + outp+=sizes1; + memcpy(outp,&GLUE_PUSH_EAX,sizeof(GLUE_PUSH_EAX)); outp+=sizeof(GLUE_PUSH_EAX); + memcpy(outp,(char*)code2+4,sizes2); + outp+=sizes2; + memcpy(outp,&GLUE_POP_EBX,sizeof(GLUE_POP_EBX)); outp+=sizeof(GLUE_POP_EBX); + + memcpy(outp,myfunc,size2); + if (preProc) preProc(outp,size2,ctx); + if (repl) + { + if (repl[0]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[0]); + if (repl[1]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[1]); + if (repl[2]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[2]); + if (repl[3]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[3]); + } + + ctx->computTableTop++; + + return ((INT_PTR)(block)); + } +} + + +//--------------------------------------------------------------------------------------------------------------- +INT_PTR nseel_createCompiledFunction1(compileContext *ctx, int fntype, INT_PTR fn, INT_PTR code) +{ + NSEEL_PPPROC preProc=0; + int size,size2; + char *block; + void *myfunc; + void *func1; + + size =((int *)code)[0]; + func1 = (void *)(code+4); + + + if (fntype == MATH_FN && fn == 4) // special case: while + { + void *func3; + INT_PTR *ptr; + + unsigned char *newblock2, *p; + + p=newblock2=newBlock(size+sizeof(GLUE_RET)+GLUE_FUNC_ENTER_SIZE+GLUE_FUNC_LEAVE_SIZE,32); + memcpy(p,&GLUE_FUNC_ENTER,GLUE_FUNC_ENTER_SIZE); p+=GLUE_FUNC_ENTER_SIZE; + memcpy(p,func1,size); p+=size; + memcpy(p,&GLUE_FUNC_LEAVE,GLUE_FUNC_LEAVE_SIZE); p+=GLUE_FUNC_LEAVE_SIZE; + memcpy(p,&GLUE_RET,sizeof(GLUE_RET)); p+=sizeof(GLUE_RET); + + ctx->l_stats[2]+=size+2; + + func3 = GLUE_realAddress(nseel_asm_repeatwhile,nseel_asm_repeatwhile_end,&size); + + block=(char *)newTmpBlock(size); + ptr = (INT_PTR *)(block+4); + memcpy(ptr,func3,size); + ptr=EEL_GLUE_set_immediate(ptr,newblock2); + EEL_GLUE_set_immediate(ptr,&g_closefact); + + ctx->computTableTop++; + return (INT_PTR)block; + } + + { + void **repl; + myfunc = nseel_getFunctionAddress(fntype, fn, &size2,&preProc,&repl); + + block=(char *)newTmpBlock(size+size2); + + memcpy(block+4, func1, size); + memcpy(block+size+4,myfunc,size2); + if (preProc) preProc(block+size+4,size2,ctx); + if (repl) + { + unsigned char *outp=(unsigned char *)block+size+4; + if (repl[0]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[0]); + if (repl[1]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[1]); + if (repl[2]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[2]); + if (repl[3]) outp=(unsigned char *)EEL_GLUE_set_immediate(outp,repl[3]); + } + + ctx->computTableTop++; + + return ((INT_PTR)(block)); + } +} + + +static char *preprocessCode(compileContext *ctx, char *expression) +{ + char *expression_start=expression; + int len=0; + int alloc_len=strlen(expression)+1+64; + char *buf=(char *)malloc(alloc_len); + int semicnt=0; + // we need to call onCompileNewLine for each new line we get + + //onCompileNewLine(ctx, + + while (*expression) + { + if (len > alloc_len-64) + { + alloc_len = len+128; + buf=(char*)realloc(buf,alloc_len); + } + + if (expression[0] == '/') + { + if (expression[1] == '/') + { + expression+=2; + while (expression[0] && expression[0] != '\n') expression++; + continue; + } + else if (expression[1] == '*') + { + expression+=2; + while (expression[0] && (expression[0] != '*' || expression[1] != '/')) + { + if (expression[0] == '\n') onCompileNewLine(ctx,expression+1-expression_start,len); + expression++; + } + if (expression[0]) expression+=2; // at this point we KNOW expression[0]=* and expression[1]=/ + continue; + } + } + + if (expression[0] == '$') + { + if (toupper(expression[1]) == 'X') + { + char *p=expression+2; + unsigned int v=strtoul(expression+2,&p,16); + char tmp[64]; + expression=p; + + sprintf(tmp,"%u",v); + memcpy(buf+len,tmp,strlen(tmp)); + len+=strlen(tmp); + ctx->l_stats[0]+=strlen(tmp); + continue; + + } + if (expression[1]=='\'' && expression[2] && expression[3]=='\'') + { + char tmp[64]; + sprintf(tmp,"%u",((unsigned char *)expression)[2]); + expression+=4; + + memcpy(buf+len,tmp,strlen(tmp)); + len+=strlen(tmp); + ctx->l_stats[0]+=strlen(tmp); + continue; + } + if (toupper(expression[1]) == 'P' && toupper(expression[2]) == 'I') + { + static char *str="3.141592653589793"; + expression+=3; + memcpy(buf+len,str,17); + len+=17; //strlen(str); + ctx->l_stats[0]+=17; + continue; + } + if (toupper(expression[1]) == 'E') + { + static char *str="2.71828183"; + expression+=2; + memcpy(buf+len,str,10); + len+=10; //strlen(str); + ctx->l_stats[0]+=10; + continue; + } + if (toupper(expression[1]) == 'P' && toupper(expression[2]) == 'H' && toupper(expression[3]) == 'I') + { + static char *str="1.61803399"; + expression+=4; + memcpy(buf+len,str,10); + len+=10; //strlen(str); + ctx->l_stats[0]+=10; + continue; + } + + } + + { + char c=*expression++; + + if (c == '\n') onCompileNewLine(ctx,expression-expression_start,len); + if (isspace(c)) c=' '; + + if (c == '(') semicnt++; + else if (c == ')') { semicnt--; if (semicnt < 0) semicnt=0; } + else if (c == ';' && semicnt > 0) + { + // convert ; to % if next nonwhitespace char is alnum, otherwise convert to space + int p=0; + int nc; + int commentstate=0; + while ((nc=expression[p])) + { + if (!commentstate && nc == '/') + { + if (expression[p+1] == '/') commentstate=1; + else if (expression[p+1] == '*') commentstate=2; + } + + if (commentstate == 1 && nc == '\n') commentstate=0; + else if (commentstate == 2 && nc == '*' && expression[p+1]=='/') + { + p++; // skip * + commentstate=0; + } + else if (!commentstate && !isspace(nc)) break; + + p++; + } + // fucko, we should look for even more chars, me thinks + if (nc && (isalnum(nc) +#if 1 + || nc == '(' || nc == '_' || nc == '!' || nc == '$' +#endif + )) c='%'; + else c = ' '; // stray ; + } +#if 0 + else if (semicnt > 0 && c == ',') + { + int p=0; + int nc; + while ((nc=expression[p]) && isspace(nc)) p++; + if (nc == ',' || nc == ')') + { + expression += p+1; + buf[len++]=','; + buf[len++]='0'; + c=nc; // append this char + } + } +#endif + // list of operators + + else if (!isspace(c) && !isalnum(c)) // check to see if this operator is ours + { + + static char *symbollists[]= + { + "", // or any control char that is not parenthed + ":(,;?%", + ",):?;", // or || or && + ",);", // jf> removed :? from this, for = + ",);", + "", // only scans for a negative ] level + + }; + + + static struct + { + char op[2]; + char lscan,rscan; + char *func; + } preprocSymbols[] = + { + {{'+','='}, 0, 3, "_addop" }, + {{'-','='}, 0, 3, "_subop" }, + {{'%','='}, 0, 3, "_modop" }, + {{'|','='}, 0, 3, "_orop" }, + {{'&','='}, 0, 3, "_andop"}, + + {{'/','='}, 0, 3, "_divop"}, + {{'*','='}, 0, 3, "_mulop"}, + {{'^','='}, 0, 3, "_powop"}, + + {{'=','='}, 1, 2, "_equal" }, + {{'<','='}, 1, 2, "_beleq" }, + {{'>','='}, 1, 2, "_aboeq" }, + {{'<',0 }, 1, 2, "_below" }, + {{'>',0 }, 1, 2, "_above" }, + {{'!','='}, 1, 2, "_noteq" }, + {{'|','|'}, 1, 2, "_or" }, + {{'&','&'}, 1, 2, "_and" }, + {{'=',0 }, 0, 3, "_set" }, + {{'%',0}, 0, 0, "_mod" }, + {{'^',0}, 0, 0, "pow" }, + + + {{'[',0 }, 0, 5, }, + {{'!',0 },-1, 0, }, // this should also ignore any leading +- + {{'?',0 }, 1, 4, }, + + }; + + + int n; + int ns=sizeof(preprocSymbols)/sizeof(preprocSymbols[0]); + for (n = 0; n < ns; n++) + { + if (c == preprocSymbols[n].op[0] && (!preprocSymbols[n].op[1] || expression[0] == preprocSymbols[n].op[1])) + { + break; + } + } + if (n < ns) + { + + int lscan=preprocSymbols[n].lscan; + int rscan=preprocSymbols[n].rscan; + + // parse left side of =, scanning back for an unparenthed nonwhitespace nonalphanumeric nonparenth? + // so megabuf(x+y)= would be fine, x=, but +x= would do +set(x,) + char *l_ptr=0; + char *r_ptr=0; + if (lscan >= 0) + { + char *scan=symbollists[lscan]; + int l_semicnt=0; + l_ptr=buf + len - 1; + while (l_ptr >= buf) + { + if (*l_ptr == ')') l_semicnt++; + else if (*l_ptr == '(') + { + l_semicnt--; + if (l_semicnt < 0) break; + } + else if (!l_semicnt) + { + if (!*scan) + { + if (!isspace(*l_ptr) && !isalnum(*l_ptr) && *l_ptr != '_' && *l_ptr != '.') break; + } + else + { + char *sc=scan; + if (lscan == 2 && ( // not currently used, even + (l_ptr[0]=='|' && l_ptr[1] == '|')|| + (l_ptr[0]=='&' && l_ptr[1] == '&') + ) + ) break; + while (*sc && *l_ptr != *sc) sc++; + if (*sc) break; + } + } + l_ptr--; + } + buf[len]=0; + + l_ptr++; + + len = l_ptr - buf; + + l_ptr = _strdup(l_ptr); // doesn't need to be preprocessed since it just was + } + if (preprocSymbols[n].op[1]) expression++; + + r_ptr=expression; + { + // scan forward to an uncommented, unparenthed semicolon, comma, or ) + int r_semicnt=0; + int r_qcnt=0; + char *scan=symbollists[rscan]; + int commentstate=0; + int hashadch=0; + int bracketcnt=0; + while (*r_ptr) + { + if (!commentstate && *r_ptr == '/') + { + if (r_ptr[1] == '/') commentstate=1; + else if (r_ptr[1] == '*') commentstate=2; + } + if (commentstate == 1 && *r_ptr == '\n') commentstate=0; + else if (commentstate == 2 && *r_ptr == '*' && r_ptr[1]=='/') + { + r_ptr++; // skip * + commentstate=0; + } + else if (!commentstate) + { + if (*r_ptr == '(') {hashadch=1; r_semicnt++; } + else if (*r_ptr == ')') + { + r_semicnt--; + if (r_semicnt < 0) break; + } + else if (!r_semicnt) + { + char *sc=scan; + if (*r_ptr == ';' || *r_ptr == ',') break; + + if (!rscan) + { + if (*r_ptr == ':') break; + if (!isspace(*r_ptr) && !isalnum(*r_ptr) && *r_ptr != '_' && *r_ptr != '.' && hashadch) break; + if (isalnum(*r_ptr) || *r_ptr == '_')hashadch=1; + } + else if (rscan == 2 && + ((r_ptr[0]=='|' && r_ptr[1] == '|')|| + (r_ptr[0]=='&' && r_ptr[1] == '&') + ) + ) break; + + else if (rscan == 3 || rscan == 4) + { + if (*r_ptr == ':') r_qcnt--; + else if (*r_ptr == '?') r_qcnt++; + + if (r_qcnt < 3-rscan) break; + } + else if (rscan == 5) + { + if (*r_ptr == '[') bracketcnt++; + else if (*r_ptr == ']') bracketcnt--; + if (bracketcnt < 0) break; + } + + while (*sc && *r_ptr != *sc) sc++; + if (*sc) break; + } + } + r_ptr++; + } + // expression -> r_ptr is our string (not including r_ptr) + + { + char *orp=r_ptr; + + char rps=*orp; + *orp=0; // temporarily terminate + + r_ptr=preprocessCode(ctx,expression); + expression=orp; + + *orp = rps; // fix termination(restore string) + } + + } + + if (r_ptr) + { + int thisl = strlen(l_ptr?l_ptr:"") + strlen(r_ptr) + 32; + + if (len+thisl > alloc_len-64) + { + alloc_len = len+thisl+128; + buf=(char*)realloc(buf,alloc_len); + } + + + if (n == ns-3) + { + char *lp = l_ptr; + char *rp = r_ptr; + while (lp && *lp && isspace(*lp)) lp++; + while (rp && *rp && isspace(*rp)) rp++; + if (lp && !strncasecmp(lp,"gmem",4) && (!lp[4] || isspace(lp[4]))) + { + len+=sprintf(buf+len,"_gmem(%s",r_ptr && *r_ptr ? r_ptr : "0"); + ctx->l_stats[0]+=strlen(l_ptr)+4; + } + else if (rp && *rp && strcmp(rp,"0")) + { + len+=sprintf(buf+len,"_mem((%s)+(%s)",lp,rp); + ctx->l_stats[0]+=strlen(lp)+strlen(rp)+8; + } + else + { + len+=sprintf(buf+len,"_mem(%s",lp); + ctx->l_stats[0]+=strlen(lp)+4; + } + + // skip the ] + if (*expression == ']') expression++; + + } + else if (n == ns-2) + { + len+=sprintf(buf+len,"_not(%s", + r_ptr); + + ctx->l_stats[0]+=4; + } + else if (n == ns-1)// if (l_ptr,r_ptr1,r_ptr2) + { + char *rptr2=r_ptr; + char *tmp=r_ptr; + int parcnt=0; + int qcnt=1; + while (*rptr2) + { + if (*rptr2 == '?') qcnt++; + else if (*rptr2 == ':') qcnt--; + else if (*rptr2 == '(') parcnt++; + else if (*rptr2 == ')') parcnt--; + if (parcnt < 0) break; + if (!parcnt && !qcnt && *rptr2 == ':') break; + rptr2++; + } + if (*rptr2) *rptr2++=0; + while (isspace(*rptr2)) rptr2++; + + while (isspace(*tmp)) tmp++; + + len+=sprintf(buf+len,"_if(%s,%s,%s",l_ptr,*tmp?tmp:"0",*rptr2?rptr2:"0"); + ctx->l_stats[0]+=6; + } + else + { + len+=sprintf(buf+len,"%s(%s,%s",preprocSymbols[n].func,l_ptr?l_ptr:"",r_ptr); + ctx->l_stats[0]+=strlen(preprocSymbols[n].func)+2; + } + + } + + free(r_ptr); + free(l_ptr); + + + c = ')'; // close parenth below + } + } + +// if (c != ' ' || (len && buf[len-1] != ' ')) // don't bother adding multiple spaces + { + buf[len++]=c; + if (c != ' ') ctx->l_stats[0]++; + } + } + } + buf[len]=0; + + return buf; +} + +#ifdef PPROC_TEST + +int main(int argc, char* argv[]) +{ + compileContext ctx={0}; + char *p=preprocessCode(&ctx,argv[1]); + if (p)printf("%s\n",p); + free(p); + return 0; +} + +#endif + +#if 0 +static void movestringover(char *str, int amount) +{ + char tmp[1024+8]; + + int l=(int)strlen(str); + l=min(1024-amount-1,l); + + memcpy(tmp,str,l+1); + + while (l >= 0 && tmp[l]!='\n') l--; + l++; + + tmp[l]=0;//ensure we null terminate + + memcpy(str+amount,tmp,l+1); +} +#endif + +//------------------------------------------------------------------------------ +NSEEL_CODEHANDLE NSEEL_code_compile(NSEEL_VMCTX _ctx, char *_expression, int lineoffs) +{ + compileContext *ctx = (compileContext *)_ctx; + char *expression,*expression_start; + int computable_size=0; + codeHandleType *handle; + startPtr *scode=NULL; + startPtr *startpts=NULL; + + if (!ctx) return 0; + + ctx->last_error_string[0]=0; + + if (!_expression || !*_expression) return 0; + + freeBlocks((llBlock **)&ctx->tmpblocks_head); // free blocks + freeBlocks((llBlock **)&ctx->blocks_head); // free blocks + memset(ctx->l_stats,0,sizeof(ctx->l_stats)); + free(ctx->compileLineRecs); ctx->compileLineRecs=0; ctx->compileLineRecs_size=0; ctx->compileLineRecs_alloc=0; + + handle = (codeHandleType*)newBlock(sizeof(codeHandleType),8); + + if (!handle) + { + return 0; + } + + memset(handle,0,sizeof(codeHandleType)); + + expression_start=expression=preprocessCode(ctx,_expression); + + + while (*expression) + { + void *startptr; + char *expr; + ctx->colCount=0; + ctx->computTableTop=0; + + // single out segment + while (*expression == ';' || isspace(*expression)) expression++; + if (!*expression) break; + expr=expression; + + while (*expression && *expression != ';') expression++; + if (*expression) *expression++ = 0; + + // parse + + startptr=nseel_compileExpression(ctx,expr); + + if (ctx->computTableTop > NSEEL_MAX_TEMPSPACE_ENTRIES- /* safety */ 16 - /* alignment */4 || + !startptr) + { + int byteoffs = expr - expression_start; + int destoffs,linenumber; + char buf[21], *p; + int x,le; + +#ifdef NSEEL_EEL1_COMPAT_MODE + if (!startptr) continue; +#endif + if (ctx->errVar > 0) byteoffs += ctx->errVar; + linenumber=findByteOffsetInSource(ctx,byteoffs,&destoffs); + if (destoffs < 0) destoffs=0; + + le=strlen(_expression); + if (destoffs >= le) destoffs=le; + p= _expression + destoffs; + for (x = 0;x < 20; x ++) + { + if (!*p || *p == '\r' || *p == '\n') break; + buf[x]=*p++; + } + buf[x]=0; + + sprintf(ctx->last_error_string,"Around line %d '%s'",linenumber+lineoffs,buf); + + ctx->last_error_string[sizeof(ctx->last_error_string)-1]=0; + scode=NULL; + break; + } + if (computable_size < ctx->computTableTop) + { + computable_size=ctx->computTableTop; + } + + { + startPtr *tmp=(startPtr*) __newBlock((llBlock **)&ctx->tmpblocks_head,sizeof(startPtr)); + if (!tmp) break; + + tmp->startptr = startptr; + tmp->next=NULL; + if (!scode) scode=startpts=tmp; + else + { + scode->next=tmp; + scode=tmp; + } + } +} + free(ctx->compileLineRecs); ctx->compileLineRecs=0; ctx->compileLineRecs_size=0; ctx->compileLineRecs_alloc=0; + + // check to see if failed on the first startingCode + if (!scode) + { + handle=NULL; // return NULL (after resetting blocks_head) + } + else + { + char *tabptr = (char *)(handle->workTable=calloc(computable_size+64, sizeof(EEL_F))); + unsigned char *writeptr; + startPtr *p=startpts; + int size=sizeof(GLUE_RET)+GLUE_FUNC_ENTER_SIZE+GLUE_FUNC_LEAVE_SIZE; // for ret at end :) + + if (((INT_PTR)tabptr)&31) + tabptr += 32-(((INT_PTR)tabptr)&31); + + // now we build one big code segment out of our list of them, inserting a mov esi, computable before each item + while (p) + { + size += GLUE_RESET_ESI(NULL,0); + size+=*(int *)p->startptr; + p=p->next; + } + handle->code = newBlock(size,32); + if (handle->code) + { + writeptr=(unsigned char *)handle->code; + memcpy(writeptr,&GLUE_FUNC_ENTER,GLUE_FUNC_ENTER_SIZE); writeptr += GLUE_FUNC_ENTER_SIZE; + p=startpts; + while (p) + { + int thissize=*(int *)p->startptr; + writeptr+=GLUE_RESET_ESI(writeptr,tabptr); + //memcpy(writeptr,&GLUE_MOV_ESI_EDI,sizeof(GLUE_MOV_ESI_EDI)); + //writeptr+=sizeof(GLUE_MOV_ESI_EDI); + memcpy(writeptr,(char*)p->startptr + 4,thissize); + writeptr += thissize; + + p=p->next; + } + memcpy(writeptr,&GLUE_FUNC_LEAVE,GLUE_FUNC_LEAVE_SIZE); writeptr += GLUE_FUNC_LEAVE_SIZE; + memcpy(writeptr,&GLUE_RET,sizeof(GLUE_RET)); writeptr += sizeof(GLUE_RET); + ctx->l_stats[1]=size; + } + handle->blocks = ctx->blocks_head; + ctx->blocks_head=0; + + } + freeBlocks((llBlock **)&ctx->tmpblocks_head); // free blocks + freeBlocks((llBlock **)&ctx->blocks_head); // free blocks + + if (handle) + { + memcpy(handle->code_stats,ctx->l_stats,sizeof(ctx->l_stats)); + nseel_evallib_stats[0]+=ctx->l_stats[0]; + nseel_evallib_stats[1]+=ctx->l_stats[1]; + nseel_evallib_stats[2]+=ctx->l_stats[2]; + nseel_evallib_stats[3]+=ctx->l_stats[3]; + nseel_evallib_stats[4]++; + } + memset(ctx->l_stats,0,sizeof(ctx->l_stats)); + + free(expression_start); + + return (NSEEL_CODEHANDLE)handle; +} + +//------------------------------------------------------------------------------ +void NSEEL_code_execute(NSEEL_CODEHANDLE code) +{ + INT_PTR tabptr; + INT_PTR codeptr; + codeHandleType *h = (codeHandleType *)code; + if (!h || !h->code) return; + + codeptr = (INT_PTR) h->code; +#if 0 + { + unsigned int *p=(unsigned int *)codeptr; + while (*p != GLUE_RET[0]) + { + printf("instr:%04X:%04X\n",*p>>16,*p&0xffff); + p++; + } + } +#endif + + tabptr=(INT_PTR)h->workTable; + if (tabptr&31) + tabptr += 32-((tabptr)&31); + //printf("calling code!\n"); + GLUE_CALL_CODE(tabptr,codeptr); + +} + + +char *NSEEL_code_getcodeerror(NSEEL_VMCTX ctx) +{ + compileContext *c=(compileContext *)ctx; + if (ctx && c->last_error_string[0]) return c->last_error_string; + return 0; +} + +//------------------------------------------------------------------------------ +void NSEEL_code_free(NSEEL_CODEHANDLE code) +{ + codeHandleType *h = (codeHandleType *)code; + if (h != NULL) + { + free(h->workTable); + nseel_evallib_stats[0]-=h->code_stats[0]; + nseel_evallib_stats[1]-=h->code_stats[1]; + nseel_evallib_stats[2]-=h->code_stats[2]; + nseel_evallib_stats[3]-=h->code_stats[3]; + nseel_evallib_stats[4]--; + freeBlocks(&h->blocks); + + + } + +} + + +//------------------------------------------------------------------------------ +void NSEEL_VM_resetvars(NSEEL_VMCTX _ctx) +{ + if (_ctx) + { + compileContext *ctx=(compileContext *)_ctx; + int x; + if (ctx->varTable_Names || ctx->varTable_Values) for (x = 0; x < ctx->varTable_numBlocks; x ++) + { + if (ctx->varTable_Names) free(ctx->varTable_Names[x]); + if (ctx->varTable_Values) free(ctx->varTable_Values[x]); + } + + free(ctx->varTable_Values); + free(ctx->varTable_Names); + ctx->varTable_Values=0; + ctx->varTable_Names=0; + + ctx->varTable_numBlocks=0; + } +} + + +NSEEL_VMCTX NSEEL_VM_alloc() // return a handle +{ + compileContext *ctx=calloc(1,sizeof(compileContext)); + return ctx; +} + +void NSEEL_VM_free(NSEEL_VMCTX _ctx) // free when done with a VM and ALL of its code have been freed, as well +{ + + if (_ctx) + { + compileContext *ctx=(compileContext *)_ctx; + NSEEL_VM_resetvars(_ctx); + NSEEL_VM_freeRAM(_ctx); + + freeBlocks((llBlock **)&ctx->tmpblocks_head); // free blocks + freeBlocks((llBlock **)&ctx->blocks_head); // free blocks + free(ctx->compileLineRecs); + free(ctx); + } + +} + +int *NSEEL_code_getstats(NSEEL_CODEHANDLE code) +{ + codeHandleType *h = (codeHandleType *)code; + if (h) + { + return h->code_stats; + } + return 0; +} + +void NSEEL_VM_SetCustomFuncThis(NSEEL_VMCTX ctx, void *thisptr) +{ + if (ctx) + { + compileContext *c=(compileContext*)ctx; + c->caller_this=thisptr; + } +} + + + + + +void NSEEL_PProc_RAM(void *data, int data_size, compileContext *ctx) +{ + if (data_size>0) EEL_GLUE_set_immediate(data, &ctx->ram_blocks); +} +void NSEEL_PProc_THIS(void *data, int data_size, compileContext *ctx) +{ + if (data_size>0) EEL_GLUE_set_immediate(data, ctx->caller_this); +} diff --git a/lib/vis_milkdrop/ns-eel2/nseel-eval.c b/lib/vis_milkdrop/ns-eel2/nseel-eval.c new file mode 100644 index 0000000..2dc1d06 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-eval.c @@ -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 +#include +#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; +} diff --git a/lib/vis_milkdrop/ns-eel2/nseel-lextab.c b/lib/vis_milkdrop/ns-eel2/nseel-lextab.c new file mode 100644 index 0000000..9d90b76 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-lextab.c @@ -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, + }; + + diff --git a/lib/vis_milkdrop/ns-eel2/nseel-ram.c b/lib/vis_milkdrop/ns-eel2/nseel-ram.c new file mode 100644 index 0000000..d20dd44 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-ram.c @@ -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 +#include +#include +#include + + +#ifdef _WIN32 +#include +#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; + } +} \ No newline at end of file diff --git a/lib/vis_milkdrop/ns-eel2/nseel-yylex.c b/lib/vis_milkdrop/ns-eel2/nseel-yylex.c new file mode 100644 index 0000000..605b477 --- /dev/null +++ b/lib/vis_milkdrop/ns-eel2/nseel-yylex.c @@ -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; cllsave[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); +} diff --git a/lib/vis_milkdrop/plugin.cpp b/lib/vis_milkdrop/plugin.cpp index 715e4de..e678fc8 100644 --- a/lib/vis_milkdrop/plugin.cpp +++ b/lib/vis_milkdrop/plugin.cpp @@ -499,6 +499,9 @@ extern char g_visName[]; // declared in MilkDropXBMC.cpp extern bool g_bDebugOutput; extern bool g_bDumpFileCleared; +void NSEEL_HOSTSTUB_EnterMutex() {} +void NSEEL_HOSTSTUB_LeaveMutex() {} + // these callback functions are called by menu.cpp whenever the user finishes editing an eval_ expression. void OnUserEditedPerFrame(LPARAM param1, LPARAM param2) { @@ -1014,7 +1017,7 @@ int CPlugin::AllocateMyNonDx8Stuff() BuildMenus(); - m_bMMX = CheckForMMX(); + //m_bMMX = CheckForMMX(); //m_bSSE = CheckForSSE(); m_pState->Default(); diff --git a/lib/vis_milkdrop/state.cpp b/lib/vis_milkdrop/state.cpp index 532d95b..07805f7 100644 --- a/lib/vis_milkdrop/state.cpp +++ b/lib/vis_milkdrop/state.cpp @@ -29,7 +29,7 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "state.h" #include "support.h" -#include "evallib/compiler.h" +//#include "evallib/compiler.h" #include "plugin.h" #include "utility.h" @@ -50,22 +50,39 @@ CState::CState() // it is a SUBSET of the per-vertex calculation variable list. m_pf_codehandle = NULL; m_pp_codehandle = NULL; - for (int i=0; im_szUserMessage, "warning: preset \"%s\": error in 'per_frame_init' code", m_szDesc); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; - q_values_after_init_code[0] = 0; - q_values_after_init_code[1] = 0; - q_values_after_init_code[2] = 0; - q_values_after_init_code[3] = 0; - q_values_after_init_code[4] = 0; - q_values_after_init_code[5] = 0; - q_values_after_init_code[6] = 0; - q_values_after_init_code[7] = 0; - monitor_after_init_code = 0; + for (int vi = 0; vi<8; vi++) + q_values_after_init_code[vi] = 0; + monitor_after_init_code = 0; } else { // now execute the code, save the values of q1..q8, and clean up the code! - g_plugin->LoadPerFrameEvallibVars(g_plugin->m_pState); + g_plugin->LoadPerFrameEvallibVars(g_plugin->m_pState); - executeCode(pf_codehandle_init); + NSEEL_code_execute(pf_codehandle_init); q_values_after_init_code[0] = *var_pf_q1; q_values_after_init_code[1] = *var_pf_q2; @@ -1523,39 +1527,34 @@ void CState::RecompileExpressions(int flags, int bReInit) q_values_after_init_code[5] = *var_pf_q6; q_values_after_init_code[6] = *var_pf_q7; q_values_after_init_code[7] = *var_pf_q8; - monitor_after_init_code = *var_pf_monitor; + monitor_after_init_code = *var_pf_monitor; - freeCode(pf_codehandle_init); + NSEEL_code_free(pf_codehandle_init); pf_codehandle_init = NULL; } - } + } // 2. compile preset per-frame code StripLinefeedCharsAndComments(m_szPerFrameExpr, buf); if (buf[0]) { - if ( ! (m_pf_codehandle = compileCode(buf))) + if ( ! (m_pf_codehandle = NSEEL_code_compile(m_pf_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in 'per_frame' code", m_szDesc); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; } } - resetVars(NULL); - resetVars(m_pv_vars); - // 3. compile preset per-pixel code StripLinefeedCharsAndComments(m_szPerPixelExpr, buf); if (buf[0]) { - if ( ! (m_pp_codehandle = compileCode(buf))) + if ( ! (m_pp_codehandle = NSEEL_code_compile(m_pv_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in 'per_pixel' code", m_szDesc); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; } } - - resetVars(NULL); } if (flags & RECOMPILE_WAVE_CODE) @@ -1566,10 +1565,9 @@ void CState::RecompileExpressions(int flags, int bReInit) StripLinefeedCharsAndComments(m_wave[i].m_szInit, buf); if (buf[0] && bReInit) { - resetVars(m_wave[i].m_pf_vars); { - int codehandle_temp; - if ( ! (codehandle_temp = compileCode(buf))) + NSEEL_CODEHANDLE codehandle_temp; + if ( ! (codehandle_temp = NSEEL_code_compile(m_wave[i].m_pf_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in wave %d init code", m_szDesc, i); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; @@ -1597,7 +1595,7 @@ void CState::RecompileExpressions(int flags, int bReInit) g_plugin->LoadCustomWavePerFrameEvallibVars(g_plugin->m_pState, i); - executeCode(codehandle_temp); + NSEEL_code_execute(codehandle_temp); m_wave[i].t_values_after_init_code[0] = *m_wave[i].var_pf_t1; m_wave[i].t_values_after_init_code[1] = *m_wave[i].var_pf_t2; @@ -1608,37 +1606,32 @@ void CState::RecompileExpressions(int flags, int bReInit) m_wave[i].t_values_after_init_code[6] = *m_wave[i].var_pf_t7; m_wave[i].t_values_after_init_code[7] = *m_wave[i].var_pf_t8; - freeCode(codehandle_temp); + NSEEL_code_free(codehandle_temp); codehandle_temp = NULL; } } - resetVars(NULL); } // 2. compile custom waveform per-frame code StripLinefeedCharsAndComments(m_wave[i].m_szPerFrame, buf); if (buf[0]) { - resetVars(m_wave[i].m_pf_vars); - if ( ! (m_wave[i].m_pf_codehandle = compileCode(buf))) + if ( ! (m_wave[i].m_pf_codehandle = NSEEL_code_compile(m_wave[i].m_pf_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in wave %d per-frame code", m_szDesc, i); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; } - resetVars(NULL); } // 3. compile custom waveform per-point code StripLinefeedCharsAndComments(m_wave[i].m_szPerPoint, buf); if (buf[0]) { - resetVars(m_wave[i].m_pp_vars); - if ( ! (m_wave[i].m_pp_codehandle = compileCode(buf))) + if ( ! (m_wave[i].m_pp_codehandle = NSEEL_code_compile(m_wave[i].m_pp_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in wave %d per-point code", m_szDesc, i); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; } - resetVars(NULL); } } } @@ -1651,11 +1644,10 @@ void CState::RecompileExpressions(int flags, int bReInit) StripLinefeedCharsAndComments(m_shape[i].m_szInit, buf); if (buf[0] && bReInit) { - resetVars(m_shape[i].m_pf_vars); #ifndef _NO_EXPR_ { - int codehandle_temp; - if ( ! (codehandle_temp = compileCode(buf))) + NSEEL_CODEHANDLE codehandle_temp; + if ( ! (codehandle_temp = NSEEL_code_compile(m_shape[i].m_pf_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in shape %d init code", m_szDesc, i); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; @@ -1683,7 +1675,7 @@ void CState::RecompileExpressions(int flags, int bReInit) g_plugin->LoadCustomShapePerFrameEvallibVars(g_plugin->m_pState, i); - executeCode(codehandle_temp); + NSEEL_code_execute(codehandle_temp); m_shape[i].t_values_after_init_code[0] = *m_shape[i].var_pf_t1; m_shape[i].t_values_after_init_code[1] = *m_shape[i].var_pf_t2; @@ -1694,27 +1686,24 @@ void CState::RecompileExpressions(int flags, int bReInit) m_shape[i].t_values_after_init_code[6] = *m_shape[i].var_pf_t7; m_shape[i].t_values_after_init_code[7] = *m_shape[i].var_pf_t8; - freeCode(codehandle_temp); + NSEEL_code_free(codehandle_temp); codehandle_temp = NULL; } } #endif - resetVars(NULL); } // 2. compile custom shape per-frame code StripLinefeedCharsAndComments(m_shape[i].m_szPerFrame, buf); if (buf[0]) { - resetVars(m_shape[i].m_pf_vars); #ifndef _NO_EXPR_ - if ( ! (m_shape[i].m_pf_codehandle = compileCode(buf))) + if ( ! (m_shape[i].m_pf_codehandle = NSEEL_code_compile(m_shape[i].m_pf_eel, buf))) { sprintf(g_plugin->m_szUserMessage, "warning: preset \"%s\": error in shape %d per-frame code", m_szDesc, i); g_plugin->m_fShowUserMessageUntilThisTime = g_plugin->GetTime() + 6.0f; } #endif - resetVars(NULL); } /* diff --git a/lib/vis_milkdrop/state.h b/lib/vis_milkdrop/state.h index 5f6b106..c52c458 100644 --- a/lib/vis_milkdrop/state.h +++ b/lib/vis_milkdrop/state.h @@ -35,7 +35,8 @@ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "evallib/eval.h" +//#include "evallib/eval.h" +#include "ns-eel2/ns-eel.h" #include "md_defines.h" // flags for CState::RecompileExpressions(): @@ -106,11 +107,11 @@ class CShape char m_szInit[8192]; // note: only executed once -> don't need to save codehandle char m_szPerFrame[8192]; //char m_szPerPoint[8192]; - int m_pf_codehandle; + NSEEL_CODEHANDLE m_pf_codehandle; //int m_pp_codehandle; // for per-frame expression evaluation: - varType m_pf_vars[EVAL_MAX_VARS]; + NSEEL_VMCTX m_pf_eel; double *var_pf_time, *var_pf_fps; double *var_pf_frame; double *var_pf_progress; @@ -163,11 +164,11 @@ class CWave char m_szInit[8192]; // note: only executed once -> don't need to save codehandle char m_szPerFrame[8192]; char m_szPerPoint[8192]; - int m_pf_codehandle; - int m_pp_codehandle; + NSEEL_CODEHANDLE m_pf_codehandle; + NSEEL_CODEHANDLE m_pp_codehandle; // for per-frame expression evaluation: - varType m_pf_vars[EVAL_MAX_VARS]; + NSEEL_VMCTX m_pf_eel; double *var_pf_time, *var_pf_fps; double *var_pf_frame; double *var_pf_progress; @@ -177,7 +178,7 @@ class CWave double *var_pf_r, *var_pf_g, *var_pf_b, *var_pf_a; // for per-point expression evaluation: - varType m_pp_vars[EVAL_MAX_VARS]; + NSEEL_VMCTX m_pp_eel; double *var_pp_time, *var_pp_fps; double *var_pp_frame; double *var_pp_progress; @@ -322,8 +323,8 @@ class CState //COscillator m_wavePosY; // 0 = centered // for arbitrary function evaluation: - int m_pf_codehandle; - int m_pp_codehandle; + NSEEL_CODEHANDLE m_pf_codehandle; + NSEEL_CODEHANDLE m_pp_codehandle; char m_szPerFrameInit[8192]; char m_szPerFrameExpr[8192]; //char m_szPerPixelInit[8192]; @@ -338,7 +339,7 @@ class CState float m_fBlendProgress; // 0..1; updated every frame based on StartTime and Duration. // for once-per-frame expression evaluation: - varType m_pf_vars[EVAL_MAX_VARS]; + NSEEL_VMCTX m_pf_eel; double *var_pf_zoom, *var_pf_zoomexp, *var_pf_rot, *var_pf_warp, *var_pf_cx, *var_pf_cy, *var_pf_dx, *var_pf_dy, *var_pf_sx, *var_pf_sy; double *var_pf_time, *var_pf_fps; double *var_pf_bass, *var_pf_mid, *var_pf_treb, *var_pf_bass_att, *var_pf_mid_att, *var_pf_treb_att; @@ -370,7 +371,7 @@ class CState // for per-vertex expression evaluation: - varType m_pv_vars[EVAL_MAX_VARS]; + NSEEL_VMCTX m_pv_eel; double *var_pv_zoom, *var_pv_zoomexp, *var_pv_rot, *var_pv_warp, *var_pv_cx, *var_pv_cy, *var_pv_dx, *var_pv_dy, *var_pv_sx, *var_pv_sy; double *var_pv_time, *var_pv_fps; double *var_pv_bass, *var_pv_mid, *var_pv_treb, *var_pv_bass_att, *var_pv_mid_att, *var_pv_treb_att; diff --git a/lib/vis_milkdrop/utility.cpp b/lib/vis_milkdrop/utility.cpp index ed47efa..984c3fc 100644 --- a/lib/vis_milkdrop/utility.cpp +++ b/lib/vis_milkdrop/utility.cpp @@ -80,228 +80,6 @@ float AdjustRateToFPS(float per_frame_decay_rate_at_fps1, float fps1, float actu return per_frame_decay_rate_at_fps2; } -#if 0 - -#define INITEMPBUFFERSIZE (1024*8) -static char INITempBuffer[INITEMPBUFFERSIZE]; -static char INIfsp[MAX_PATH]; -static char INIsection[256]; - -static void GetFromINIArray(char *mem, char *key, char *def, char *buffer, int buffersize) -{ - char *p; - char realkey[256]; - - strcpy(realkey, key); //make a copy incase key==buffer - memcpy(buffer, def, buffersize); - while(mem[0]!=0 || mem[1]!=0) - { - if (strnicmp(realkey, mem, strlen(realkey))==0) - { - p = strchr(mem, '='); - if (p) - { - p++; - while(*p==32) p++; - - memcpy(buffer, p, buffersize); - return; - } - } - mem+= strlen(mem)+1; - } -} - -static void InternalGetPrivateProfileSectionData(FILE* Fh, int fsize, char *ReturnBuffer,int size) -{ - char chr; - int strcount; - char *RB = ReturnBuffer; - - while((fsize>0)&&(size>4)) - { - fread(&chr,sizeof(char),1,Fh); - fsize--; - - if( (chr > ' ') && (chr <='z') ) - { - if(chr=='[') break; - - strcount = 0; - - ReturnBuffer[0] = chr; - ReturnBuffer++; - size--; - strcount++; - - while((fsize>0)&&(size>4)) - { - fread(&chr,sizeof(char),1,Fh); - fsize--; - - if((chr==0x0a)||(chr==0x0d)) - { - if(strcount) - { - while (ReturnBuffer[-1]==32) - { - ReturnBuffer--; - size++; - } - - ReturnBuffer[0] = 0; - ReturnBuffer++; - size--; - } - break; - } - else - { - if (chr==0x09) chr=32; - ReturnBuffer[0] = chr; - ReturnBuffer++; - size--; - strcount++; - } - } - } - } - - while (ReturnBuffer[-1]==32) - { - ReturnBuffer--; - size++; - } - - ReturnBuffer[0] = 0; - ReturnBuffer[1] = 0; -} - -int InternalGetPrivateProfileSection(char *Group,char *ReturnBuffer,int size,char *filename) -{ - FILE* Fh; - int fsize; - char chr; - int count; - int strcount; - char tmpbuf[256]; - - count = 0; - - Fh = fopen(filename,"rb"); - if(Fh==0) return(0); - - fseek(Fh, 0, SEEK_END); - fsize = ftell(Fh); - fseek(Fh,0, SEEK_SET); - - while((fsize>0)&&(size>4)) - { - fread(&chr,sizeof(char),1,Fh); - fsize--; - - if(chr=='[') - { - strcount = 0; - - while((fsize>0)&&(size>4)) - { - fread(&chr,sizeof(char),1,Fh); - fsize--; - - if(chr==']') - { - if(strcount) - { - tmpbuf[strcount] = 0; - - // string found, check against 'group' - - if(stricmp(Group,tmpbuf)==0) - { - // got it! - - InternalGetPrivateProfileSectionData(Fh,fsize,ReturnBuffer,size); - fclose(Fh); - return(0); - } - } - break; - } - else - { - tmpbuf[strcount] = chr; - strcount++; - } - } - } - } - - ReturnBuffer[0] = 0; - ReturnBuffer[1] = 0; - - fclose(Fh); - return(0); -} - -bool validIniFile = false; -char* iniFile = NULL; -char currIniFilename[MAX_PATH]; -char currIniSection[256]; -int iniFileSize = 0; - - -int InternalGetPrivateProfileString(char *szSectionName, char *szKeyName, char *szDefault, char *buffer, int size, char *szIniFile) -{ - bool newFile = false; - - if (stricmp(currIniFilename, szIniFile)) - { - // Load new ini file - newFile = true; - - FILE* handle; - - handle = fopen(szIniFile, "rb"); - if (handle == 0) - { - validIniFile = false; - GetFromSectionCache(szKeyName, szDefault, buffer, size); - return (strlen(buffer)); - } - - fseek(Fh, 0, SEEK_END); - iniFileSize = ftell(Fh); - fseek(Fh,0, SEEK_SET); - - iniFile = new char[iniFileSize]; - fread(iniFile, iniFileSize, 1, handle); - fclose(iniFile); - } - - if (newFile || stricmp(currIniSection, szSectionName)) - { - - } - - - -/* - - if (stricmp(INIfsp, szIniFile)!=0 || stricmp(INIsection, szSectionName)!=0) - { - InternalGetPrivateProfileSection(szSectionName, INITempBuffer, INITEMPBUFFERSIZE, szIniFile); - strcpy(INIfsp, szIniFile); - strcpy(INIsection, szSectionName); - } - - GetFromINIArray(INITempBuffer, szKeyName, szDefault, buffer, size); - return(strlen(buffer)); -*/ -} - -#endif - #define SECTION_CACHE_SIZE (1024 * 40) bool validIni = false; char currIniFilename[MAX_PATH]; @@ -649,79 +427,6 @@ void GuidToText(GUID *pGUID, char *str, int nStrLen) d[0], d[1], d[2], d[3], d[4], d[5], d[6], d[7], d[8], d[9], d[10]); } -/* -int GetPentiumTimeRaw(unsigned __int64 *cpu_timestamp) -{ - // returns 0 on failure, 1 on success - // warning: watch out for wraparound! - - // note: it's probably better to use QueryPerformanceFrequency - // and QueryPerformanceCounter()! - - // get high-precision time: - __try - { - unsigned __int64 *dest = (unsigned __int64 *)cpu_timestamp; - __asm - { - _emit 0xf // these two bytes form the 'rdtsc' asm instruction, - _emit 0x31 // available on Pentium I and later. - mov esi, dest - mov [esi ], eax // lower 32 bits of tsc - mov [esi+4], edx // upper 32 bits of tsc - } - return 1; - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - return 0; - } - - return 0; -} - -double GetPentiumTimeAsDouble(unsigned __int64 frequency) -{ - // returns < 0 on failure; otherwise, returns current cpu time, in seconds. - // warning: watch out for wraparound! - - // note: it's probably better to use QueryPerformanceFrequency - // and QueryPerformanceCounter()! - - if (frequency==0) - return -1.0; - - // get high-precision time: - __try - { - unsigned __int64 high_perf_time; - unsigned __int64 *dest = &high_perf_time; - __asm - { - _emit 0xf // these two bytes form the 'rdtsc' asm instruction, - _emit 0x31 // available on Pentium I and later. - mov esi, dest - mov [esi ], eax // lower 32 bits of tsc - mov [esi+4], edx // upper 32 bits of tsc - } - __int64 time_s = (__int64)(high_perf_time / frequency); // unsigned->sign conversion should be safe here - __int64 time_fract = (__int64)(high_perf_time % frequency); // unsigned->sign conversion should be safe here - // note: here, we wrap the timer more frequently (once per week) - // than it otherwise would (VERY RARELY - once every 585 years on - // a 1 GHz), to alleviate floating-point precision errors that start - // to occur when you get to very high counter values. - double ret = (time_s % (60*60*24*7)) + (double)time_fract/(double)((__int64)frequency); - return ret; - } - __except(EXCEPTION_EXECUTE_HANDLER) - { - return -1.0; - } - - return -1.0; -} -*/ - #ifdef _DEBUG void OutputDebugMessage(char *szStartText, HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam) { @@ -1077,6 +782,7 @@ void MissingDirectX(HWND hwnd) */ } +#if 0 bool CheckForMMX() { DWORD bMMX = 0; @@ -1275,6 +981,7 @@ void memcpy_MMX(void *pDest, void *pSrc, int nBytes) } } } +#endif // 0 void GetDesktopFolder(char *szDesktopFolder) // should be MAX_PATH len. { From e19eb34d0a8b77e28fce08098fe794336e5b3536 Mon Sep 17 00:00:00 2001 From: Anton Fedchin Date: Mon, 25 Dec 2017 16:55:13 +0300 Subject: [PATCH 2/3] drop old evallib --- lib/vis_milkdrop/evallib/CAL_TAB.C | 601 ---------------- lib/vis_milkdrop/evallib/CMakeLists.txt | 21 - lib/vis_milkdrop/evallib/Compiler.c | 424 ------------ lib/vis_milkdrop/evallib/Compiler.h | 74 -- lib/vis_milkdrop/evallib/Gettok.c | 6 - lib/vis_milkdrop/evallib/LEX.H | 53 -- lib/vis_milkdrop/evallib/LLSAVE.C | 6 - lib/vis_milkdrop/evallib/Lexget.c | 20 - lib/vis_milkdrop/evallib/Lexswi.c | 23 - lib/vis_milkdrop/evallib/Lextab.c | 260 ------- lib/vis_milkdrop/evallib/Lmovb.c | 29 - lib/vis_milkdrop/evallib/Scan.l | 54 -- lib/vis_milkdrop/evallib/Yylex.c | 172 ----- lib/vis_milkdrop/evallib/cal.y | 155 ----- lib/vis_milkdrop/evallib/cal_tab.h | 42 -- lib/vis_milkdrop/evallib/cfunc.c | 879 ------------------------ lib/vis_milkdrop/evallib/eval.c | 239 ------- lib/vis_milkdrop/evallib/eval.h | 82 --- lib/vis_milkdrop/evallib/makel.bat | 1 - lib/vis_milkdrop/evallib/makey.bat | 2 - lib/vis_milkdrop/evallib/readme.txt | 112 --- 21 files changed, 3255 deletions(-) delete mode 100644 lib/vis_milkdrop/evallib/CAL_TAB.C delete mode 100644 lib/vis_milkdrop/evallib/CMakeLists.txt delete mode 100644 lib/vis_milkdrop/evallib/Compiler.c delete mode 100644 lib/vis_milkdrop/evallib/Compiler.h delete mode 100644 lib/vis_milkdrop/evallib/Gettok.c delete mode 100644 lib/vis_milkdrop/evallib/LEX.H delete mode 100644 lib/vis_milkdrop/evallib/LLSAVE.C delete mode 100644 lib/vis_milkdrop/evallib/Lexget.c delete mode 100644 lib/vis_milkdrop/evallib/Lexswi.c delete mode 100644 lib/vis_milkdrop/evallib/Lextab.c delete mode 100644 lib/vis_milkdrop/evallib/Lmovb.c delete mode 100644 lib/vis_milkdrop/evallib/Scan.l delete mode 100644 lib/vis_milkdrop/evallib/Yylex.c delete mode 100644 lib/vis_milkdrop/evallib/cal.y delete mode 100644 lib/vis_milkdrop/evallib/cal_tab.h delete mode 100644 lib/vis_milkdrop/evallib/cfunc.c delete mode 100644 lib/vis_milkdrop/evallib/eval.c delete mode 100644 lib/vis_milkdrop/evallib/eval.h delete mode 100644 lib/vis_milkdrop/evallib/makel.bat delete mode 100644 lib/vis_milkdrop/evallib/makey.bat delete mode 100644 lib/vis_milkdrop/evallib/readme.txt diff --git a/lib/vis_milkdrop/evallib/CAL_TAB.C b/lib/vis_milkdrop/evallib/CAL_TAB.C deleted file mode 100644 index 2b904a0..0000000 --- a/lib/vis_milkdrop/evallib/CAL_TAB.C +++ /dev/null @@ -1,601 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include -//#include -#include -#include "Compiler.h" -#include "eval.h" - -#define VALUE 258 -#define IDENTIFIER 259 -#define FUNCTION1 260 -#define FUNCTION2 261 -#define FUNCTION3 262 -#define UMINUS 263 -#define UPLUS 264 -#define YYSTYPE int - -int yyerror(char *); -int yylex(char **exp); - -extern int result; - -typedef struct -{ - int timestamp; - int first_line; - int first_column; - int last_line; - int last_column; - char *text; -} yyltype; - -#define YYLTYPE yyltype - -#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 YYPURE 1 - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY -2 -#define YYEOF 0 -#define YYACCEPT return(0) -#define YYABORT return(1) - -#define YYTERROR 1 -#define YYERRCODE 256 - -#ifndef YYIMPURE -#define YYLEX yylex(&exp) -#endif - -#ifndef YYPURE -#define YYLEX yylex(&yylval)//, &yylloc) MY MODIF! -#endif - -/* If nonreentrant, generate the variables here */ - -#ifndef YYIMPURE - -int yychar; /* the lookahead symbol */ -YYSTYPE yylval; /* the semantic value of the */ - /* lookahead symbol */ - - -int yynerrs; /* number of parse errors so far */ -#endif /* YYIMPURE */ - -/* 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 yyparse(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; - -#ifndef YYPURE - int yychar; - YYSTYPE yylval; - int yynerrs; -#endif - - YYSTYPE yyval; /* the variable used to return */ - /* semantic values from the action */ - /* routines */ - - int yylen; - - yylval = 0; - yystate = 0; - yyerrstatus = 0; - yynerrs = 0; - 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 (yychar == YYEMPTY) - { -// yyStackSize = yyssp - (yyss - 1); - yychar = YYLEX; - } - - /* Convert token to internal form (in yychar1) for indexing tables with */ - - if (yychar <= 0) /* This means end of input. */ - { - yychar1 = 0; - yychar = YYEOF; /* Don't call YYLEX any more */ - - } - else - { - yychar1 = YYTRANSLATE(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 (yychar != YYEOF) - yychar = YYEMPTY; - - *++yyvsp = 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]; result = yyvsp[0]; ; - break;} -case 2: -//#ln 34 "cal.y" -{ { - int i = (int)setVar((int)yyvsp[-2], 0); - int v = createCompiledValue(0, &(varTable[i].value)); - yyval = createCompiledFunction2(MATH_SIMPLE, FN_ASSIGN, v, (int)yyvsp[0]); - result = yyval; - } - ; - break;} -case 3: -//#ln 50 "cal.y" -{ yyval = yyvsp[0] ; - break;} -case 4: -//#ln 55 "cal.y" -{ yyval = getVar((int)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 = createCompiledFunction2(MATH_SIMPLE, FN_MULTIPLY, yyvsp[-2], yyvsp[0]); - break;} -case 9: -//#ln 72 "cal.y" -{ yyval = createCompiledFunction2(MATH_SIMPLE, FN_DIVIDE, yyvsp[-2], yyvsp[0]); - break;} -case 10: -//#ln 78 "cal.y" -{ yyval = createCompiledFunction2(MATH_SIMPLE, FN_MODULO, yyvsp[-2], yyvsp[0]); - break;} -case 11: -//#ln 84 "cal.y" -{ yyval = createCompiledFunction2(MATH_SIMPLE, FN_ADD, yyvsp[-2], yyvsp[0]); - break;} -case 12: -//#ln 90 "cal.y" -{ yyval = createCompiledFunction2(MATH_SIMPLE, FN_SUB, yyvsp[-2], yyvsp[0]); - break;} -case 13: -//#ln 96 "cal.y" -{ yyval = createCompiledFunction2(MATH_SIMPLE, FN_AND, yyvsp[-2], yyvsp[0]); - break;} -case 14: -//#ln 102 "cal.y" -{ yyval = createCompiledFunction2(MATH_SIMPLE, FN_OR, yyvsp[-2], yyvsp[0]); - break;} -case 15: -//#ln 108 "cal.y" -{ yyval = createCompiledFunction1(MATH_SIMPLE, FN_UMINUS, yyvsp[0]); - break;} -case 16: -//#ln 114 "cal.y" -{ yyval = createCompiledFunction1(MATH_SIMPLE, FN_UPLUS, yyvsp[0]); - break;} -case 17: -//#ln 120 "cal.y" -{ yyval = yyvsp[0]; - break;} -case 18: -//#ln 125 "cal.y" -{ yyval = createCompiledFunction1(MATH_FN, (int)yyvsp[-3], yyvsp[-1]); - break;} -case 19: -//#ln 131 "cal.y" -{ yyval = createCompiledFunction2(MATH_FN, (int)yyvsp[-5], yyvsp[-3], yyvsp[-1]); - break;} -case 20: -//#ln 137 "cal.y" -{ yyval = createCompiledFunction3(MATH_FN, (int)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. */ - { - ++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 (yychar == YYEOF) YYABORT; - - 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 = yylval; - - yystate = yyn; - goto yynewstate; -} diff --git a/lib/vis_milkdrop/evallib/CMakeLists.txt b/lib/vis_milkdrop/evallib/CMakeLists.txt deleted file mode 100644 index 69c4252..0000000 --- a/lib/vis_milkdrop/evallib/CMakeLists.txt +++ /dev/null @@ -1,21 +0,0 @@ -project(evallib) - -enable_language(C) - -cmake_minimum_required(VERSION 2.6) - -set(SOURCES CAL_TAB.C - cfunc.c - Compiler.c - eval.c - Gettok.c - Lextab.c - LLSAVE.C - Yylex.c) - -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") - # disable optimization for cfunc.c and Compiler.c - set_source_files_properties(cfunc.c Compiler.c COMPILE_FLAGS -Od) -endif() - -add_library(evallib STATIC ${SOURCES}) diff --git a/lib/vis_milkdrop/evallib/Compiler.c b/lib/vis_milkdrop/evallib/Compiler.c deleted file mode 100644 index f1c0562..0000000 --- a/lib/vis_milkdrop/evallib/Compiler.c +++ /dev/null @@ -1,424 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ -#include -//#include -#include -#include -#include "Compiler.h" -#include "eval.h" - -#define LLB_DSIZE (65536-64) -typedef struct _llBlock { - struct _llBlock *next; - int sizeused; - char block[LLB_DSIZE]; -} llBlock; - -typedef struct _startPtr { - struct _startPtr *next; - void *startptr; -} startPtr; - -typedef struct { - llBlock *blocks; - startPtr *startpts; - } codeHandleType; - -static llBlock *blocks_head = NULL; - -double computTable[16384]; -double *nextBlock=computTable; - -extern CRITICAL_SECTION g_eval_cs; - -static void *newBlock(int size); -static void freeBlocks(llBlock *start); - - -void _asm_sin(void); -void _asm_cos(void); -void _asm_tan(void); -void _asm_int(void); -void _asm_asin(void); -void _asm_acos(void); -void _asm_atan(void); -void _asm_atan2(void); -void _asm_sqr(void); -void _asm_sqrt(void); -void _asm_pow(void); -void _asm_exp(void); -void _asm_log(void); -void _asm_log10(void); -void _asm_abs(void); -void _asm_min(void); -void _asm_max(void); -void _asm_sig(void); -void _asm_sign(void); -void _asm_rand(void); -void _asm_band(void); -void _asm_bor(void); -void _asm_bnot(void); -void _asm_if(void); -void _asm_equal(void); -void _asm_below(void); -void _asm_above(void); -void _asm_assign(void); -void _asm_add(void); -void _asm_sub(void); -void _asm_mul(void); -void _asm_div(void); -void _asm_mod(void); -void _asm_or(void); -void _asm_and(void); -void _asm_uplus(void); -void _asm_uminus(void); -void _asm_function3(void); -void _asm_function3_end(void); -void _asm_function2(void); -void _asm_function2_end(void); -void _asm_function1(void); -void _asm_function1_end(void); -void _asm_simpleValue(void); -void _asm_simpleValue_end(void); - -functionType fnTable[27] = {{ "sin", _asm_sin, 1 }, - { "cos", _asm_cos, 1 }, - { "tan", _asm_tan, 1 }, - { "int", _asm_int, 1 }, - { "asin", _asm_asin, 1 }, - { "acos", _asm_acos, 1 }, - { "atan", _asm_atan, 1 }, - { "atan2", _asm_atan2, 2 }, - { "sqr", _asm_sqr, 1 }, - { "sqrt", _asm_sqrt, 1 }, - { "pow", _asm_pow, 2 }, - { "exp", _asm_exp, 1 }, - { "log", _asm_log, 1 }, - { "log10", _asm_log10, 1 }, - { "abs", _asm_abs, 1 }, - { "min", _asm_min, 2 }, - { "max", _asm_max, 2 }, - { "sigmoid",_asm_sig, 2 } , - { "sign", _asm_sign, 1 } , - { "rand", _asm_rand, 1 } , - { "band", _asm_band, 2 } , - { "bor", _asm_bor, 2 } , - { "bnot", _asm_bnot, 1 } , - { "if", _asm_if, 3 }, - { "equal", _asm_equal, 2 }, - { "below", _asm_below, 2 }, - { "above", _asm_above, 2 }, - }; - - -//--------------------------------------------------------------------------------------------------------------- -void *realAddress(void *fn) -{ -#if defined(_DEBUG) - unsigned char *ptr = (char *)fn; - if(*ptr == 0xE9) - ptr += (*(int *)((ptr+1))+5); - return ptr; -#else - // Release Mode - return fn; -#endif -} - -//#define realAddress(a) a - -//--------------------------------------------------------------------------------------------------------------- -static void freeBlocks(llBlock *start) -{ - while (start) - { - llBlock *llB = start->next; - VirtualFree(start, 0, MEM_RELEASE); - start=llB; - } -} - -//--------------------------------------------------------------------------------------------------------------- -static void *newBlock(int size) -{ - llBlock *llb; - int alloc_size; - if (blocks_head && (LLB_DSIZE - blocks_head->sizeused) >= size) - { - void *t=blocks_head->block+blocks_head->sizeused; - blocks_head->sizeused+=size; - return t; - } - alloc_size=sizeof(llBlock); - if ((int)size > LLB_DSIZE) alloc_size += size - LLB_DSIZE; - llb = (llBlock *)VirtualAlloc(NULL, alloc_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE); // grab bigger block if absolutely necessary (heh) - llb->sizeused=size; - llb->next = blocks_head; - blocks_head = llb; - return llb->block; -} - -//--------------------------------------------------------------------------------------------------------------- -static int *findFBlock(char *p) -{ - while (*(int *)p != 0xFFFFFFFF) p++; - return (int*)p; -} - - -//--------------------------------------------------------------------------------------------------------------- -int createCompiledValue(double value, double *addrValue) -{ - int size; - char *block; - double *dupValue; - int i =0; - char *p; - char txt[512]; - - //size=(int)_asm_simpleValue_end-(int)_asm_simpleValue; - size = 0x10; - block=(char *)newBlock(size); - - if (addrValue == NULL) - *(dupValue = (double *)newBlock(sizeof(double))) = value; - else - dupValue = addrValue; - - memcpy(block, realAddress(_asm_simpleValue), size); - - p = block; - while (*(int *)p != 0xFFFFFFFF) - { - txt[i++] = *p; - p++; - }; - txt[i] = 0; - - *findFBlock(block)=(int)dupValue; - - return ((int)(block)); - -} - -//--------------------------------------------------------------------------------------------------------------- -int getFunctionAddress(int fntype, int fn) -{ - switch (fntype) - { - case MATH_SIMPLE: - switch (fn) - { - case FN_ASSIGN: - return (int)realAddress(_asm_assign); - case FN_ADD: - return (int)realAddress(_asm_add); - case FN_SUB: - return (int)realAddress(_asm_sub); - case FN_MULTIPLY: - return (int)realAddress(_asm_mul); - case FN_DIVIDE: - return (int)realAddress(_asm_div); - case FN_MODULO: - return (int)realAddress(_asm_mod); - case FN_AND: - return (int)realAddress(_asm_and); - case FN_OR: - return (int)realAddress(_asm_or); - case FN_UPLUS: - return (int)realAddress(_asm_uplus); - case FN_UMINUS: - return (int)realAddress(_asm_uminus); - } - case MATH_FN: - return (int)realAddress(fnTable[fn].afunc); - } - return 0; -} - - -//--------------------------------------------------------------------------------------------------------------- -int createCompiledFunction3(int fntype, int fn, int code1, int code2, int code3) -{ - int *p; - int size; - char *block; - -// size=(int)_asm_function3_end-(int)_asm_function3; - size = 0x30; - block=(char *)newBlock(size); - - memcpy(block, realAddress(_asm_function3), size); - - p=findFBlock(block); *p++=code1; - p=findFBlock((char*)p); *p++=code2; - p=findFBlock((char*)p); *p++=code3; - p=findFBlock((char*)p); *p++=getFunctionAddress(fntype, fn); - - return ((int)(block)); -} - -//--------------------------------------------------------------------------------------------------------------- -int createCompiledFunction2(int fntype, int fn, int code1, int code2) -{ - int *p; - int size; - char *block; - -// size=(int)_asm_function2_end-(int)_asm_function2; - size = 0x20; - block=(char *)newBlock(size); - - memcpy(block, realAddress(_asm_function2), size); - - p=findFBlock(block); *p++=code1; - p=findFBlock((char*)p); *p++=code2; - p=findFBlock((char*)p); *p++=getFunctionAddress(fntype, fn); - - return ((int)(block)); -} - - -//--------------------------------------------------------------------------------------------------------------- -int createCompiledFunction1(int fntype, int fn, int code) -{ - int size; - int *p; - char *block; - -// size=(int)_asm_function1_end-(int)_asm_function1; - size = 0x20; - block=(char *)newBlock(size); - - memcpy(block, realAddress(_asm_function1), size); - - p=findFBlock(block); *p++=code; - p=findFBlock((char*)p); *p++=getFunctionAddress(fntype, fn); - - return ((int)(block)); -} - -//------------------------------------------------------------------------------ -int compileCode(char *expression) -{ - char expr[4096]; - codeHandleType *handle; - startPtr *scode=NULL; - blocks_head=0; - - if (!expression || !*expression) return 0; - if (!varTable) return 0; - - handle = (codeHandleType*)newBlock(sizeof(codeHandleType)); - - if (!handle) return 0; - - memset(handle,0,sizeof(codeHandleType)); - - while (*expression) - { - startPtr *tmp; - char *expr_ptr; - int l=4095; - colCount=0; - - // single out segment - while (*expression == ';' || *expression == ' ' || *expression == '\n' || - *expression == '\r' || *expression == '\t') expression++; - if (!*expression) break; - expr_ptr = expr; - while (l-->0) - { - int a=*expression; - if (a) expression++; - if (!a || a == ';') break; - if (a == '\n' || a=='\r' || a=='\t') a=' '; - *expr_ptr++ = a; - } - *expr_ptr = 0; - - // parse - tmp=(startPtr*) newBlock(sizeof(startPtr)); - if (!tmp) break; - tmp->startptr=compileExpression(expr); - if (!tmp->startptr) { scode=NULL; break; } - tmp->next=NULL; - if (!scode) scode=handle->startpts=tmp; - else - { - scode->next=tmp; - scode=tmp; - } - } - - // check to see if failed on the first startingCode - if (!scode) - { - freeBlocks(blocks_head); // free blocks - handle=NULL; // return NULL (after resetting blocks_head) - } - else handle->blocks = blocks_head; - - blocks_head=0; - - return (int)handle; -} - -//------------------------------------------------------------------------------ -void executeCode(int handle) -{ - codeHandleType *h = (codeHandleType *)handle; - startPtr *p; - if (!h) return; -// EnterCriticalSection(&g_eval_cs); - p=h->startpts; - while (p) - { - void *startPoint=p->startptr; - if (!startPoint) break; - p=p->next; - nextBlock=computTable; - __asm pusha // Lets cover our ass - __asm call startPoint - __asm popa - } -// LeaveCriticalSection(&g_eval_cs); -} - -//------------------------------------------------------------------------------ -void freeCode(int handle) -{ - codeHandleType *h = (codeHandleType *)handle; - if (h != NULL) - { - freeBlocks(h->blocks); - } -} - diff --git a/lib/vis_milkdrop/evallib/Compiler.h b/lib/vis_milkdrop/evallib/Compiler.h deleted file mode 100644 index 8781876..0000000 --- a/lib/vis_milkdrop/evallib/Compiler.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -. -*/ -#ifndef __COMPILER_H -#define __COMPILER_H - -#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 - -#ifdef __cplusplus -extern "C" { -#endif - - -int compileCode(char *exp); -void executeCode(int handle); -void freeCode(int handle); - - - -typedef struct { - char *name; - void *afunc; - int nParams; - } functionType; -extern functionType fnTable[27]; - -int createCompiledValue(double value, double *addrValue); -int createCompiledFunction1(int fntype, int fn, int code); -int createCompiledFunction2(int fntype, int fn, int code1, int code2); -int createCompiledFunction3(int fntype, int fn, int code1, int code2, int code3); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/vis_milkdrop/evallib/Gettok.c b/lib/vis_milkdrop/evallib/Gettok.c deleted file mode 100644 index 02dd6b0..0000000 --- a/lib/vis_milkdrop/evallib/Gettok.c +++ /dev/null @@ -1,6 +0,0 @@ -/* - * Bob Denny 28-Aug-82 Remove reference to stdio.h - * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C - */ - -#include "lex.h" diff --git a/lib/vis_milkdrop/evallib/LEX.H b/lib/vis_milkdrop/evallib/LEX.H deleted file mode 100644 index 2a6af32..0000000 --- a/lib/vis_milkdrop/evallib/LEX.H +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Bob Denny 28-Aug-82 Remove reference to FILE *lexin to - * eliminate dependency on standard I/O library. Only - * lexgetc() used it, and it's there now. - * Add EOF definition for standalone uses. - * Corrected comment for llnxtmax. - * - * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C. Removed - * equivalence of yylval and lexval since - * a multi-typed parser wants yylval to be - * typed to be the union of the types (YYSTYPE). - */ - -/* - * lex library header file -- accessed through - * #include - */ - -#include - -/* - * Description of scanning tables. The entries at the front of - * the struct must remain in place for the assembler routines to find. - */ -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 */ -}; - -#define NBPW 16 -#define LEXERR 256 -#define LEXSKIP (-1) -#define EOF (-1) -//#define NULL (0) -#define LEXECHO(fp) {lexecho((fp));} - -#define lextext llbuf -#define lexlast llend - -extern FILE *lexin; -extern llstin(); - diff --git a/lib/vis_milkdrop/evallib/LLSAVE.C b/lib/vis_milkdrop/evallib/LLSAVE.C deleted file mode 100644 index 23c5e47..0000000 --- a/lib/vis_milkdrop/evallib/LLSAVE.C +++ /dev/null @@ -1,6 +0,0 @@ -/* - * This is linked from lexlib to resolve a global in yylex which - * will be undefined if the user grammar has not defined any rules - * with right-context (look-ahead) - */ -char *llsave[1]; /* Look ahead buffer */ diff --git a/lib/vis_milkdrop/evallib/Lexget.c b/lib/vis_milkdrop/evallib/Lexget.c deleted file mode 100644 index b4c76f9..0000000 --- a/lib/vis_milkdrop/evallib/Lexget.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * lexget.c - * - * Bob Denny 28-Aug-82 Move stdio dependencies to lexerr(), lexget(), - * lexech() and mapch(). This is one of 4 modules - * in lexlib which depend upon the standard I/O package. - * - * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C. - */ - -#include -#include "lex.h" -extern char expression[4096]; -extern int pos; -lexgetc() -{ -char c = expression[pos]; -if (c) pos++; - return( c != 0 ? c : -1); -} diff --git a/lib/vis_milkdrop/evallib/Lexswi.c b/lib/vis_milkdrop/evallib/Lexswi.c deleted file mode 100644 index 4999200..0000000 --- a/lib/vis_milkdrop/evallib/Lexswi.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * lexswitch -- switch lex tables - */ - -/* - * Bob Denny 28-Aug-82 Remove reference to stdio.h - * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C - */ - -#include "lex.h" - -extern struct lextab *_tabp; - -struct lextab * -lexswitch(lp) -struct lextab *lp; -{ - register struct lextab *olp; - - olp = _tabp; - _tabp = lp; - return(olp); -} diff --git a/lib/vis_milkdrop/evallib/Lextab.c b/lib/vis_milkdrop/evallib/Lextab.c deleted file mode 100644 index a8a1f12..0000000 --- a/lib/vis_milkdrop/evallib/Lextab.c +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Created by IBM PC LEX from file "scan.l" - * - for use with standard I/O - */ - -#include -#include "lex.h" -#define LL16BIT int - -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); -} - -int lexval; -char lbuf[]; - -#define YYSTYPE int -#include "cal_tab.h" -int c; - -extern YYSTYPE yylval; -int translate(int type); -void count(void); -void setLastVar(void); -int lookup(int *typeOfObject); - - -#define INTCONST 1 -#define DBLCONST 2 -#define HEXCONST 3 -#define VARIABLE 4 -#define OTHER 5 - -int _Alextab(__na__) -{ - if (__na__ >= 0 && __na__ <= 19) count(); - switch (__na__) - { - case 0: yylval = translate(HEXCONST); return VALUE; - case 1: yylval = translate(INTCONST); return VALUE; - case 2: yylval = translate(INTCONST); return VALUE; - case 3: yylval = translate(DBLCONST); return VALUE; - case 4: - case 5: setLastVar(); yylval = lookup(&__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); -} - - -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, - }; - - -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, - }; - -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, - }; - -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, - }; - -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 lextab = { - 36, - _Dlextab, - _Nlextab, - _Clextab, - _Blextab, - 524, - _lmovb, - _Flextab, - _Alextab, - - NULL, - 0, - 0, - 0, - }; - - diff --git a/lib/vis_milkdrop/evallib/Lmovb.c b/lib/vis_milkdrop/evallib/Lmovb.c deleted file mode 100644 index 8be9ec7..0000000 --- a/lib/vis_milkdrop/evallib/Lmovb.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Bob Denny 28-Aug-82 Remove reference to stdio.h - * Scott Guthery 20-Nov-83 Adapt for IBM PC & DeSmet C - */ - -#include "lex.h" - -_lmovb(lp, c, st) -register int c, st; -register struct lextab *lp; -{ - int base; - - while ((base = lp->llbase[st]+c) > lp->llnxtmax || - (lp->llcheck[base] & 0377) != st) { - - if (st != lp->llendst) { -/* - * This miscompiled on Decus C many years ago: - * st = lp->lldefault[st] & 0377; - */ - base = lp->lldefault[st] & 0377; - st = base; - } - else - return(-1); - } - return(lp->llnext[base]&0377); -} diff --git a/lib/vis_milkdrop/evallib/Scan.l b/lib/vis_milkdrop/evallib/Scan.l deleted file mode 100644 index 2513433..0000000 --- a/lib/vis_milkdrop/evallib/Scan.l +++ /dev/null @@ -1,54 +0,0 @@ -%{ -#define YYSTYPE double -#include "cal_tab.h" -int c; - -extern YYSTYPE yylval; -double translate(int type); -void count(void); -void setLastVar(void); -int lookup(int *typeOfObject); -struct lextab *lexswitch(struct lextab *lp); - - -#define INTCONST 1 -#define DBLCONST 2 -#define HEXCONST 3 -#define VARIABLE 4 -#define OTHER 5 - -%} - -digit = [0-9]; -letter = [a-zA-Z_]; -hex = [a-fA-F0-9]; -/* -- */ -space = [\40]; -/*number = (digit* | "-" digit*);*/ -number = digit*; -exp = [Ee] number; -doubl = number "." (digit* | digit* exp); - -%% -hex hex* [hH] { count(); yylval = translate(HEXCONST); return VALUE; } -digit* { count(); yylval = translate(INTCONST); return VALUE; } -digit digit* [Dd] { count(); yylval = translate(INTCONST); return VALUE; } -doubl { count(); yylval = translate(DBLCONST); return VALUE; } -letter* { count(); { int typeOfObject; setLastVar(); yylval = lookup(&typeOfObject); return typeOfObject; }} -letter (letter|digit)* { count(); { int typeOfObject; setLastVar(); yylval = lookup(&typeOfObject); return typeOfObject; }} -'+' { count(); return '+'; } -'-' { count(); return '-'; } -'*' { count(); return '*'; } -'/' { count(); return '/'; } -'%' { count(); return '%'; } -'&' { count(); return '&'; } -'|' { count(); return '|'; } -'(' { count(); return '('; } -')' { count(); return ')'; } -'=' { count(); return '='; } -',' { count(); return ','; } -';' { count(); return ';'; } -[ \t\v\f] { count(); } -. { count(); } - -%% diff --git a/lib/vis_milkdrop/evallib/Yylex.c b/lib/vis_milkdrop/evallib/Yylex.c deleted file mode 100644 index 37d685d..0000000 --- a/lib/vis_milkdrop/evallib/Yylex.c +++ /dev/null @@ -1,172 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ -#include "lex.h" - -#define ERROR 256 /* yacc's value */ - -static int llset(void); -static int llinp(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)) ); -} - -static char *llsave[16]; /* Look ahead buffer */ -static char llbuf[100]; /* work buffer */ -static char *llp1 = &llbuf[0]; /* pointer to next avail. in token */ -static char *llp2 = &llbuf[0]; /* pointer to end of lookahead */ -static char *llend = &llbuf[0]; /* pointer to end of token */ -static char *llebuf = &llbuf[sizeof llbuf]; -static int lleof; -static int yyline = 0; -extern struct lextab lextab; - -int gettoken(char *lltb, int lltbsiz) -{ - register char *lp, *tp, *ep; - - tp = lltb; - ep = tp+lltbsiz-1; - for (lp = llbuf; lp < llend && tp < ep;) - *tp++ = *lp++; - *tp = 0; - return(tp-lltb); -} - - -int yylex(char **exp) -{ - register int c, st; - int final, l, llk, i; - register struct lextab *lp; - char *cp; - - while (1) - { - llk = 0; - if (llset()) return(0); - st = 0; - final = -1; - lp = &lextab; - - do { - if (lp->lllook && (l = lp->lllook[st])) { - for (c=0; cllfinal[st]) != -1) { - final = i; - llend = llp1; - } - if ((c = llinp(exp)) < 0) - break; - if ((cp = lp->llbrk) && llk==0 && tst__b(c, cp)) { - llp1--; - break; - } - } while ((st = (*lp->llmove)(lp, c, st)) != -1); - - - if (llp2 < llp1) - llp2 = llp1; - if (final == -1) { - llend = llp1; - if (st == 0 && c < 0) - return(0); - if ((cp = lp->llill) && tst__b(c, cp)) { - continue; - } - return(ERROR); - } - if (c = (final >> 11) & 037) - llend = llsave[c-1]; - if ((c = (*lp->llactr)(final&03777)) >= 0) - return(c); - } -} - -void llinit(viud) -{ - llp1 = llp2 = llend = llbuf; - llebuf = llbuf + sizeof(llbuf); - lleof = yyline = 0; -} - - -static int llinp(char **exp) -{ - register c; - register struct lextab *lp; - register char *cp; - - lp = &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 = (llp1 < llp2) ? *llp1 & 0377 : (lleof) ? EOF : lexgetc(exp); - if (c >= 0) { /* Got a character? */ - if (cp && tst__b(c, cp)) - continue; /* Ignore it */ - if (llp1 >= llebuf) { /* No, is there room? */ - return -1; - } - *llp1++ = c; /* Store in token buff */ - } else - lleof = 1; /* Set EOF signal */ - return(c); - } -} - -static int llset(void) -/* - * Return TRUE if EOF and nothing was moved in the look-ahead buffer - */ -{ - register char *lp1, *lp2; - - for (lp1 = llbuf, lp2 = llend; lp2 < llp2;) - *lp1++ = *lp2++; - llend = llp1 = llbuf; - llp2 = lp1; - return(lleof && lp1 == llbuf); -} diff --git a/lib/vis_milkdrop/evallib/cal.y b/lib/vis_milkdrop/evallib/cal.y deleted file mode 100644 index 3844ac0..0000000 --- a/lib/vis_milkdrop/evallib/cal.y +++ /dev/null @@ -1,155 +0,0 @@ - - %{ - #define YYSTYPE double - #include - #include - #include "Compiler.h" - #include "eval.h" - - yyerror(char *); - yylex(); - - extern int yyStackSize; - extern double result; - - int regs[26]; - int base; - - %} - - %token VALUE IDENTIFIER FUNCTION1 FUNCTION2 FUNCTION3 - - %left '|' - %left '&' - %left '+' '-' - %left '*' '/' '%' - %left UMINUS /*supplies precedence for unary minus */ - %left UPLUS /*supplies precedence for unary plus */ - - %% /*beginning of rules section */ - - stat : math_expr - { $$ = $1; result = $1; } - | IDENTIFIER '=' math_expr - { if (parseType == PARSE_EVAL) - { - setVar((int)$1, $3); - $$ = $3; - result = $3; - } - else - { - double i = setVar((int)$1, 0); - double v = createCompiledValue(0, &(varTable[(int)i].value)); - $$ = createCompiledFunction2(MATH_SIMPLE, FN_ASSIGN, v, $3); - result = $$; - } - } - ; - - value : VALUE { $$ = $1 } - - - primary_expr - : IDENTIFIER - { $$ = getVar((int)$1);} - | value - { $$ = $1;} - | '(' math_expr ')' - { $$ = $2;} - ; - - math_expr - : primary_expr - { $$ = $1; } - | math_expr '*' math_expr - { if (parseType == PARSE_EVAL) - $$ = $1 * $3; - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_MULTIPLY, $1, $3); - } - | math_expr '/' math_expr - { if (parseType == PARSE_EVAL) - $$ = $1 / $3; - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_DIVIDE, $1, $3); - } - | math_expr '%' math_expr - { if (parseType == PARSE_EVAL) - $$ = (double)((int)$1 % (int)$3); - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_MODULO, $1, $3); - } - | math_expr '+' math_expr - { if (parseType == PARSE_EVAL) - $$ = $1 + $3; - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_ADD, $1, $3); - } - | math_expr '-' math_expr - { if (parseType == PARSE_EVAL) - $$ = $1 - $3; - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_SUB, $1, $3); - } - | math_expr '&' math_expr - { if (parseType == PARSE_EVAL) - $$ = (double)((int)$1 & (int)$3); - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_AND, $1, $3); - } - | math_expr '|' math_expr - { if (parseType == PARSE_EVAL) - $$ = (double)((int)$1 | (int)$3); - else - $$ = createCompiledFunction2(MATH_SIMPLE, FN_OR, $1, $3); - } - | '-' math_expr %prec UMINUS - { if (parseType == PARSE_EVAL) - $$ = -$2; - else - $$ = createCompiledFunction1(MATH_SIMPLE, FN_UMINUS, $2); - } - | '+' math_expr %prec UPLUS - { if (parseType == PARSE_EVAL) - $$ = +$2; - else - $$ = createCompiledFunction1(MATH_SIMPLE, FN_UPLUS, $2); - } - | fonction - { $$ = $1; } - ; - - fonction - : FUNCTION1 '(' math_expr ')' - { if (parseType == PARSE_EVAL) - $$ = calcFunction1((int)$1, $3); - else - $$ = createCompiledFunction1(MATH_FN, (int)$1, $3); - } - | FUNCTION2 '(' math_expr ',' math_expr ')' - { if (parseType == PARSE_EVAL) - $$ = calcFunction2((int)$1, $3, $5); - else - $$ = createCompiledFunction2(MATH_FN, (int)$1, $3, $5); - } - | FUNCTION3 '(' math_expr ',' math_expr ',' math_expr ')' - { if (parseType == PARSE_EVAL) - $$ = calcFunction3((int)$1, $3, $5, $7); - else - $$ = createCompiledFunction3(MATH_FN, (int)$1, $3, $5, $7); - } - ; - - - - %% - main() - { - return(yyparse()); - } - - yywrap() - { - return(1); - } diff --git a/lib/vis_milkdrop/evallib/cal_tab.h b/lib/vis_milkdrop/evallib/cal_tab.h deleted file mode 100644 index 3621332..0000000 --- a/lib/vis_milkdrop/evallib/cal_tab.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ -#ifndef YYSTYPE -#define YYSTYPE int -#endif -#define VALUE 258 -#define IDENTIFIER 259 -#define FUNCTION1 260 -#define FUNCTION2 261 -#define FUNCTION3 262 -#define UMINUS 263 -#define UPLUS 264 - - -YYSTYPE yylval; diff --git a/lib/vis_milkdrop/evallib/cfunc.c b/lib/vis_milkdrop/evallib/cfunc.c deleted file mode 100644 index 30940b8..0000000 --- a/lib/vis_milkdrop/evallib/cfunc.c +++ /dev/null @@ -1,879 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ -#include -//#include -#include -#include -#include "Compiler.h" -#include "eval.h" -#pragma warning(disable: 4312) - -static float g_cmpaddtab[2]={0.0,1.0}; -static double g_closefact = 0.00001, g_half=0.5; -extern double *nextBlock; - - -// FUNCTION CALL TEMPLATES - THESE ARE NEVER ACTUALLY CALLED, -// BUT COPIED AND MODIFIED. -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_simpleValue(void) -{ - __asm - { - mov eax, 0FFFFFFFFh; - ret - } -} -__declspec ( naked ) void _asm_simpleValue_end(void){} - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_function3(void) -{ - __asm - { - mov ecx, 0FFFFFFFFh - call ecx - push eax - mov ecx, 0FFFFFFFFh - call ecx - push eax - mov ecx, 0FFFFFFFFh - call ecx - pop ebx - pop ecx - mov edx, 0FFFFFFFFh - jmp edx - } -} -__declspec ( naked ) void _asm_function3_end(void){} - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_function2(void) -{ - __asm - { - mov ecx, 0FFFFFFFFh - call ecx - push eax - mov ecx, 0FFFFFFFFh - call ecx - pop ebx - mov ecx, 0FFFFFFFFh - jmp ecx - } -} -__declspec ( naked ) void _asm_function2_end(void){} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_function1(void) -{ - __asm - { - mov ecx, 0FFFFFFFFh - call ecx - mov ecx, 0FFFFFFFFh - jmp ecx - } -} -__declspec ( naked ) void _asm_function1_end(void){} - -// END FUNCTION CALL TEMPLATES - - - -// our registers -static int a,b; -static double *res; - - -#define isnonzero(x) (fabs(x) > g_closefact) - -//--------------------------------------------------------------------------------------------------------------- -static double _rand(double x) -{ - if (x < 1.0) x=1.0; - return (double)(rand()%(int)max(x,1.0)); -} - -//--------------------------------------------------------------------------------------------------------------- -static double _band(double var, double var2) -{ -return isnonzero(var) && isnonzero(var2) ? 1 : 0; -} - -//--------------------------------------------------------------------------------------------------------------- -static double _bor(double var, double var2) -{ -return isnonzero(var) || isnonzero(var2) ? 1 : 0; -} - -//--------------------------------------------------------------------------------------------------------------- -static double _sig(double x, double constraint) -{ -double t = (1+exp(-x*constraint)); -return isnonzero(t) ? 1.0/t : 0; -} - - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_int(void) -{ - __asm mov dword ptr a, eax - - res = nextBlock++; - - _asm mov edx, DWORD PTR a - _asm fld QWORD PTR [edx] - _asm mov edx, DWORD PTR res - _asm fistp DWORD PTR [edx] - _asm fild DWORD PTR[edx] - _asm fstp QWORD PTR [edx] - _asm mov eax, res - _asm ret - -/* - MrC - The old version uses _ftol2_sse which stomps over our stack - *res = (double) ((int)(*((double*)a))); - __asm - { - mov eax, res - ret - } -*/ -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_asin(void) -{ - __asm mov dword ptr a, eax - - res = nextBlock++; - - *res = asin(*(double*)a); - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_acos(void) -{ - __asm mov dword ptr a, eax - - res = nextBlock++; - - *res = acos(*(double*)a); - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_atan(void) -{ - __asm mov dword ptr a, eax - - res = nextBlock++; - - *res = atan(*(double*)a); - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_atan2(void) -{ - __asm - { - mov dword ptr a, eax - mov dword ptr b, ebx - } - - res = nextBlock++; - *res = atan2(*(double*)b, *(double*)a); - __asm - { - mov eax, res - ret - } -} - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_sig(void) -{ - __asm - { - mov dword ptr a, eax - mov dword ptr b, ebx - } - res = nextBlock++; - *res = _sig(*(double*)b, *(double*)a); - __asm - { - mov eax, dword ptr res - ret - } -} -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_rand(void) -{ - __asm - { - mov dword ptr a, eax - } - - res = nextBlock++; - *res = _rand(*(double*)a); - - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_band(void) -{ - __asm - { - mov dword ptr a, eax - mov dword ptr b, ebx - } - - res = nextBlock++; - *res = _band(*(double*)b, *(double*)a); - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_bor(void) -{ - __asm - { - mov dword ptr a, eax - mov dword ptr b, ebx - } - - res = nextBlock++; - *res = _bor(*(double*)b, *(double*)a); - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_pow(void) -{ - __asm - { - mov dword ptr a, eax - mov dword ptr b, ebx - } - - res = nextBlock++; - *res = pow(*(double*)b, *(double*)a); - __asm - { - mov eax, res - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_exp(void) -{ - __asm mov dword ptr a, eax - - res = nextBlock++; - - *res = exp(*(double*)a); - __asm - { - mov eax, res - ret - } -} - - - - - - - - - - -// these below are all asm, no loops, radness - - - - - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_sin(void) -{ - __asm - { - fld qword ptr [eax] - mov eax, nextBlock - fsin - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_cos(void) -{ - __asm - { - fld qword ptr [eax] - mov eax, nextBlock - fcos - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_tan(void) -{ - __asm - { - fld qword ptr [eax] - mov eax, nextBlock - fsincos - fdiv - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_sqr(void) -{ - __asm - { - fld qword ptr [eax] - fld st(0) - mov eax, nextBlock - fmul - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_sqrt(void) -{ - __asm - { - fld qword ptr [eax] - mov eax, nextBlock - fabs - fsqrt - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_log(void) -{ - __asm - { - fld1 - fldl2e - fdiv - fld qword ptr [eax] - mov eax, nextBlock - fyl2x - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_log10(void) -{ - __asm - { - fld1 - fldl2t - fdiv - fld qword ptr [eax] - mov eax, nextBlock - fyl2x - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_abs(void) -{ - __asm - { - fld qword ptr [eax] - mov eax, nextBlock - fabs - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_assign(void) -{ - __asm - { - mov ecx, [eax] - mov edx, [eax+4] - mov [ebx], ecx - mov [ebx+4], edx - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_add(void) -{ - __asm - { - fld qword ptr [eax] - mov eax, nextBlock - fld qword ptr [ebx] - fadd - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_sub(void) -{ - __asm - { - fld qword ptr [ebx] - fld qword ptr [eax] - mov eax, nextBlock - fsub - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_mul(void) -{ - __asm - { - fld qword ptr [ebx] - fld qword ptr [eax] - mov eax, nextBlock - fmul - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_div(void) -{ - __asm - { - fld qword ptr [ebx] - fdiv qword ptr [eax] - mov eax, nextBlock - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_mod(void) -{ - __asm - { - fld qword ptr [ebx] - - fld qword ptr [eax] - fsub dword ptr [g_cmpaddtab+4] - fabs - fadd qword ptr [eax] - fadd dword ptr [g_cmpaddtab+4] - - fmul qword ptr [g_half] - - mov ebx, nextBlock - - fistp dword ptr [ebx] - fistp dword ptr [ebx+4] - mov eax, [ebx+4] - xor edx, edx - div dword ptr [ebx] - mov [ebx], edx - fild dword ptr [ebx] - fstp qword ptr [ebx] - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx // eax is still good - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_or(void) -{ - __asm - { - fld qword ptr [ebx] - fld qword ptr [eax] - mov eax, nextBlock - fistp qword ptr [eax] - fistp qword ptr [eax+8] - mov ebx, [eax] - or [eax+4], ebx - mov ebx, [eax+8] - or [eax+12], ebx - fild qword ptr [eax] - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_and(void) -{ - __asm - { - fld qword ptr [ebx] - fld qword ptr [eax] - mov eax, nextBlock - fistp qword ptr [eax] - fistp qword ptr [eax+8] - mov ebx, [eax] - and [eax+4], ebx - mov ebx, [eax+8] - and [eax+12], ebx - fild qword ptr [eax] - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_uplus(void) -{ - __asm - { - mov ebx, nextBlock - mov ecx, [eax] - mov [ebx], ecx - mov ecx, [eax+4] - mov [ebx+4], ecx - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_uminus(void) -{ - __asm - { - mov ebx, nextBlock - mov ecx, [eax] - mov [ebx], ecx - mov ecx, [eax+4] - xor ecx, 0x80000000 - mov [ebx+4], ecx - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx - ret - } -} - - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_sign(void) -{ - __asm - { - fld qword ptr [eax] - fld st(0) - fabs - mov eax, nextBlock - fld qword ptr [g_closefact] - fadd - fdiv - fstp qword ptr [eax] - add eax, 8 - mov nextBlock, eax - sub eax, 8 - ret - } -} - - - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_bnot(void) -{ - __asm - { - mov ebx, nextBlock - fld qword ptr [g_closefact] - fld qword ptr [eax] - fabs - fcompp - fstsw ax - shr eax, 6 - and eax, (1<<2) - add eax, offset g_cmpaddtab - fld dword ptr [eax] - fstp qword ptr [ebx] - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_if(void) -{ - __asm - { - fld qword ptr [eax] - fld qword ptr [ebx] - fld qword ptr [g_closefact] - fld qword ptr [ecx] - fabs - fcompp - fstsw ax - mov ebx, nextBlock - fstp qword ptr [ebx] - fstp qword ptr [ebx+8] - shr eax, 5 - and eax, (1<<3) - add eax, ebx - fld qword ptr [eax] - fstp qword ptr [ebx] - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_equal(void) -{ - __asm - { - fld qword ptr [g_closefact] - fld qword ptr [eax] - fld qword ptr [ebx] - fsub - fabs - fcompp - fstsw ax - shr eax, 6 - and eax, (1<<2) - add eax, offset g_cmpaddtab - fld dword ptr [eax] - mov eax, nextBlock - fstp qword ptr [eax] - mov ebx, eax - add ebx, 8 - mov nextBlock, ebx - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_below(void) -{ - __asm - { - fld qword ptr [eax] - fld qword ptr [ebx] - mov ebx, nextBlock - fcompp - fstsw ax - shr eax, 6 - and eax, (1<<2) - add eax, offset g_cmpaddtab - fld dword ptr [eax] - fstp qword ptr [ebx] - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx - ret - } -} - -//--------------------------------------------------------------------------------------------------------------- -__declspec ( naked ) void _asm_above(void) -{ - __asm - { - fld qword ptr [ebx] - fld qword ptr [eax] - mov ebx, nextBlock - fcompp - fstsw ax - shr eax, 6 - and eax, (1<<2) - add eax, offset g_cmpaddtab - fld dword ptr [eax] - fstp qword ptr [ebx] - mov eax, ebx - add ebx, 8 - mov nextBlock, ebx - ret - } -} - - -__declspec ( naked ) void _asm_min(void) -{ - __asm - { - fld qword ptr [eax] - fld qword ptr [ebx] - fld st(1) - mov eax, nextBlock - fld st(1) - add eax, 8 - fsub - mov nextBlock, eax - fabs // stack contains fabs(1-2),1,2 - fchs - sub eax, 8 - fadd - fadd - fld qword ptr [g_half] - fmul - fstp qword ptr [eax] - ret - } -} - -__declspec ( naked ) void _asm_max(void) -{ - __asm - { - fld qword ptr [eax] - fld qword ptr [ebx] - fld st(1) - mov eax, nextBlock - fld st(1) - add eax, 8 - fsub - mov nextBlock, eax - fabs // stack contains fabs(1-2),1,2 - sub eax, 8 - fadd - fadd - fld qword ptr [g_half] - fmul - fstp qword ptr [eax] - ret - } -} diff --git a/lib/vis_milkdrop/evallib/eval.c b/lib/vis_milkdrop/evallib/eval.c deleted file mode 100644 index 27d5d61..0000000 --- a/lib/vis_milkdrop/evallib/eval.c +++ /dev/null @@ -1,239 +0,0 @@ -/* - LICENSE - ------- -Copyright 2005 Nullsoft, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - - * Neither the name of Nullsoft nor the names of its contributors may be used to - endorse or promote products derived from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR -CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER -IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT -OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ -#include -//#include -#include -#include -#include -#include -#include -#include "cal_tab.h" -#include "compiler.h" -#include "eval.h" -#include "CAL_TAB.C" - -#define INTCONST 1 -#define DBLCONST 2 -#define HEXCONST 3 -#define VARIABLE 4 -#define OTHER 5 - -#define strnicmp _strnicmp -#define strcmpi _strcmpi - -int yyparse(char *exp); -void llinit(void); -int gettoken(char *lltb, int lltbsiz); -char yytext[256]=""; -char expression[4096]=""; -char lastVar[256]=""; -int *errPtr; -int result; -int colCount=0; - -varType *varTable; - - -//------------------------------------------------------------------------------ -void *compileExpression(char *exp) -{ - int errv=0; - errPtr=&errv; - llinit(); - if (!yyparse(exp) && !*errPtr) - { - return (void*)result; - } - return 0; -} - -// NOTE: be sure to initialize & clean these up from your app! (InitializeCriticalSection(&g_eval_cs);) -CRITICAL_SECTION g_eval_cs; -BOOL g_eval_cs_valid; - -//------------------------------------------------------------------------------ -void resetVars(varType *vars) -{ - if (!g_eval_cs_valid) - { - g_eval_cs_valid = TRUE; -// InitializeCriticalSection(&g_eval_cs); - } - -// if (vars) EnterCriticalSection(&g_eval_cs); - varTable=vars; -// if (!vars) LeaveCriticalSection(&g_eval_cs); -} - -//------------------------------------------------------------------------------ - -//------------------------------------------------------------------------------ -void setLastVar(void) -{ - gettoken(lastVar, sizeof lastVar); -} - -//------------------------------------------------------------------------------ -int setVar(int varNum, double value) -{ - int i=varNum; - if (varNum < 0) - for (i=0;i= '0' && a <= '9') v+=a-'0'; - else if (a >= 'A' && a <= 'F') v+=10+a-'A'; - else if (a >= 'a' && a <= 'f') v+=10+a-'a'; - else break; - v<<=4; - } - return createCompiledValue((double)v, NULL); - } - return 0; -} - -//------------------------------------------------------------------------------ -int objectId(int nParams) -{ - switch (nParams) - { - case 1: return FUNCTION1; - case 2: return FUNCTION2; - case 3: return FUNCTION3; - } - return IDENTIFIER; -} - -//------------------------------------------------------------------------------ -int lookup(int *typeOfObject) -{ - int i; - gettoken(yytext, sizeof yytext); - for (i=0;i Date: Mon, 25 Dec 2017 17:51:19 +0300 Subject: [PATCH 3/3] fixup! possible invalid value of preset index --- src/MilkdropXBMC.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/MilkdropXBMC.cpp b/src/MilkdropXBMC.cpp index 2142693..5c36733 100644 --- a/src/MilkdropXBMC.cpp +++ b/src/MilkdropXBMC.cpp @@ -87,6 +87,8 @@ void SetPresetDir(const char *pack) if (g_plugin->m_pPresetAddr) { g_plugin->m_bHoldPreset = lastLockedStatus; + if (lastPresetIndx < 0 || lastPresetIndx >(g_plugin->m_nPresets - g_plugin->m_nDirs)) + lastPresetIndx = 0; g_plugin->m_nCurrentPreset = lastPresetIndx; strcpy(g_plugin->m_szCurrentPresetFile, g_plugin->m_szPresetDir); strcat(g_plugin->m_szCurrentPresetFile, g_plugin->m_pPresetAddr[g_plugin->m_nCurrentPreset]);