1010#include <assert.h>
1111#include <stdint.h>
1212
13+ #if PRJM_F_SIZE == 4
14+ typedef int32_t PRJM_EVAL_I ;
15+ #else
16+ typedef int64_t PRJM_EVAL_I ;
17+ #endif
1318/**
1419 * @brief projectM-EvalLib intrinsic Function table.
1520 * Contains all predefined functions and information about their invocation. Most functions beginning
@@ -151,7 +156,7 @@ static const PRJM_EVAL_F close_factor_low = 1e-300;
151156#define UPPER_MASK 0x80000000UL /* most significant w-r bits */
152157#define LOWER_MASK 0x7fffffffUL /* least significant r bits */
153158
154- void prjm_eval_intrinsic_functions (prjm_eval_intrinsic_function_list_ptr list , int * count )
159+ void prjm_eval_intrinsic_functions (prjm_eval_intrinsic_function_list_ptr list , uint32_t * count )
155160{
156161 * count = sizeof (intrinsic_function_table ) / sizeof (prjm_eval_function_def_t );
157162 * list = intrinsic_function_table ;
@@ -265,14 +270,14 @@ prjm_eval_function_decl(execute_loop)
265270 PRJM_EVAL_F * value_ptr = & ctx -> value ;
266271 invoke_arg (0 , & value_ptr );
267272
268- int loop_count_int = (int ) (* value_ptr );
273+ PRJM_EVAL_I loop_count_int = (PRJM_EVAL_I ) (* value_ptr );
269274 /* Limit execution count */
270275 if (loop_count_int > MAX_LOOP_COUNT )
271276 {
272277 loop_count_int = MAX_LOOP_COUNT ;
273278 }
274279
275- for (int i = 0 ; i < loop_count_int ; i ++ )
280+ for (PRJM_EVAL_I i = 0 ; i < loop_count_int ; i ++ )
276281 {
277282 ctx -> value = .0 ;
278283 value_ptr = & ctx -> value ;
@@ -288,7 +293,7 @@ prjm_eval_function_decl(execute_while)
288293
289294 ctx -> value = .0 ;
290295 PRJM_EVAL_F * value_ptr = & ctx -> value ;
291- int loop_count_int = MAX_LOOP_COUNT ;
296+ PRJM_EVAL_I loop_count_int = MAX_LOOP_COUNT ;
292297 do
293298 {
294299 invoke_arg (0 , & value_ptr );
@@ -361,7 +366,7 @@ prjm_eval_function_decl(mem)
361366 invoke_arg (0 , & index_ptr );
362367
363368 // Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
364- PRJM_EVAL_F * mem_addr = prjm_eval_memory_allocate (ctx -> memory_buffer , (int ) (* index_ptr + 0.0001 ));
369+ PRJM_EVAL_F * mem_addr = prjm_eval_memory_allocate (ctx -> memory_buffer , (int32_t ) (* index_ptr + 0.0001 ));
365370 if (mem_addr )
366371 {
367372 assign_ret_ref (mem_addr );
@@ -379,7 +384,7 @@ prjm_eval_function_decl(freembuf)
379384 invoke_arg (0 , ret_val );
380385
381386 // Add 0.0001 to avoid using the wrong index due to tiny float rounding errors.
382- prjm_eval_memory_free_block (ctx -> memory_buffer , (int ) (* * ret_val + 0.0001 ));
387+ prjm_eval_memory_free_block (ctx -> memory_buffer , (int32_t ) (* * ret_val + 0.0001 ));
383388}
384389
385390prjm_eval_function_decl (memcpy )
@@ -601,13 +606,13 @@ prjm_eval_function_decl(mod)
601606 invoke_arg (0 , & val1_ptr );
602607 invoke_arg (1 , & val2_ptr );
603608
604- int divisor = (int ) * val2_ptr ;
609+ PRJM_EVAL_I divisor = (PRJM_EVAL_I ) * val2_ptr ;
605610 if (divisor == 0 )
606611 {
607612 assign_ret_val (0.0 );
608613 return ;
609614 }
610- assign_ret_val ((PRJM_EVAL_F ) ((int ) * val1_ptr % divisor ));
615+ assign_ret_val ((PRJM_EVAL_F ) ((PRJM_EVAL_I ) * val1_ptr % divisor ));
611616}
612617
613618prjm_eval_function_decl (boolean_and_op )
@@ -776,7 +781,7 @@ prjm_eval_function_decl(bitwise_or_op)
776781 invoke_arg (0 , ret_val );
777782 invoke_arg (1 , & val2_ptr );
778783
779- assign_ret_val ((PRJM_EVAL_F ) ((int )(* * ret_val ) | (int )(* val2_ptr )));
784+ assign_ret_val ((PRJM_EVAL_F ) ((PRJM_EVAL_I )(* * ret_val ) | (PRJM_EVAL_I )(* val2_ptr )));
780785}
781786
782787prjm_eval_function_decl (bitwise_or )
@@ -791,7 +796,7 @@ prjm_eval_function_decl(bitwise_or)
791796 invoke_arg (0 , & val1_ptr );
792797 invoke_arg (1 , & val2_ptr );
793798
794- assign_ret_val ((PRJM_EVAL_F ) ((int )(* val1_ptr ) | (int )(* val2_ptr )));
799+ assign_ret_val ((PRJM_EVAL_F ) ((PRJM_EVAL_I )(* val1_ptr ) | (PRJM_EVAL_I )(* val2_ptr )));
795800}
796801
797802prjm_eval_function_decl (bitwise_and_op )
@@ -804,7 +809,7 @@ prjm_eval_function_decl(bitwise_and_op)
804809 invoke_arg (0 , ret_val );
805810 invoke_arg (1 , & val2_ptr );
806811
807- assign_ret_val ((PRJM_EVAL_F ) ((int )(* * ret_val ) & (int )(* val2_ptr )));
812+ assign_ret_val ((PRJM_EVAL_F ) ((PRJM_EVAL_I )(* * ret_val ) & (PRJM_EVAL_I )(* val2_ptr )));
808813}
809814
810815prjm_eval_function_decl (bitwise_and )
@@ -819,7 +824,7 @@ prjm_eval_function_decl(bitwise_and)
819824 invoke_arg (0 , & val1_ptr );
820825 invoke_arg (1 , & val2_ptr );
821826
822- assign_ret_val ((PRJM_EVAL_F ) ((int )(* val1_ptr ) & (int )(* val2_ptr )));
827+ assign_ret_val ((PRJM_EVAL_F ) ((PRJM_EVAL_I )(* val1_ptr ) & (PRJM_EVAL_I )(* val2_ptr )));
823828}
824829
825830prjm_eval_function_decl (mod_op )
@@ -832,13 +837,13 @@ prjm_eval_function_decl(mod_op)
832837 invoke_arg (0 , ret_val );
833838 invoke_arg (1 , & val2_ptr );
834839
835- int divisor = (int ) * val2_ptr ;
840+ PRJM_EVAL_I divisor = (PRJM_EVAL_I ) * val2_ptr ;
836841 if (divisor == 0 )
837842 {
838843 assign_ret_val (0.0 );
839844 return ;
840845 }
841- assign_ret_val ((PRJM_EVAL_F ) ((int )(* * ret_val ) % divisor ));
846+ assign_ret_val ((PRJM_EVAL_F ) ((PRJM_EVAL_I )(* * ret_val ) % divisor ));
842847}
843848
844849prjm_eval_function_decl (pow_op )
0 commit comments