Mercurial > repos > rhope
view interp.h @ 57:2174878a6e4b
Avoid unnecessary nested switch
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Thu, 08 Oct 2009 02:12:25 -0400 |
parents | 9ee9adc696e7 |
children | 429b5f441381 |
line wrap: on
line source
#ifndef _INTERP_H_ #define _INTERP_H_ #ifdef WIN32 #include <windows.h> #endif #ifndef BOOL #define BOOL short #define TRUE 1 #define FALSE 0 #endif #ifndef DWORD #define DWORD unsigned long #endif #ifndef WINAPI #define WINAPI #endif #ifndef LPVOID #define LPVOID void * #endif #ifndef NULL #define NULL 0 #endif #include "vis_threading.h" #include "structs.h" #include "debugmacros.h" #define CONSTANT 0 #define ROOM 1 #define WORKER 2 #define INPUT 3 #define OUTPUT 4 #define SET_COMP 5 #define GET_COMP 6 #define SET_GLOBAL 7 #define GET_GLOBAL 8 #define TAIL_CALL 9 #define TAIL_RECURSE 10 #define RECTANGLE 1 #define TRAPEZOID 2 #define WORKER_TYPE 0 #define MAGIC_TYPE 1 #define USER_FLAG 0x8000 #define TYPE_MASK 0xFF #define START_COMP_STORAGE 128 #define START_DEF_STORAGE 100 #ifdef CPLUSPLUS extern "C" { #endif //extern company companylist[]; //extern int num_companies; extern BOOL execute_active; extern int program_count; VIS_EXTERN_CRITICAL_SECTION(program_count_lock) void main_callback(worker_instance * junkinst, int junk, worker_instance * main_instance, void * data); void optimize(worker_def * def); void run_optimized(worker_instance * instance, datum ** params); datum * get_constant(char * value, int len, program * prog); int execute_def(worker_def * process_def, queue_entry worker_entry, datum ** params, instance_callback callback); int execute_def_data(worker_def * process_def, queue_entry worker_entry, datum ** params, instance_callback callback, void * data); BOOL execute_def_wait(worker_def * def, datum ** params); int process_worker(queue_entry aworker); void initworkers(program * prog); void initpredefworkers(program * prog); DWORD WINAPI worker_thread(LPVOID param); void interp_start(int num_threads, BOOL use_this_thread, int argc, char ** argv, program * initial_prog); void interp_stop(); void add_if_ready(int workerNum, worker_instance * instance); void make_lookup_arrays(program * prog); void def_make_lookup(worker_def * def); queue_entry get_queue(); void add_queue(int data, worker_instance * instance); void add_multiple(int * data, int num, worker_instance * instance); void init_sync_primitives(); void init_global_storage(); void pack_list_sub_callback(worker_instance * caller_instance, int caller_workernum, worker_instance * done_instance, void * data); worker_def * find_method(int type, char * name, int num_inputs, program * prog); worker_def * find_method_noinputcheck(int type, char * name, program * prog); worker_def * find_converter_method(int totype, int fromtype, program * prog); //doesn't belong here, but because of include order issues I can't put it in datum.h datum * new_datum_comp(company * comp, unsigned char union_type, int generic_len); void vis_window_init(); //defined in window.cpp int unix_time(datum ** inputlist, queue_entry * worker_entry); int vis_random(datum ** inputlist, queue_entry * worker_entry); int vis_print(datum ** inputlist, queue_entry * worker_entry); int vis_build(datum ** inputlist, queue_entry * worker_entry); int vis_end(datum ** inputlist, queue_entry * worker_entry); int vis_append(datum ** inputlist, queue_entry * worker_entry); int vis_getinput(datum ** inputlist, queue_entry * worker_entry); int vis_stringtoint(datum ** inputlist, queue_entry * worker_entry); int vis_string_get_dstring(datum ** inputlist, queue_entry * worker_entry); int vis_whole_add(datum ** inputlist, queue_entry * worker_entry); int vis_whole_fromhex(datum ** inputlist, queue_entry * worker_entry); int vis_whole_subtract(datum ** inputlist, queue_entry * worker_entry); int vis_whole_mult(datum ** inputlist, queue_entry * worker_entry); int vis_whole_div(datum ** inputlist, queue_entry * worker_entry); int vis_whole_or(datum ** inputlist, queue_entry * worker_entry); int vis_whole_and(datum ** inputlist, queue_entry * worker_entry); int vis_whole_lsh(datum ** inputlist, queue_entry * worker_entry); int vis_whole_rsh(datum ** inputlist, queue_entry * worker_entry); int vis_inttostring(datum ** inputlist, queue_entry * worker_entry); int vis_stringequal(datum ** inputlist, queue_entry * worker_entry); int vis_string_split(datum ** inputlist, queue_entry * worker_entry); int vis_string_get_raw(datum ** inputlist, queue_entry * worker_entry); int vis_string_put_raw(datum ** inputlist, queue_entry * worker_entry); int vis_string_slice(datum ** inputlist, queue_entry * worker_entry); int vis_string_reverse(datum ** inputlist, queue_entry * worker_entry); int vis_string_length(datum ** inputlist, queue_entry * worker_entry); int vis_string_put_byte(datum ** inputlist, queue_entry * worker_entry); int vis_wholeequal(datum ** inputlist, queue_entry * worker_entry); int vis_if(datum ** inputlist, queue_entry * worker_entry); int vis_yesnotostring(datum ** inputlist, queue_entry * worker_entry); int vis_greaterint(datum ** inputlist, queue_entry * worker_entry); int vis_lesserint(datum ** inputlist, queue_entry * worker_entry); int vis_greaterstring(datum ** inputlist, queue_entry * worker_entry); int vis_lesserstring(datum ** inputlist, queue_entry * worker_entry); int vis_stringtoreal(datum ** inputlist, queue_entry * worker_entry); int vis_real_add(datum ** inputlist, queue_entry * worker_entry); int vis_real_subtract(datum ** inputlist, queue_entry * worker_entry); int vis_realequal(datum ** inputlist, queue_entry * worker_entry); int vis_greaterreal(datum ** inputlist, queue_entry * worker_entry); int vis_lesserreal(datum ** inputlist, queue_entry * worker_entry); int vis_realtostring(datum ** inputlist, queue_entry * worker_entry); //Index, Append, Swap, Insert, Remove, Set, Length, New int vis_list_index(datum ** inputlist, queue_entry * worker_entry); int vis_list_append(datum ** inputlist, queue_entry * worker_entry); int vis_list_swap(datum ** inputlist, queue_entry * worker_entry); int vis_list_insert(datum ** inputlist, queue_entry * worker_entry); int vis_list_remove(datum ** inputlist, queue_entry * worker_entry); int vis_list_set(datum ** inputlist, queue_entry * worker_entry); int vis_list_length(datum ** inputlist, queue_entry * worker_entry); int vis_list_new(datum ** inputlist, queue_entry * worker_entry); int vis_list_first(datum ** inputlist, queue_entry * worker_entry); int vis_list_next(datum ** inputlist, queue_entry * worker_entry); int vis_dict_index(datum ** inputlist, queue_entry * worker_entry); int vis_dict_swap(datum ** inputlist, queue_entry * worker_entry); int vis_dict_remove(datum ** inputlist, queue_entry * worker_entry); int vis_dict_set(datum ** inputlist, queue_entry * worker_entry); int vis_dict_length(datum ** inputlist, queue_entry * worker_entry); int vis_dict_new(datum ** inputlist, queue_entry * worker_entry); int vis_dict_first(datum ** inputlist, queue_entry * worker_entry); int vis_dict_next(datum ** inputlist, queue_entry * worker_entry); int vis_file_from_string(datum ** inputlist, queue_entry * worker_entry); int vis_file_get_fstring(datum ** inputlist, queue_entry * worker_entry); int vis_file_get_dstring(datum ** inputlist, queue_entry * worker_entry); int vis_file_get_byte(datum ** inputlist, queue_entry * worker_entry); int vis_file_get_word(datum ** inputlist, queue_entry * worker_entry); int vis_file_get_long(datum ** inputlist, queue_entry * worker_entry); int vis_file_get_double(datum ** inputlist, queue_entry * worker_entry); int vis_file_put_string(datum ** inputlist, queue_entry * worker_entry); int vis_file_length(datum ** inputlist, queue_entry * worker_entry); int vis_worker_from_string(datum ** inputlist, queue_entry * worker_entry); int vis_worker_do(datum ** inputlist, queue_entry * worker_entry); int vis_worker_setinput(datum ** inputlist, queue_entry * worker_entry); int vis_window_new(datum ** inputlist, queue_entry * worker_entry); int vis_window_add_widget(datum ** inputlist, queue_entry * worker_entry); int vis_window_show(datum ** inputlist, queue_entry * worker_entry); int vis_window_wait_close(datum ** inputlist, queue_entry * worker_entry); int vis_window_get_value(datum ** inputlist, queue_entry * worker_entry); int vis_window_set_value(datum ** inputlist, queue_entry * worker_entry); int vis_window_shown_addwidget(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_worker_call(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_wire(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_constant(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_input(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_output(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_globalget(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_globalset(datum ** inputlist, queue_entry * worker_entry); int vis_worker_clear(datum ** inputlist, queue_entry * worker_entry); int vis_worker_uses(datum ** inputlist, queue_entry * worker_entry); int vis_worker_new(datum ** inputlist, queue_entry * worker_entry); int vis_worker_setio_counts(datum ** inputlist, queue_entry * worker_entry); int vis_program_run(datum ** inputlist, queue_entry * worker_entry); int vis_program_add_builtins(datum ** inputlist, queue_entry * worker_entry); int vis_program_new_worker(datum ** inputlist, queue_entry * worker_entry); int vis_program_new(datum ** inputlist, queue_entry * worker_entry); int vis_program_find_worker(datum ** inputlist, queue_entry * worker_entry); int vis_program_add_worker(datum ** inputlist, queue_entry * worker_entry); int vis_button_new(datum ** inputlist, queue_entry * worker_entry); int vis_button_set_handler(datum ** inputlist, queue_entry * worker_entry); int vis_inputbox_new(datum ** inputlist, queue_entry * worker_entry); int vis_inputbox_settype(datum ** inputlist, queue_entry * worker_entry); int net_client_new(datum ** params, queue_entry * worker_entry); int net_client_put_string(datum ** params, queue_entry * worker_entry); int net_client_get_fstring(datum ** params, queue_entry * worker_entry); int net_client_get_dstring(datum ** params, queue_entry * worker_entry); int net_client_put_raw(datum ** params, queue_entry * worker_entry); int net_client_get_raw(datum ** params, queue_entry * worker_entry); int vis_net_listenport(datum ** params, queue_entry * worker_entry); int vis_wait_forever(datum ** params, queue_entry * worker_entry); int vis_screen_custom_defaultpaint(datum ** params, queue_entry * entry); int vis_screen_custom_drawline(datum ** params, queue_entry * entry); int vis_screen_custom_drawstring(datum ** params, queue_entry * entry); int vis_screen_custom_setdrawcolor(datum ** params, queue_entry * entry); int vis_screen_custom_moveby(datum ** params, queue_entry * entry); int vis_screen_custom_sethandler(datum ** params, queue_entry * entry); int vis_screen_custom_removehandler(datum ** params, queue_entry * entry); int vis_screen_custom_givefocus(datum ** params, queue_entry * entry); int vis_screen_custom_addwidget(datum ** params, queue_entry * entry); int vis_screen_custom_getwindow(datum ** params, queue_entry * entry); int vis_customwidget_new(datum ** inputlist, queue_entry * worker_entry); int vis_checkbox_new(datum ** params, queue_entry * entry); int vis_dropdown_new(datum ** params, queue_entry * entry); int vis_dropdown_settext(datum ** params, queue_entry * entry); int vis_dropdown_select(datum ** params, queue_entry * entry); int vis_buffer_new(datum ** params, queue_entry * entry); int vis_buffer_lock(datum ** params, queue_entry * entry); int vis_buffer_unlock(datum ** params, queue_entry * entry); int vis_buffer_putbyte(datum ** params, queue_entry * entry); int vis_buffer_writebyte(datum ** params, queue_entry * entry); int vis_buffer_putshort(datum ** params, queue_entry * entry); int vis_buffer_writeshort(datum ** params, queue_entry * entry); int vis_buffer_putlong(datum ** params, queue_entry * entry); int vis_buffer_writelong(datum ** params, queue_entry * entry); int vis_buffer_reset(datum ** params, queue_entry * entry); int vis_buffer_fromaddress(datum ** params, queue_entry * entry); int init_global_store(datum ** params, queue_entry * worker_entry); int vis_type_of(datum ** params, queue_entry * worker_entry); int vis_real_div(datum ** inputlist, queue_entry * worker_entry); int vis_real_mult(datum ** inputlist, queue_entry * worker_entry); int vis_real_cos(datum ** inputlist, queue_entry * worker_entry); int vis_real_sin(datum ** inputlist, queue_entry * worker_entry); int vis_real_tan(datum ** inputlist, queue_entry * worker_entry); int vis_real_arccos(datum ** inputlist, queue_entry * worker_entry); int vis_real_arcsin(datum ** inputlist, queue_entry * worker_entry); int vis_real_arctan(datum ** inputlist, queue_entry * worker_entry); int vis_real_exp(datum ** inputlist, queue_entry * workere_entry); int vis_real_sqrt(datum ** inputlist, queue_entry * worker_entry); int vis_clear_handler(datum ** params, queue_entry * entry); int vis_register_handler(datum ** params, queue_entry * entry); int vis_held_keys(datum ** params, queue_entry * worker_entry); int vis_touch_position(datum ** params, queue_entry * worker_entry); int vis_blueprint_new(datum ** params, queue_entry * entry); int vis_blueprint_addfield(datum ** params, queue_entry * entry); int vis_blueprint_name(datum ** params, queue_entry * entry); int vis_blueprint_getfields(datum ** params, queue_entry * entry); int vis_get_blueprint(datum ** params, queue_entry * entry); int vis_get_field(datum ** params, queue_entry * entry); int vis_set_field(datum ** params, queue_entry * entry); int vis_program_newblueprint(datum ** params, queue_entry * entry); int vis_worker_add_objectset(datum ** inputlist, queue_entry * worker_entry); int vis_worker_add_objectget(datum ** inputlist, queue_entry * worker_entry); datum * make_string(const char * string, int len, program * prog); void close_sync_primitives(); void vis_window_closed(datum * window_datum); void cleanup_check(queue_entry aworker); void cleanup_custom_worker(worker_instance * instance, int worker_num); void process_outputs(datum ** params, int aworker, worker_instance * instance); void worker_complete(queue_entry aworker); void test_virtual(); datum * create_dict(program * prog); datum * create_list(program * prog); int worker_populate_inputs(datum * inputWorker, datum * ioList, datum ** inputlist); void run_queued_irqs(); void prep_program(program * prog); void add_program_ref(program * prog); void release_program_ref(program * prog); extern int irq_queue_count; #ifdef ENABLE_PROFILING #define NUM_PROFS 33 extern __int64 vis_profile_start_times[NUM_PROFS]; extern __int64 vis_profile_running_total[NUM_PROFS]; extern int vis_profile_counts[NUM_PROFS]; unsigned __int64 __cdecl rdtsc(void); #define VIS_PROFILE_START(index) vis_profile_start_times[index] = rdtsc() #define VIS_PROFILE_END(index) vis_profile_running_total[index] += (rdtsc()-vis_profile_start_times[index]); ++vis_profile_counts[index] #define PROF_ADDREF 29 #define PROF_RELEASE 30 #define PROF_NEW_DATUM 31 #define PROF_DATUM_ALLOC 32 #else #define VIS_PROFILE_START(index) #define VIS_PROFILE_END(index) #endif #ifdef CPLUSPLUS } #endif #endif //_INTERP_H_