diff options
33 files changed, 5521 insertions, 4789 deletions
@@ -13,7 +13,7 @@ project version mediator ----------------------------------------------------------------------- ffmpeg build 4715 Mike Melanson -goom 2k4-dev18 +goom 2k4-dev21 gsm610 1.0.10 Mike Melanson liba52 0.7.4 libcdio 0.68 @@ -9,6 +9,8 @@ xine-lib (1-xxx) accelerated decoding occured while software surfaces still needed to be duplicated. * fixed plugin catalog cache (faster xine startup) + * updated internal goom to 2k4-dev21; randomized and improved look of + initial effect (hopefully no more white screens any more) xine-lib (1-rc7) * Build system improvements: replacement functions, better work with headers diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am index 9b2cc3695..74731cfd5 100644 --- a/src/post/goom/Makefile.am +++ b/src/post/goom/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/misc/Makefile.common libdir = $(XINE_PLUGINDIR)/post -EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s +EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s diff_against_release.patch ## -fomit-frame-pointer segfaults here CFLAGS = `echo @CFLAGS@ | sed -e 's/-fomit-frame-pointer//g;s/-Os//g'` @@ -22,14 +22,14 @@ endif xineplug_post_goom_la_SOURCES = $(extra_files) xine_goom.c \ config_param.c convolve_fx.c cpu_info.c drawmethods.c filters.c flying_stars_fx.c \ - gfontlib.c gfontrle.c goom_core.c goom_hash.c goom_script.c goom_script_lex.c \ - goom_script_yacc.c goom_tools.c graphic.c ifs.c lines.c mathtools.c \ + gfontlib.c gfontrle.c goom_core.c goom_tools.c goomsl.c goomsl_hash.c \ + goomsl_lex.c goomsl_yacc.c graphic.c ifs.c lines.c mathtools.c \ plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c xineplug_post_goom_la_LIBADD = $(XINE_LIB) $(GOOM_LIBS) xineplug_post_goom_la_LDFLAGS = -avoid-version -module $(XINE_PLUGIN_MIN_SYMS) noinst_HEADERS = cpu_info.h default_scripts.h drawmethods.h gfontlib.h gfontrle.h goom.h \ - goom_config.h goom_config_param.h goom_filters.h goom_fx.h goom_graphic.h goom_hash.h \ - goom_plugin_info.h goom_script.h goom_script_scanner.h goom_script_yacc.h \ - goom_tools.h goom_typedefs.h goom_visual_fx.h ifs.h lines.h mathtools.h mmx.h \ + goom_config.h goom_config_param.h goom_filters.h goom_fx.h goom_graphic.h \ + goom_plugin_info.h goom_tools.h goom_typedefs.h goom_visual_fx.h goomsl.h goomsl_hash.h \ + goomsl_private.h goomsl_yacc.h ifs.h lines.h mathtools.h mmx.h \ ppc_drawings.h ppc_zoom_ultimate.h sound_tester.h surf3d.h tentacle3d.h v3d.h diff --git a/src/post/goom/config_param.c b/src/post/goom/config_param.c index 2be4bafc9..c6402834a 100644 --- a/src/post/goom/config_param.c +++ b/src/post/goom/config_param.c @@ -11,10 +11,12 @@ #include "goom_config_param.h" #include <string.h> +/* TODO: Ajouter goom_ devant ces fonctions */ + static void empty_fct(PluginParam *dummy) { } -PluginParam secure_param() { +PluginParam goom_secure_param() { PluginParam p; p.changed = empty_fct; p.change_listener = empty_fct; @@ -24,7 +26,7 @@ PluginParam secure_param() { return p; } -PluginParam secure_f_param(char *name) { +PluginParam goom_secure_f_param(char *name) { PluginParam p = secure_param(); p.name = name; p.type = PARAM_FLOATVAL; @@ -35,13 +37,13 @@ PluginParam secure_f_param(char *name) { return p; } -PluginParam secure_f_feedback(char *name) { +PluginParam goom_secure_f_feedback(char *name) { PluginParam p = secure_f_param(name); p.rw = 0; return p; } -PluginParam secure_s_param(char *name) { +PluginParam goom_secure_s_param(char *name) { PluginParam p = secure_param(); p.name = name; p.type = PARAM_STRVAL; @@ -49,7 +51,7 @@ PluginParam secure_s_param(char *name) { return p; } -PluginParam secure_b_param(char *name, int value) { +PluginParam goom_secure_b_param(char *name, int value) { PluginParam p = secure_param(); p.name = name; p.type = PARAM_BOOLVAL; @@ -57,7 +59,7 @@ PluginParam secure_b_param(char *name, int value) { return p; } -PluginParam secure_i_param(char *name) { +PluginParam goom_secure_i_param(char *name) { PluginParam p = secure_param(); p.name = name; p.type = PARAM_INTVAL; @@ -68,13 +70,13 @@ PluginParam secure_i_param(char *name) { return p; } -PluginParam secure_i_feedback(char *name) { +PluginParam goom_secure_i_feedback(char *name) { PluginParam p = secure_i_param(name); p.rw = 0; return p; } -PluginParameters plugin_parameters(const char *name, int nb) { +PluginParameters goom_plugin_parameters(const char *name, int nb) { PluginParameters p; p.name = (char *)name; p.desc = ""; @@ -85,7 +87,7 @@ PluginParameters plugin_parameters(const char *name, int nb) { /*---------------------------------------------------------------------------*/ -void set_str_param_value(PluginParam *p, const char *str) { +void goom_set_str_param_value(PluginParam *p, const char *str) { int len = strlen(str); if (SVAL(*p)) SVAL(*p) = (char*)realloc(SVAL(*p), len+1); @@ -94,7 +96,7 @@ void set_str_param_value(PluginParam *p, const char *str) { memcpy(SVAL(*p), str, len+1); } -void set_list_param_value(PluginParam *p, const char *str) { +void goom_set_list_param_value(PluginParam *p, const char *str) { int len = strlen(str); #ifdef VERBOSE printf("%s: %d\n", str, len); diff --git a/src/post/goom/convolve_fx.c b/src/post/goom/convolve_fx.c index c73b541f9..1aaa4ae28 100644 --- a/src/post/goom/convolve_fx.c +++ b/src/post/goom/convolve_fx.c @@ -1,13 +1,14 @@ #include "goom_fx.h" #include "goom_plugin_info.h" -#include "goom_script_scanner.h" +#include "goomsl.h" #include "goom_config.h" #include <math.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -static const char DEF_SCRIPT[] = +static const char DEF_SCRIPT[] = "\n\n"; +#if 0 "-> config;\n" "-> main;\n" "\n" @@ -21,6 +22,7 @@ static const char DEF_SCRIPT[] = "\n" " Bright_Flash.Factor = Bright_Flash.Factor * DECAY_RATE;\n" "\n"; +#endif #define MAX 2.0f @@ -36,7 +38,7 @@ typedef struct _CONV_DATA{ PluginParam compile_p; PluginParameters params; - GoomScriptScanner *script; + GoomSL *script; } ConvData; @@ -50,9 +52,9 @@ static void convolve_init(VisualFX *_this) { data->light.param.fval.value = 100.0f; data->factor_adj_p = secure_f_param("Flash Intensity"); - data->factor_adj_p.param.fval.max = 200.0f; + data->factor_adj_p.param.fval.max = 100.0f; data->factor_adj_p.param.fval.step = 1.0f; - data->factor_adj_p.param.fval.value = 100.0f; + data->factor_adj_p.param.fval.value = 50.0f; data->factor_p = secure_f_feedback("Factor"); /* FVAL(data->factor_p) = data->factor / MAX;*/ @@ -70,7 +72,7 @@ static void convolve_init(VisualFX *_this) { data->params.params[5] = &data->script_p; data->params.params[6] = &data->compile_p; - data->script = goom_script_scanner_new(); + data->script = gsl_new(); _this->params = &data->params; _this->fx_data = (void*)data; @@ -112,21 +114,21 @@ static void convolve_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo ff = (FVAL(data->factor_p) * FVAL(data->factor_adj_p) + FVAL(data->light) ) / 100.0f; iff = (unsigned int)(ff * 256); - if (!goom_script_scanner_is_compiled(data->script)) { + if (!gsl_is_compiled(data->script)) { #ifdef VERBOSE printf("setting default script for dynamic brightness\n"); #endif - goom_script_scanner_compile(data->script, info, DEF_SCRIPT); + gsl_compile(data->script, DEF_SCRIPT); } if (BVAL(data->compile_p)) { /* le bouton du pauvre ... */ - goom_script_scanner_compile(data->script, info, SVAL(data->script_p)); + gsl_compile(data->script, SVAL(data->script_p)); BVAL(data->compile_p) = 0; data->compile_p.change_listener(&data->compile_p); } - if (goom_script_scanner_is_compiled(data->script)) { - goom_script_scanner_execute(data->script); + if (gsl_is_compiled(data->script)) { + gsl_execute(data->script); } info->methods.create_output_with_brightness(src,dest,info->screen.size,iff); diff --git a/src/post/goom/cpu_info.c b/src/post/goom/cpu_info.c index 67d0a19de..14e150e15 100644 --- a/src/post/goom/cpu_info.c +++ b/src/post/goom/cpu_info.c @@ -9,10 +9,14 @@ #include "cpu_info.h" -#ifdef HAVE_MMX +#ifdef CPU_X86 #include "mmx.h" #endif +#ifdef CPU_POWERPC +#include <sys/types.h> +#include <stdlib.h> +#endif static unsigned int CPU_FLAVOUR = 0; static unsigned int CPU_NUMBER = 1; diff --git a/src/post/goom/cpu_info.h b/src/post/goom/cpu_info.h index 184cb5102..81e66b5f1 100644 --- a/src/post/goom/cpu_info.h +++ b/src/post/goom/cpu_info.h @@ -11,8 +11,10 @@ */ #ifdef HAVE_MMX +#ifndef CPU_X86 #define CPU_X86 #endif +#endif /* Returns the CPU flavour described with the constants below */ unsigned int cpu_flavour (void); diff --git a/src/post/goom/diff_against_release.patch b/src/post/goom/diff_against_release.patch new file mode 100644 index 000000000..0998eef84 --- /dev/null +++ b/src/post/goom/diff_against_release.patch @@ -0,0 +1,45 @@ +--- goom_tools.c 2004-09-10 17:10:39.000000000 +0200 ++++ goom_tools.c 2004-11-21 15:28:12.000000000 +0100 +@@ -3,7 +3,6 @@ + + GoomRandom *goom_random_init(int i) { + GoomRandom *grandom = (GoomRandom*)malloc(sizeof(GoomRandom)); +- srand (i); + grandom->pos = 1; + goom_random_update_array(grandom, GOOM_NB_RAND); + return grandom; +--- convolve_fx.c 2004-09-10 17:10:38.000000000 +0200 ++++ convolve_fx.c 2004-11-21 15:48:24.729326912 +0100 +@@ -52,9 +52,9 @@ + data->light.param.fval.value = 100.0f; + + data->factor_adj_p = secure_f_param("Flash Intensity"); +- data->factor_adj_p.param.fval.max = 200.0f; ++ data->factor_adj_p.param.fval.max = 100.0f; + data->factor_adj_p.param.fval.step = 1.0f; +- data->factor_adj_p.param.fval.value = 100.0f; ++ data->factor_adj_p.param.fval.value = 50.0f; + + data->factor_p = secure_f_feedback("Factor"); + /* FVAL(data->factor_p) = data->factor / MAX;*/ +--- filters.c 2004-09-10 17:10:39.000000000 +0200 ++++ filters.c 2004-11-21 15:37:55.000000000 +0100 +@@ -705,7 +705,7 @@ + + data->general_speed = 0.0f; + data->reverse = 0; +- data->theMode = AMULETTE_MODE; ++ data->theMode = rand() % 10; + data->waveEffect = 0; + data->hypercosEffect = 0; + data->vPlaneEffect = 0; +--- goomsl_lex.c 2004-09-10 17:10:39.000000000 +0200 ++++ goomsl_lex.c 2004-11-21 15:42:50.306166960 +0100 +@@ -624,6 +624,7 @@ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + ++YY_DECL; + YY_DECL + { + register yy_state_type yy_current_state; diff --git a/src/post/goom/filters.c b/src/post/goom/filters.c index 92fb16bc6..3aa096e8a 100644 --- a/src/post/goom/filters.c +++ b/src/post/goom/filters.c @@ -705,7 +705,7 @@ static void zoomFilterVisualFXWrapper_init (struct _VISUAL_FX *_this) data->general_speed = 0.0f; data->reverse = 0; - data->theMode = AMULETTE_MODE; + data->theMode = rand() % 10; data->waveEffect = 0; data->hypercosEffect = 0; data->vPlaneEffect = 0; diff --git a/src/post/goom/goom.h b/src/post/goom/goom.h index bc0a88623..35e4e751e 100644 --- a/src/post/goom/goom.h +++ b/src/post/goom/goom.h @@ -3,7 +3,7 @@ #include "goom_config.h" #include "goom_plugin_info.h" -#include "goom_script.h" +#include "goomsl.h" #define NB_FX 10 diff --git a/src/post/goom/goom_config.h b/src/post/goom/goom_config.h index 3c9b2c2c8..5f6f15893 100644 --- a/src/post/goom/goom_config.h +++ b/src/post/goom/goom_config.h @@ -1,15 +1,15 @@ - -//#define VERSION "1.9.2" -//#define _DEBUG - +#if WORDS_BIGENDIAN +#define COLOR_ARGB +#else #define COLOR_BGRA -//#define COLOR_ARGB +#endif -#ifdef COLOR_BGRA +#if 1 +/* ndef COLOR_BGRA */ /** position des composantes **/ - #define ROUGE 2 #define BLEU 0 #define VERT 1 + #define ROUGE 2 #define ALPHA 3 #else #define ROUGE 1 @@ -17,17 +17,6 @@ #define VERT 2 #define ALPHA 0 #endif - - -// target -//#define XMMS_PLUGIN -#define STANDALONE - -//#define POWERPC - -#define HAVE_ATHLON - -//#define VERBOSE #ifndef guint32 #define guint8 unsigned char diff --git a/src/post/goom/goom_config_param.h b/src/post/goom/goom_config_param.h index cfa16917b..3c6838d30 100644 --- a/src/post/goom/goom_config_param.h +++ b/src/post/goom/goom_config_param.h @@ -79,18 +79,18 @@ typedef struct _PARAM { #define IMAX(p) ((p).param.ival.max) #define ISTEP(p) ((p).param.ival.step) -PluginParam secure_param(void); +PluginParam goom_secure_param(void); -PluginParam secure_f_param(char *name); -PluginParam secure_i_param(char *name); -PluginParam secure_b_param(char *name, int value); -PluginParam secure_s_param(char *name); +PluginParam goom_secure_f_param(char *name); +PluginParam goom_secure_i_param(char *name); +PluginParam goom_secure_b_param(char *name, int value); +PluginParam goom_secure_s_param(char *name); -PluginParam secure_f_feedback(char *name); -PluginParam secure_i_feedback(char *name); +PluginParam goom_secure_f_feedback(char *name); +PluginParam goom_secure_i_feedback(char *name); -void set_str_param_value(PluginParam *p, const char *str); -void set_list_param_value(PluginParam *p, const char *str); +void goom_set_str_param_value(PluginParam *p, const char *str); +void goom_set_list_param_value(PluginParam *p, const char *str); typedef struct _PARAMETERS { char *name; @@ -99,6 +99,17 @@ typedef struct _PARAMETERS { PluginParam **params; } PluginParameters; -PluginParameters plugin_parameters(const char *name, int nb); +PluginParameters goom_plugin_parameters(const char *name, int nb); + +#define secure_param goom_secure_param +#define secure_f_param goom_secure_f_param +#define secure_i_param goom_secure_i_param +#define secure_b_param goom_secure_b_param +#define secure_s_param goom_secure_s_param +#define secure_f_feedback goom_secure_f_feedback +#define secure_i_feedback goom_secure_i_feedback +#define set_list_param_value goom_set_list_param_value +#define set_str_param_value goom_set_str_param_value +#define plugin_parameters goom_plugin_parameters #endif diff --git a/src/post/goom/goom_core.c b/src/post/goom/goom_core.c index b933dd742..10fe968a6 100644 --- a/src/post/goom/goom_core.c +++ b/src/post/goom/goom_core.c @@ -24,7 +24,7 @@ #include "sound_tester.h" #include "goom_plugin_info.h" #include "goom_fx.h" -#include "goom_script.h" +#include "goomsl.h" /* #define VERBOSE */ @@ -101,7 +101,7 @@ PluginInfo *goom_init (guint32 resx, guint32 resy) gfont_load (); - goom_set_main_script(goomInfo, goomInfo->main_script_str); + /* goom_set_main_script(goomInfo, goomInfo->main_script_str); */ return goomInfo; } @@ -152,7 +152,7 @@ guint32 *goom_update (PluginInfo *goomInfo, gint16 data[2][512], /* ! etude du signal ... */ evaluate_sound (data, &(goomInfo->sound)); - goom_execute_main_script(goomInfo); + /* goom_execute_main_script(goomInfo); */ /* ! calcul du deplacement des petits points ... */ largfactor = goomInfo->sound.speedvar / 150.0f + goomInfo->sound.volume / 1.5f; diff --git a/src/post/goom/goom_plugin_info.h b/src/post/goom/goom_plugin_info.h index 1ec562e39..b587c0c65 100644 --- a/src/post/goom/goom_plugin_info.h +++ b/src/post/goom/goom_plugin_info.h @@ -10,7 +10,7 @@ #include "goom_visual_fx.h" #include "goom_filters.h" #include "goom_tools.h" -#include "goom_script_scanner.h" +#include "goomsl.h" typedef struct { char drawIFS; @@ -163,8 +163,8 @@ struct _PLUGIN_INFO { GoomRandom *gRandom; - GoomScriptScanner *scanner; - GoomScriptScanner *main_scanner; + GoomSL *scanner; + GoomSL *main_scanner; const char *main_script_str; }; diff --git a/src/post/goom/goom_script.c b/src/post/goom/goom_script.c deleted file mode 100644 index 5645d583e..000000000 --- a/src/post/goom/goom_script.c +++ /dev/null @@ -1,107 +0,0 @@ -#include "goom_script.h" -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -static PluginParameters *getBaseForVariable (PluginInfo *pluginInfo, const char *name) { - - int i; - if (name == NULL) { - printf("ERROR: No variable container name specified\n"); - return NULL; - } - - /* TODO: using an hashmap */ - for (i=0;i<pluginInfo->nbParams;i++) { - if (!strcmp(name, pluginInfo->params[i].name)) { - return &(pluginInfo->params[i]); - } - } - - printf ("ERROR: No such variable container: %s\n", name); - return NULL; -} - -static PluginParam *getParamForVariable(PluginParameters *params, const char *name) { - - int i; - if (name == NULL) - return NULL; - - for (i=0;i<params->nbParams;i++) { - if (params->params[i] && (!strcmp(name, params->params[i]->name))) { - return params->params[i]; - } - } - printf ("ERROR: No such variable into %s: %s\n", params->name, name); - return NULL; -} - -PluginParam *goom_script_get_param(PluginInfo *pluginInfo, const char *name) { - - int i; - char *base; - char *var; - int len = strlen(name); - int hasDot = 0; - PluginParameters *pparams; - - if (name == NULL) - return NULL; - if (pluginInfo == NULL) { - printf("ERROR: programming %s on line %d\n", __FILE__, __LINE__); - return NULL; - } - - base = (char*)calloc(len+1,1); - var = (char*)calloc(len+1,1); - - for (i=0;i<len;i++) { - - char c = name[i]; - if (c == '_') { - c=' '; - } - if (c == '.') { - if (i==0) - return NULL; - hasDot = i; - } - else if (hasDot) - var[i-hasDot-1] = c; - else - base[i] = c; - } - if ((hasDot==0)||(var[0]==0)||(base[0]==0)) - return NULL; - - pparams = getBaseForVariable(pluginInfo,base); - if (pparams==NULL) - return NULL; - return getParamForVariable(pparams, var); -} - -void goom_execute_script(PluginInfo *pluginInfo, const char *cmds) { - - goom_script_scanner_compile(pluginInfo->scanner, pluginInfo, cmds); - goom_script_scanner_execute(pluginInfo->scanner); -} - -/* set a script that will be executed every loop */ -void goom_set_main_script(PluginInfo *pluginInfo, const char *script) { - - pluginInfo->main_script_str = script; - goom_script_scanner_compile(pluginInfo->main_scanner, pluginInfo, script); -} - -void goom_execute_main_script(PluginInfo *pluginInfo) { - - goom_script_scanner_execute(pluginInfo->main_scanner); -} - -/* return a script containing the current goom state */ -char *goom_create_state_script(PluginInfo *pluginInfo) { - printf("not implemented\n"); - return NULL; -} - diff --git a/src/post/goom/goom_script.h b/src/post/goom/goom_script.h deleted file mode 100644 index ca1cb5665..000000000 --- a/src/post/goom/goom_script.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _GOOM_SCRIPT_H -#define _GOOM_SCRIPT_H - -#include "goom_plugin_info.h" - -void goom_execute_script(PluginInfo *pluginInfo, const char *cmds); - -/* set a script that will be executed every loop */ -void goom_set_main_script(PluginInfo *pluginInfo, const char *script); -void goom_execute_main_script(PluginInfo *pluginInfo); - - /* return a script containing the current goom state */ -char *goom_create_state_script(PluginInfo *pluginInfo); - -PluginParam *goom_script_get_param(PluginInfo *pluginInfo, const char *name); - -#endif /* _GOOM_SCRIPT_H */ diff --git a/src/post/goom/goom_script_lex.c b/src/post/goom/goom_script_lex.c deleted file mode 100644 index f50882d29..000000000 --- a/src/post/goom/goom_script_lex.c +++ /dev/null @@ -1,2494 +0,0 @@ - -#line 3 "lex.yy.c" - -#define YY_INT_ALIGNED short int - -/* A lexical scanner generated by flex */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 -#define YY_FLEX_SUBMINOR_VERSION 31 -#if YY_FLEX_SUBMINOR_VERSION > 0 -#define FLEX_BETA -#endif - -/* First, we deal with platform-specific or compiler-specific issues. */ - -/* begin standard C headers. */ -#include <stdio.h> -#include <string.h> -#include <errno.h> -#include <stdlib.h> - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */ - -#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L -#include <inttypes.h> -typedef int8_t flex_int8_t; -typedef uint8_t flex_uint8_t; -typedef int16_t flex_int16_t; -typedef uint16_t flex_uint16_t; -typedef int32_t flex_int32_t; -typedef uint32_t flex_uint32_t; -#else -typedef signed char flex_int8_t; -typedef short int flex_int16_t; -typedef int flex_int32_t; -typedef unsigned char flex_uint8_t; -typedef unsigned short int flex_uint16_t; -typedef unsigned int flex_uint32_t; -#endif /* ! C99 */ - -/* Limits of integral types. */ -#ifndef INT8_MIN -#define INT8_MIN (-128) -#endif -#ifndef INT16_MIN -#define INT16_MIN (-32767-1) -#endif -#ifndef INT32_MIN -#define INT32_MIN (-2147483647-1) -#endif -#ifndef INT8_MAX -#define INT8_MAX (127) -#endif -#ifndef INT16_MAX -#define INT16_MAX (32767) -#endif -#ifndef INT32_MAX -#define INT32_MAX (2147483647) -#endif -#ifndef UINT8_MAX -#define UINT8_MAX (255U) -#endif -#ifndef UINT16_MAX -#define UINT16_MAX (65535U) -#endif -#ifndef UINT32_MAX -#define UINT32_MAX (4294967295U) -#endif - -#endif /* ! FLEXINT_H */ - -#ifdef __cplusplus - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN (yy_start) = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START (((yy_start) - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart(yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#ifndef YY_BUF_SIZE -#define YY_BUF_SIZE 16384 -#endif - -#ifndef YY_TYPEDEF_YY_BUFFER_STATE -#define YY_TYPEDEF_YY_BUFFER_STATE -typedef struct yy_buffer_state *YY_BUFFER_STATE; -#endif - -extern int yyleng; - -extern FILE *yyin, *yyout; - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - - #define YY_LESS_LINENO(n) - -/* Return all but the first "n" matched characters back to the input stream. */ -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - *yy_cp = (yy_hold_char); \ - YY_RESTORE_YY_MORE_OFFSET \ - (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, (yytext_ptr) ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ - -#ifndef YY_TYPEDEF_YY_SIZE_T -#define YY_TYPEDEF_YY_SIZE_T -typedef unsigned int yy_size_t; -#endif - -#ifndef YY_STRUCT_YY_BUFFER_STATE -#define YY_STRUCT_YY_BUFFER_STATE -struct yy_buffer_state - { - FILE *yy_input_file; - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - int yy_bs_lineno; /**< The line count. */ - int yy_bs_column; /**< The column count. */ - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; - -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - - }; -#endif /* !YY_STRUCT_YY_BUFFER_STATE */ - -/* Stack of input buffers. */ -static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ -static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ -static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - * - * Returns the top of the stack, or NULL. - */ -#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ - ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ - : NULL) - -/* Same as previous macro, but useful when we know that the buffer stack is not - * NULL or when we need an lvalue. For internal use only. - */ -#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] - -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; -static int yy_n_chars; /* number of characters read into yy_ch_buf */ -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart (FILE *input_file ); -void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); -YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); -void yy_delete_buffer (YY_BUFFER_STATE b ); -void yy_flush_buffer (YY_BUFFER_STATE b ); -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); -void yypop_buffer_state (void ); - -static void yyensure_buffer_stack (void ); -static void yy_load_buffer_state (void ); -static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); - -#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) - -YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); -YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); -YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); - -void *yyalloc (yy_size_t ); -void *yyrealloc (void *,yy_size_t ); -void yyfree (void * ); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! YY_CURRENT_BUFFER ){ \ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! YY_CURRENT_BUFFER ){\ - yyensure_buffer_stack (); \ - YY_CURRENT_BUFFER_LVALUE = \ - yy_create_buffer(yyin,YY_BUF_SIZE ); \ - } \ - YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) - -/* Begin user sect3 */ - -typedef unsigned char YY_CHAR; - -FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; - -typedef int yy_state_type; - -extern int yylineno; - -int yylineno = 1; - -extern char *yytext; -#define yytext_ptr yytext - -static yy_state_type yy_get_previous_state (void ); -static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); -static int yy_get_next_buffer (void ); -static void yy_fatal_error (yyconst char msg[] ); - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - (yytext_ptr) = yy_bp; \ - yyleng = (size_t) (yy_cp - yy_bp); \ - (yy_hold_char) = *yy_cp; \ - *yy_cp = '\0'; \ - (yy_c_buf_p) = yy_cp; - -#define YY_NUM_RULES 15 -#define YY_END_OF_BUFFER 16 -/* This struct is not used in this scanner, - but its presence is necessary. */ -struct yy_trans_info - { - flex_int32_t yy_verify; - flex_int32_t yy_nxt; - }; -static yyconst flex_int16_t yy_accept[36] = - { 0, - 0, 0, 0, 0, 16, 14, 13, 1, 14, 14, - 10, 9, 9, 9, 3, 3, 13, 10, 7, 4, - 12, 11, 0, 9, 9, 9, 2, 11, 8, 9, - 6, 8, 9, 5, 0 - } ; - -static yyconst flex_int32_t yy_ec[256] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, - 1, 5, 1, 1, 6, 7, 8, 9, 9, 9, - 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, - 1, 10, 1, 1, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 1, 1, 1, 1, 11, 1, 12, 11, 11, 11, - - 11, 13, 11, 11, 14, 11, 11, 15, 11, 16, - 17, 11, 11, 11, 11, 18, 11, 11, 11, 11, - 11, 11, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1 - } ; - -static yyconst flex_int32_t yy_meta[19] = - { 0, - 1, 1, 1, 1, 1, 1, 2, 1, 3, 1, - 4, 4, 4, 4, 4, 4, 4, 4 - } ; - -static yyconst flex_int16_t yy_base[40] = - { 0, - 0, 0, 16, 17, 59, 60, 56, 60, 14, 52, - 21, 49, 19, 20, 60, 47, 52, 0, 60, 60, - 60, 44, 0, 45, 22, 24, 60, 32, 0, 25, - 33, 0, 20, 17, 60, 42, 45, 29, 47 - } ; - -static yyconst flex_int16_t yy_def[40] = - { 0, - 35, 1, 36, 36, 35, 35, 35, 35, 35, 35, - 35, 37, 37, 37, 35, 35, 35, 11, 35, 35, - 35, 35, 38, 37, 37, 37, 35, 35, 39, 37, - 37, 39, 26, 26, 0, 35, 35, 35, 35 - } ; - -static yyconst flex_int16_t yy_nxt[79] = - { 0, - 6, 7, 8, 6, 6, 9, 6, 10, 11, 6, - 12, 12, 13, 14, 12, 12, 12, 12, 8, 8, - 16, 16, 18, 19, 21, 23, 23, 22, 23, 18, - 23, 23, 29, 25, 24, 26, 33, 34, 30, 23, - 28, 31, 15, 15, 15, 15, 24, 24, 24, 32, - 32, 23, 28, 17, 27, 23, 20, 17, 35, 5, - 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, - 35, 35, 35, 35, 35, 35, 35, 35 - } ; - -static yyconst flex_int16_t yy_chk[79] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 3, 4, - 3, 4, 9, 9, 11, 13, 14, 11, 25, 11, - 26, 30, 38, 13, 34, 14, 30, 33, 25, 31, - 28, 26, 36, 36, 36, 36, 37, 37, 37, 39, - 39, 24, 22, 17, 16, 12, 10, 7, 5, 35, - 35, 35, 35, 35, 35, 35, 35, 35, 35, 35, - 35, 35, 35, 35, 35, 35, 35, 35 - } ; - -static yy_state_type yy_last_accepting_state; -static char *yy_last_accepting_cpos; - -extern int yy_flex_debug; -int yy_flex_debug = 0; - -/* The intent behind this definition is that it'll catch - * any uses of REJECT which flex missed. - */ -#define REJECT reject_used_but_not_detected -#define yymore() yymore_used_but_not_detected -#define YY_MORE_ADJ 0 -#define YY_RESTORE_YY_MORE_OFFSET -char *yytext; -#line 1 "goom_script_lex.l" -#line 2 "goom_script_lex.l" - -#include <math.h> -#include <stdlib.h> -#include <string.h> -#include "goom_script_scanner.h" -#include "goom_script_yacc.h" -void yyerror(char *); -void yyparse(); - -/* #define TRACE_SCRIPT */ - -#define INSTR_SETI_PARAM_INTEGER 1 -#define INSTR_SETI_VAR_INTEGER 2 -#define INSTR_SETI_VAR_VAR 3 -#define INSTR_SETI_VAR_PARAM 4 -#define INSTR_SETI_PARAM_VAR 5 -/* #define INSTR_JUMP 6 */ -#define INSTR_NOP 7 -#define INSTR_SETF_PARAM_FLOAT 8 -#define INSTR_SETF_VAR_FLOAT 9 -#define INSTR_SETF_VAR_VAR 10 -#define INSTR_SETF_VAR_PARAM 11 -#define INSTR_SETF_PARAM_VAR 12 -#define INSTR_ISLOWERF_VAR_VAR 13 -#define INSTR_ISLOWERF_VAR_FLOAT 14 -#define INSTR_ISLOWERI_VAR_VAR 15 -#define INSTR_ISLOWERI_VAR_INTEGER 16 -#define INSTR_ADDI_VAR_INTEGER 17 -#define INSTR_ADDF_VAR_FLOAT 18 -#define INSTR_ADDI_VAR_VAR 19 -#define INSTR_ADDF_VAR_VAR 20 -#define INSTR_MULI_VAR_INTEGER 21 -#define INSTR_MULF_VAR_FLOAT 22 -#define INSTR_MULI_VAR_VAR 23 -#define INSTR_MULF_VAR_VAR 24 -#define INSTR_ISEQUALF_VAR_VAR 25 -#define INSTR_ISEQUALF_VAR_FLOAT 26 -#define INSTR_ISEQUALI_VAR_VAR 27 -#define INSTR_ISEQUALI_VAR_INTEGER 28 -/* #define INSTR_JZERO 29 */ -#define INSTR_DIVF_VAR_FLOAT 30 -#define INSTR_DIVF_VAR_VAR 31 -#define INSTR_SUBF_VAR_FLOAT 32 -#define INSTR_SUBF_VAR_VAR 33 -/* #define INSTR_CALL 34 */ -/* #define INSTR_RET 35 */ - -#define VALIDATE_OK "ok" -#define VALIDATE_ERROR "error while validating" -#define VALIDATE_TODO "todo" -#define VALIDATE_SYNTHAX_ERROR "synthax error" -#define VALIDATE_NO_SUCH_INT "no such integer variable" -#define VALIDATE_NO_SUCH_PARAM "no such param" -#define VALIDATE_NO_SUCH_VAR "no such variable" -#define VALIDATE_NO_SUCH_DEST_VAR "no such destination variable" -#define VALIDATE_NO_SUCH_SRC_VAR "no such src variable" - -#include "goom_script.h" - - /* ------------- SCRIPT_EXEC_ENV ------------ */ - - /* Instruction *instr_init(GoomScriptScanner *parent, const char *name, int id, int nb_param); */ - static void instr_free(Instruction *_this); - /* void instr_add_param(Instruction *_this, char *param, int type); */ - static const char *instr_validate(Instruction *_this); - /* void instr_display(Instruction *_this); */ - - /* ----------- INSTRUCTION_FLOW ------------- */ - - static InstructionFlow *iflow_new(void); - static void iflow_add_instr(InstructionFlow *_this, Instruction *instr); - static void iflow_clean(InstructionFlow *_this); - static void iflow_execute(InstructionFlow *_this, ScriptExecEnv *exec_env); - - /* ----------- IMPLEMENTATIONS --------------- */ - - void iflow_clean(InstructionFlow *_this) { - /* TODO: clean chaque instruction du flot */ - _this->number = 0; - goom_hash_free(_this->labels); - _this->labels = goom_hash_new(); - } - - InstructionFlow *iflow_new(void) { - - InstructionFlow *_this = (InstructionFlow*)malloc(sizeof(InstructionFlow)); - _this->number = 0; - _this->tabsize = 6; - _this->instr = (Instruction**)malloc(_this->tabsize * sizeof(Instruction*)); - _this->labels = goom_hash_new(); - - return _this; - } - - void iflow_add_instr(InstructionFlow *_this, Instruction *instr) { - - if (_this->number == _this->tabsize) { - _this->tabsize *= 2; - _this->instr = (Instruction**)realloc(_this->instr, _this->tabsize * sizeof(Instruction*)); - } - _this->instr[_this->number] = instr; - instr->address = _this->number; - _this->number++; - } - - /** - * instr_add_param - */ - void instr_add_param(Instruction *instr, char *param, int type) { - - int len; - if (instr==NULL) - return; - if (instr->cur_param==0) - return; - --instr->cur_param; - len = strlen(param); - instr->params[instr->cur_param] = (char*)malloc(len+1); - strcpy(instr->params[instr->cur_param], param); - instr->types[instr->cur_param] = type; - if (instr->cur_param == 0) { - - const char *result = instr_validate(instr); - if (result != VALIDATE_OK) { - printf("ERROR LINE %d: ", instr->parent->num_lines + 1); - instr_display(instr); - printf("... %s\n", result); - instr->parent->compilationOK = 0; - } - - if (instr->id != INSTR_NOP) - iflow_add_instr(instr->parent->current_flow, instr); - else - instr_free(instr); - } - } - - /** - * instr_init - */ - Instruction *instr_init(GoomScriptScanner *parent, const char *name, int id, int nb_param) { - - Instruction *instr = (Instruction*)malloc(sizeof(Instruction)); - instr->params = (char**)malloc(nb_param*sizeof(char*)); - instr->types = (int*)malloc(nb_param*sizeof(int)); - instr->cur_param = instr->nb_param = nb_param; - instr->parent = parent; - instr->id = id; - instr->name = name; - instr->jump_label = NULL; - return instr; - } - - void instr_free(Instruction *_this) { - - int i; - free(_this->types); - for (i=_this->cur_param; i<_this->nb_param; ++i) - free(_this->params[i]); - free(_this->params); - free(_this); - } - - void instr_display(Instruction *_this) { - int i=_this->nb_param-1; - printf("%s", _this->name); - while(i>=_this->cur_param) { - printf(" %s", _this->params[i]); - --i; - } - } - - /** VALIDATE **/ - - static const char *validate_v_v(Instruction *_this) { - - _this->data.v_v.var_dest = goom_hash_get(_this->parent->vars, _this->params[1]); - _this->data.v_v.var_src = goom_hash_get(_this->parent->vars, _this->params[0]); - - if (_this->data.v_v.var_dest == NULL) { - return VALIDATE_NO_SUCH_DEST_VAR; - } - if (_this->data.v_v.var_src == NULL) { - return VALIDATE_NO_SUCH_SRC_VAR; - } - return VALIDATE_OK; - } - - static const char *validate_v_i(Instruction *_this) { - - _this->data.v_i.var = goom_hash_get(_this->parent->vars, _this->params[1]); - _this->data.v_i.value = atoi(_this->params[0]); - - if (_this->data.v_i.var == NULL) { - return VALIDATE_NO_SUCH_INT; - } - return VALIDATE_OK; - } - - static const char *validate_v_p(Instruction *_this) { - _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[1]); - _this->data.p_i.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[0]); - if (_this->data.p_i.param == NULL) - return VALIDATE_NO_SUCH_PARAM; - if (_this->data.p_i.param->type != PARAM_INTVAL) - return VALIDATE_ERROR; - if (_this->data.v_i.var == NULL) { - return VALIDATE_NO_SUCH_INT; - } - return VALIDATE_OK; - } - - static const char *validate_p_v(Instruction *_this) { - _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[0]); - _this->data.v_p.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); - if (_this->data.v_p.param == NULL) - return VALIDATE_NO_SUCH_PARAM; - if (_this->data.v_p.param->type != PARAM_INTVAL) - return VALIDATE_ERROR; - if (_this->data.v_p.var == NULL) { - return VALIDATE_NO_SUCH_INT; - } - return VALIDATE_OK; - } - - static const char *validate_p_i(Instruction *_this) { - _this->data.p_i.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); - _this->data.p_i.value = atoi(_this->params[0]); - if (_this->data.p_i.param == NULL) - return VALIDATE_NO_SUCH_PARAM; - if (_this->data.p_i.param->type == PARAM_INTVAL) - return VALIDATE_OK; - return VALIDATE_ERROR; - } - - /***/ - - static const char *validate_v_f(Instruction *_this) { - - _this->data.v_f.var = goom_hash_get(_this->parent->vars, _this->params[1]); - _this->data.v_f.value = atof(_this->params[0]); - - if (_this->data.v_f.var == NULL) { - return VALIDATE_NO_SUCH_VAR; - } - return VALIDATE_OK; - } - - static const char *validate_v_pf(Instruction *_this) { - - _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[1]); - _this->data.v_p.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[0]); - if (_this->data.v_p.param == NULL) - return VALIDATE_NO_SUCH_VAR; - if (_this->data.v_p.param->type != PARAM_FLOATVAL) - return VALIDATE_ERROR; - if (_this->data.v_p.var == NULL) { - return VALIDATE_NO_SUCH_VAR; - } - return VALIDATE_OK; - } - - static const char *validate_pf_v(Instruction *_this) { - - _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[0]); - _this->data.v_p.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); - if (_this->data.v_p.param == NULL) - return VALIDATE_NO_SUCH_VAR; - if (_this->data.v_p.param->type != PARAM_FLOATVAL) - return VALIDATE_ERROR; - if (_this->data.v_p.var == NULL) { - return VALIDATE_NO_SUCH_VAR; - } - return VALIDATE_OK; - } - - static const char *validate_p_f(Instruction *_this) { - _this->data.p_f.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); - _this->data.p_f.value = atof(_this->params[0]); - if (_this->data.p_f.param == NULL) - return VALIDATE_NO_SUCH_VAR; - if (_this->data.p_f.param->type == PARAM_FLOATVAL) - return VALIDATE_OK; - return VALIDATE_ERROR; - } - - static const char *validate_i(Instruction *_this, int v_i_id, int v_v_id) { - - if ((_this->types[0] == TYPE_INTEGER) && (_this->types[1] == TYPE_VAR)) { - _this->id = v_i_id; - return validate_v_i(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { - _this->id = v_v_id; - return validate_v_v(_this); - } - return VALIDATE_ERROR; - } - - static const char *validate_f(Instruction *_this, int v_f_id, int v_v_id) { - - if ((_this->types[0] == TYPE_FLOAT) && (_this->types[1] == TYPE_VAR)) { - _this->id = v_f_id; - return validate_v_f(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { - _this->id = v_v_id; - return validate_v_v(_this); - } - return VALIDATE_ERROR; - } - - /** - * instr_validate - */ - const char *instr_validate(Instruction *_this) { - - switch (_this->id) { - - /* set.i */ - case INSTR_SETI: - - if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_INTEGER)) { - _this->id = INSTR_SETI_PARAM_INTEGER; - return validate_p_i(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_INTEGER)) { - _this->id = INSTR_SETI_VAR_INTEGER; - return validate_v_i(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { - _this->id = INSTR_SETI_VAR_VAR; - return validate_v_v(_this); - } - else if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_VAR)) { - _this->id = INSTR_SETI_PARAM_VAR; - return validate_p_v(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_PARAM)) { - _this->id = INSTR_SETI_VAR_PARAM; - return validate_v_p(_this); - } - else { - return VALIDATE_TODO; - } - return VALIDATE_SYNTHAX_ERROR; - - /* set.f */ - case INSTR_SETF: - - if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_FLOAT)) { - _this->id = INSTR_SETF_PARAM_FLOAT; - return validate_p_f(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_FLOAT)) { - _this->id = INSTR_SETF_VAR_FLOAT; - return validate_v_f(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { - _this->id = INSTR_SETF_VAR_VAR; - return validate_v_v(_this); - } - else if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_VAR)) { - _this->id = INSTR_SETF_PARAM_VAR; - return validate_pf_v(_this); - } - else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_PARAM)) { - _this->id = INSTR_SETF_VAR_PARAM; - return validate_v_pf(_this); - } - else { - return VALIDATE_TODO; - } - return VALIDATE_SYNTHAX_ERROR; - - /* int */ - case INSTR_INT: - - if (_this->types[0] == TYPE_VAR) { - _this->id = INSTR_NOP; - goom_hash_put_int(_this->parent->vars, _this->params[0], 0); - return VALIDATE_OK; - } - return VALIDATE_SYNTHAX_ERROR; - - /* call */ - case INSTR_CALL: - if (_this->types[0] == TYPE_LABEL) { - _this->jump_label = _this->params[0]; - return VALIDATE_OK; - } - return VALIDATE_ERROR; - - /* ret */ - case INSTR_RET: - return VALIDATE_OK; - - /* jump */ - case INSTR_JUMP: - - if (_this->types[0] == TYPE_LABEL) { - _this->jump_label = _this->params[0]; - return VALIDATE_OK; - } - return VALIDATE_ERROR; - - /* jzero */ - case INSTR_JZERO: - - if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_LABEL)) { - _this->jump_label = _this->params[0]; - _this->data.v.var = goom_hash_get(_this->parent->vars, _this->params[1]); - if (_this->data.v.var == NULL) return VALIDATE_NO_SUCH_VAR; - return VALIDATE_OK; - } - return VALIDATE_ERROR; - - /* label */ - case INSTR_LABEL: - - if (_this->types[0] == TYPE_LABEL) { - _this->id = INSTR_NOP; - goom_hash_put_int(_this->parent->current_flow->labels, _this->params[0], _this->parent->current_flow->number); - return VALIDATE_OK; - } - return VALIDATE_ERROR; - - /* isequal.i */ - case INSTR_ISEQUALI: - return validate_i(_this, INSTR_ISEQUALI_VAR_INTEGER, INSTR_ISEQUALI_VAR_VAR); - - /* isequal.f */ - case INSTR_ISEQUALF: - return validate_f(_this, INSTR_ISEQUALF_VAR_FLOAT, INSTR_ISEQUALF_VAR_VAR); - - /* islower.i */ - case INSTR_ISLOWERI: - return validate_i(_this, INSTR_ISLOWERI_VAR_INTEGER, INSTR_ISLOWERI_VAR_VAR); - - /* islower.f */ - case INSTR_ISLOWERF: - return validate_f(_this, INSTR_ISLOWERF_VAR_FLOAT, INSTR_ISLOWERF_VAR_VAR); - - /* add.i */ - case INSTR_ADDI: - return validate_i(_this, INSTR_ADDI_VAR_INTEGER, INSTR_ADDI_VAR_VAR); - - /* add.f */ - case INSTR_ADDF: - return validate_f(_this, INSTR_ADDF_VAR_FLOAT, INSTR_ADDF_VAR_VAR); - - /* mul.i */ - case INSTR_MULI: - return validate_i(_this, INSTR_MULI_VAR_INTEGER, INSTR_MULI_VAR_VAR); - - /* mul.f */ - case INSTR_MULF: - return validate_f(_this, INSTR_MULF_VAR_FLOAT, INSTR_MULF_VAR_VAR); - - /* sub.f */ - case INSTR_SUBF: - return validate_f(_this, INSTR_SUBF_VAR_FLOAT, INSTR_SUBF_VAR_VAR); - - /* div.f */ - case INSTR_DIVF: - return validate_f(_this, INSTR_DIVF_VAR_FLOAT, INSTR_DIVF_VAR_VAR); - - default: - return VALIDATE_TODO; - } - return VALIDATE_ERROR; - } - - /** EXECUTE **/ - - void iflow_execute(InstructionFlow *_this, ScriptExecEnv *exec_env) { - - int ip = 0; - int stack[512]; - int stack_pointer = 0; - - stack[stack_pointer++] = _this->number + 1; - - while (ip < _this->number) { - Instruction *instr = _this->instr[ip]; -#ifdef TRACE_SCRIPT - printf("execute "); instr_display(instr); printf("\n"); -#endif - - switch (instr->id) { - - /* SET.I */ - case INSTR_SETI_PARAM_INTEGER: - IVAL(*instr->data.p_i.param) = instr->data.p_i.value; - instr->data.p_i.param->change_listener(instr->data.p_i.param); - ++ip; break; - - case INSTR_SETI_VAR_VAR: - *instr->data.v_v.var_dest = *instr->data.v_v.var_src; - ++ip; break; - - case INSTR_SETI_PARAM_VAR: - IVAL(*instr->data.v_p.param) = instr->data.v_p.var->i; - instr->data.v_p.param->change_listener(instr->data.v_p.param); - ++ip; break; - - case INSTR_SETI_VAR_PARAM: - instr->data.v_p.var->i = IVAL(*instr->data.v_p.param); - ++ip; break; - - case INSTR_SETI_VAR_INTEGER: - instr->data.v_i.var->i = instr->data.v_i.value; - ++ip; break; - - /* SET.F */ - case INSTR_SETF_PARAM_FLOAT: - FVAL(*instr->data.p_i.param) = instr->data.p_f.value; - instr->data.p_f.param->change_listener(instr->data.p_f.param); - ++ip; break; - - case INSTR_SETF_VAR_VAR: - *instr->data.v_v.var_dest = *instr->data.v_v.var_src; - ++ip; break; - - case INSTR_SETF_PARAM_VAR: - FVAL(*instr->data.v_p.param) = instr->data.v_p.var->f; - instr->data.v_p.param->change_listener(instr->data.v_p.param); - ++ip; break; - - case INSTR_SETF_VAR_PARAM: - instr->data.v_p.var->f = FVAL(*instr->data.v_p.param); - ++ip; break; - - case INSTR_SETF_VAR_FLOAT: - instr->data.v_f.var->f = instr->data.v_f.value; - ++ip; break; - - /* JUMP */ - case INSTR_JUMP: - ip += instr->data.jump_offset; break; - - /* JZERO */ - case INSTR_JZERO: - ip += (instr->data.v.var->i ? 1 : instr->data.jump_offset); break; - - case INSTR_NOP: - ++ip; break; - - /* ISEQUAL.I */ - case INSTR_ISEQUALI_VAR_VAR: - instr->data.v_v.var_dest->i -= instr->data.v_v.var_src->i; - ++ip; break; - - case INSTR_ISEQUALI_VAR_INTEGER: - instr->data.v_i.var->i -= instr->data.v_i.value; - ++ip; break; - - /* ISEQUAL.F */ - case INSTR_ISEQUALF_VAR_VAR: - instr->data.v_v.var_dest->f -= instr->data.v_v.var_src->f; - ++ip; break; - - case INSTR_ISEQUALF_VAR_FLOAT: - instr->data.v_f.var->f -= instr->data.v_f.value; - ++ip; break; - - /* ISLOWER.I */ - case INSTR_ISLOWERI_VAR_VAR: - instr->data.v_v.var_dest->i = (instr->data.v_v.var_dest->i < instr->data.v_v.var_src->i); - ++ip; break; - - case INSTR_ISLOWERI_VAR_INTEGER: - instr->data.v_i.var->i = (instr->data.v_i.var->i < instr->data.v_i.value); - ++ip; break; - - /* ISLOWER.F */ - case INSTR_ISLOWERF_VAR_VAR: - instr->data.v_v.var_dest->f = (instr->data.v_v.var_dest->f < instr->data.v_v.var_src->f); - ++ip; break; - - case INSTR_ISLOWERF_VAR_FLOAT: - instr->data.v_f.var->f = (instr->data.v_f.var->f < instr->data.v_f.value); - ++ip; break; - - /* ADD.I */ - case INSTR_ADDI_VAR_VAR: - instr->data.v_v.var_dest->i += instr->data.v_v.var_src->i; - ++ip; break; - - case INSTR_ADDI_VAR_INTEGER: - instr->data.v_i.var->i += instr->data.v_i.value; - ++ip; break; - - /* ADD.F */ - case INSTR_ADDF_VAR_VAR: - instr->data.v_v.var_dest->f += instr->data.v_v.var_src->f; - ++ip; break; - - case INSTR_ADDF_VAR_FLOAT: - instr->data.v_f.var->f += instr->data.v_f.value; - ++ip; break; - - /* MUL.I */ - case INSTR_MULI_VAR_VAR: - instr->data.v_v.var_dest->i *= instr->data.v_v.var_src->i; - ++ip; break; - - case INSTR_MULI_VAR_INTEGER: - instr->data.v_i.var->i *= instr->data.v_i.value; - ++ip; break; - - /* MUL.F */ - case INSTR_MULF_VAR_FLOAT: - instr->data.v_f.var->f *= instr->data.v_f.value; - ++ip; break; - - case INSTR_MULF_VAR_VAR: - instr->data.v_v.var_dest->f *= instr->data.v_v.var_src->f; - ++ip; break; - - /* DIV.F */ - case INSTR_DIVF_VAR_FLOAT: - instr->data.v_f.var->f /= instr->data.v_f.value; - ++ip; break; - - case INSTR_DIVF_VAR_VAR: - instr->data.v_v.var_dest->f /= instr->data.v_v.var_src->f; - ++ip; break; - - /* SUB.F */ - case INSTR_SUBF_VAR_FLOAT: - instr->data.v_f.var->f -= instr->data.v_f.value; - ++ip; break; - - case INSTR_SUBF_VAR_VAR: - instr->data.v_v.var_dest->f -= instr->data.v_v.var_src->f; - ++ip; break; - - /* CALL */ - case INSTR_CALL: - stack[stack_pointer++] = ip + 1; - ip += instr->data.jump_offset; break; - - /* RET */ - case INSTR_RET: - ip = stack[--stack_pointer]; break; - - default: - printf("NOT IMPLEMENTED : %d\n", instr->id); - ++ip; - } - } - } - - GoomScriptScanner *currentScanner; - -#line 1122 "lex.yy.c" - -#define INITIAL 0 -#define COMMENT 1 - -#ifndef YY_NO_UNISTD_H -/* Special case for "unistd.h", since it is non-ANSI. We include it way - * down here because we want the user's section 1 to have been scanned first. - * The user has a chance to override it with an option. - */ -#include <unistd.h> -#endif - -#ifndef YY_EXTRA_TYPE -#define YY_EXTRA_TYPE void * -#endif - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap (void ); -#else -extern int yywrap (void ); -#endif -#endif - - static void yyunput (int c,char *buf_ptr ); - -#ifndef yytext_ptr -static void yy_flex_strncpy (char *,yyconst char *,int ); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * ); -#endif - -#ifndef YY_NO_INPUT - -#ifdef __cplusplus -static int yyinput (void ); -#else -static int input (void ); -#endif - -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ -#ifndef ECHO -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ - if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ - { \ - int c = '*'; \ - size_t n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else \ - { \ - errno=0; \ - while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ - { \ - if( errno != EINTR) \ - { \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - break; \ - } \ - errno=0; \ - clearerr(yyin); \ - } \ - }\ -\ - -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -#endif - -/* end tables serialization structures and prototypes */ - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -#define YY_DECL_IS_OURS 1 - -extern int yylex (void); - -#define YY_DECL int yylex (void) -#endif /* !YY_DECL */ - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -#define YY_RULE_SETUP \ - YY_USER_ACTION - -/** The main scanner function which does all the work. - */ -YY_DECL -{ - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -#line 664 "goom_script_lex.l" - - -#line 1277 "lex.yy.c" - - if ( (yy_init) ) - { - (yy_init) = 0; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! (yy_start) ) - (yy_start) = 1; /* first start state */ - - if ( ! yyin ) - yyin = stdin; - - if ( ! yyout ) - yyout = stdout; - - if ( ! YY_CURRENT_BUFFER ) { - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_load_buffer_state( ); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { - yy_cp = (yy_c_buf_p); - - /* Support of yytext. */ - *yy_cp = (yy_hold_char); - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - - yy_current_state = (yy_start); -yy_match: - do - { - register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 36 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - ++yy_cp; - } - while ( yy_base[yy_current_state] != 60 ); - -yy_find_action: - yy_act = yy_accept[yy_current_state]; - if ( yy_act == 0 ) - { /* have to back up */ - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - yy_act = yy_accept[yy_current_state]; - } - - YY_DO_BEFORE_ACTION; - -do_action: /* This label is used only to access EOF actions. */ - - switch ( yy_act ) - { /* beginning of action switch */ - case 0: /* must back up */ - /* undo the effects of YY_DO_BEFORE_ACTION */ - *yy_cp = (yy_hold_char); - yy_cp = (yy_last_accepting_cpos); - yy_current_state = (yy_last_accepting_state); - goto yy_find_action; - -case 1: -/* rule 1 can match eol */ -YY_RULE_SETUP -#line 666 "goom_script_lex.l" -{ ++currentScanner->num_lines; } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 668 "goom_script_lex.l" -{ BEGIN INITIAL; } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 669 "goom_script_lex.l" -{ /* eat up comment */ } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 671 "goom_script_lex.l" -{ BEGIN COMMENT; } - YY_BREAK -case 5: -YY_RULE_SETUP -#line 673 "goom_script_lex.l" -{ return FLOAT_TK; } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 674 "goom_script_lex.l" -{ return INT_TK; } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 675 "goom_script_lex.l" -{ return ARROW_TK; } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 676 "goom_script_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_PARAM; } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 677 "goom_script_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_VAR; } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 678 "goom_script_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_INTEGER; } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 679 "goom_script_lex.l" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_FLOAT; } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 680 "goom_script_lex.l" -{ sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return TYPE_FLOAT; } - YY_BREAK -case 13: -YY_RULE_SETUP -#line 681 "goom_script_lex.l" -/* eat up whitespace */ - YY_BREAK -case 14: -YY_RULE_SETUP -#line 682 "goom_script_lex.l" -{ yylval.charValue = *yytext; return *yytext; } - YY_BREAK -case 15: -YY_RULE_SETUP -#line 684 "goom_script_lex.l" -ECHO; - YY_BREAK -#line 1436 "lex.yy.c" -case YY_STATE_EOF(INITIAL): -case YY_STATE_EOF(COMMENT): - yyterminate(); - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = (yy_hold_char); - YY_RESTORE_YY_MORE_OFFSET - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between YY_CURRENT_BUFFER and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++(yy_c_buf_p); - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { - yy_cp = (yy_c_buf_p); - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_END_OF_FILE: - { - (yy_did_buffer_switch_on_eof) = 0; - - if ( yywrap( ) ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = - (yytext_ptr) + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - (yy_c_buf_p) = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; - - yy_current_state = yy_get_previous_state( ); - - yy_cp = (yy_c_buf_p); - yy_bp = (yytext_ptr) + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ -} /* end of yylex */ - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ -static int yy_get_next_buffer (void) -{ - register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - register char *source = (yytext_ptr); - register int number_to_move, i; - int ret_val; - - if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; - - else - { - size_t num_to_read = - YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = YY_CURRENT_BUFFER; - - int yy_c_buf_p_offset = - (int) ((yy_c_buf_p) - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - - number_to_move - 1; - - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), - (yy_n_chars), num_to_read ); - - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - if ( (yy_n_chars) == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart(yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - (yy_n_chars) += number_to_move; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; - YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; - - (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; - - return ret_val; -} - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - - static yy_state_type yy_get_previous_state (void) -{ - register yy_state_type yy_current_state; - register char *yy_cp; - - yy_current_state = (yy_start); - - for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) - { - register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 36 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - } - - return yy_current_state; -} - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) -{ - register int yy_is_jam; - register char *yy_cp = (yy_c_buf_p); - - register YY_CHAR yy_c = 1; - if ( yy_accept[yy_current_state] ) - { - (yy_last_accepting_state) = yy_current_state; - (yy_last_accepting_cpos) = yy_cp; - } - while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) - { - yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 36 ) - yy_c = yy_meta[(unsigned int) yy_c]; - } - yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 35); - - return yy_is_jam ? 0 : yy_current_state; -} - - static void yyunput (int c, register char * yy_bp ) -{ - register char *yy_cp; - - yy_cp = (yy_c_buf_p); - - /* undo effects of setting up yytext */ - *yy_cp = (yy_hold_char); - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = (yy_n_chars) + 2; - register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ - YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; - register char *source = - &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; - - while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; - - if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - - (yytext_ptr) = yy_bp; - (yy_hold_char) = *yy_cp; - (yy_c_buf_p) = yy_cp; -} - -#ifndef YY_NO_INPUT -#ifdef __cplusplus - static int yyinput (void) -#else - static int input (void) -#endif - -{ - int c; - - *(yy_c_buf_p) = (yy_hold_char); - - if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) - /* This was really a NUL. */ - *(yy_c_buf_p) = '\0'; - - else - { /* need more input */ - int offset = (yy_c_buf_p) - (yytext_ptr); - ++(yy_c_buf_p); - - switch ( yy_get_next_buffer( ) ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart(yyin ); - - /*FALLTHROUGH*/ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap( ) ) - return EOF; - - if ( ! (yy_did_buffer_switch_on_eof) ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - (yy_c_buf_p) = (yytext_ptr) + offset; - break; - } - } - } - - c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ - *(yy_c_buf_p) = '\0'; /* preserve yytext */ - (yy_hold_char) = *++(yy_c_buf_p); - - return c; -} -#endif /* ifndef YY_NO_INPUT */ - -/** Immediately switch to a different input stream. - * @param input_file A readable stream. - * - * @note This function does not reset the start condition to @c INITIAL . - */ - void yyrestart (FILE * input_file ) -{ - - if ( ! YY_CURRENT_BUFFER ){ - yyensure_buffer_stack (); - YY_CURRENT_BUFFER_LVALUE = - yy_create_buffer(yyin,YY_BUF_SIZE ); - } - - yy_init_buffer(YY_CURRENT_BUFFER,input_file ); - yy_load_buffer_state( ); -} - -/** Switch to a different input buffer. - * @param new_buffer The new input buffer. - * - */ - void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) -{ - - /* TODO. We should be able to replace this entire function body - * with - * yypop_buffer_state(); - * yypush_buffer_state(new_buffer); - */ - yyensure_buffer_stack (); - if ( YY_CURRENT_BUFFER == new_buffer ) - return; - - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - YY_CURRENT_BUFFER_LVALUE = new_buffer; - yy_load_buffer_state( ); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - (yy_did_buffer_switch_on_eof) = 1; -} - -static void yy_load_buffer_state (void) -{ - (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; - (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; - yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; - (yy_hold_char) = *(yy_c_buf_p); -} - -/** Allocate and initialize an input buffer state. - * @param file A readable stream. - * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. - * - * @return the allocated buffer state. - */ - YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) -{ - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer(b,file ); - - return b; -} - -/** Destroy the buffer. - * @param b a buffer created with yy_create_buffer() - * - */ - void yy_delete_buffer (YY_BUFFER_STATE b ) -{ - - if ( ! b ) - return; - - if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ - YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yyfree((void *) b->yy_ch_buf ); - - yyfree((void *) b ); -} - -#ifndef __cplusplus -extern int isatty (int ); -#endif /* __cplusplus */ - -/* Initializes or reinitializes a buffer. - * This function is sometimes called more than once on the same buffer, - * such as during a yyrestart() or at EOF. - */ - static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) - -{ - int oerrno = errno; - - yy_flush_buffer(b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - - /* If b is the current buffer, then yy_init_buffer was _probably_ - * called from yyrestart() or through yy_get_next_buffer. - * In that case, we don't want to reset the lineno or column. - */ - if (b != YY_CURRENT_BUFFER){ - b->yy_bs_lineno = 1; - b->yy_bs_column = 0; - } - - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; - - errno = oerrno; -} - -/** Discard all buffered characters. On the next scan, YY_INPUT will be called. - * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. - * - */ - void yy_flush_buffer (YY_BUFFER_STATE b ) -{ - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == YY_CURRENT_BUFFER ) - yy_load_buffer_state( ); -} - -/** Pushes the new state onto the stack. The new state becomes - * the current state. This function will allocate the stack - * if necessary. - * @param new_buffer The new state. - * - */ -void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) -{ - if (new_buffer == NULL) - return; - - yyensure_buffer_stack(); - - /* This block is copied from yy_switch_to_buffer. */ - if ( YY_CURRENT_BUFFER ) - { - /* Flush out information for old buffer. */ - *(yy_c_buf_p) = (yy_hold_char); - YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); - YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); - } - - /* Only push if top exists. Otherwise, replace top. */ - if (YY_CURRENT_BUFFER) - (yy_buffer_stack_top)++; - YY_CURRENT_BUFFER_LVALUE = new_buffer; - - /* copied from yy_switch_to_buffer. */ - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; -} - -/** Removes and deletes the top of the stack, if present. - * The next element becomes the new top. - * - */ -void yypop_buffer_state (void) -{ - if (!YY_CURRENT_BUFFER) - return; - - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - if ((yy_buffer_stack_top) > 0) - --(yy_buffer_stack_top); - - if (YY_CURRENT_BUFFER) { - yy_load_buffer_state( ); - (yy_did_buffer_switch_on_eof) = 1; - } -} - -/* Allocates the stack if it does not exist. - * Guarantees space for at least one push. - */ -static void yyensure_buffer_stack (void) -{ - int num_to_alloc; - - if (!(yy_buffer_stack)) { - - /* First allocation is just for 2 elements, since we don't know if this - * scanner will even need a stack. We use 2 instead of 1 to avoid an - * immediate realloc on the next call. - */ - num_to_alloc = 1; - (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc - (num_to_alloc * sizeof(struct yy_buffer_state*) - ); - - memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); - - (yy_buffer_stack_max) = num_to_alloc; - (yy_buffer_stack_top) = 0; - return; - } - - if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ - - /* Increase the buffer to prepare for a possible push. */ - int grow_size = 8 /* arbitrary grow size */; - - num_to_alloc = (yy_buffer_stack_max) + grow_size; - (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc - ((yy_buffer_stack), - num_to_alloc * sizeof(struct yy_buffer_state*) - ); - - /* zero only the new slots.*/ - memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); - (yy_buffer_stack_max) = num_to_alloc; - } -} - -/** Setup the input buffer state to scan directly from a user-specified character buffer. - * @param base the character buffer - * @param size the size in bytes of the character buffer - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) -{ - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer(b ); - - return b; -} - -/** Setup the input buffer state to scan a string. The next call to yylex() will - * scan from a @e copy of @a str. - * @param str a NUL-terminated string to scan - * - * @return the newly allocated buffer state object. - * @note If you want to scan bytes that may contain NUL values, then use - * yy_scan_bytes() instead. - */ -YY_BUFFER_STATE yy_scan_string (yyconst char * yy_str ) -{ - - return yy_scan_bytes(yy_str,strlen(yy_str) ); -} - -/** Setup the input buffer state to scan the given bytes. The next call to yylex() will - * scan from a @e copy of @a bytes. - * @param bytes the byte buffer to scan - * @param len the number of bytes in the buffer pointed to by @a bytes. - * - * @return the newly allocated buffer state object. - */ -YY_BUFFER_STATE yy_scan_bytes (yyconst char * bytes, int len ) -{ - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yyalloc(n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; - - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer(buf,n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; -} - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -static void yy_fatal_error (yyconst char* msg ) -{ - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); -} - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - int yyless_macro_arg = (n); \ - YY_LESS_LINENO(yyless_macro_arg);\ - yytext[yyleng] = (yy_hold_char); \ - (yy_c_buf_p) = yytext + yyless_macro_arg; \ - (yy_hold_char) = *(yy_c_buf_p); \ - *(yy_c_buf_p) = '\0'; \ - yyleng = yyless_macro_arg; \ - } \ - while ( 0 ) - -/* Accessor methods (get/set functions) to struct members. */ - -/** Get the current line number. - * - */ -int yyget_lineno (void) -{ - - return yylineno; -} - -/** Get the input stream. - * - */ -FILE *yyget_in (void) -{ - return yyin; -} - -/** Get the output stream. - * - */ -FILE *yyget_out (void) -{ - return yyout; -} - -/** Get the length of the current token. - * - */ -int yyget_leng (void) -{ - return yyleng; -} - -/** Get the current token. - * - */ - -char *yyget_text (void) -{ - return yytext; -} - -/** Set the current line number. - * @param line_number - * - */ -void yyset_lineno (int line_number ) -{ - - yylineno = line_number; -} - -/** Set the input stream. This does not discard the current - * input buffer. - * @param in_str A readable stream. - * - * @see yy_switch_to_buffer - */ -void yyset_in (FILE * in_str ) -{ - yyin = in_str ; -} - -void yyset_out (FILE * out_str ) -{ - yyout = out_str ; -} - -int yyget_debug (void) -{ - return yy_flex_debug; -} - -void yyset_debug (int bdebug ) -{ - yy_flex_debug = bdebug ; -} - -/* yylex_destroy is for both reentrant and non-reentrant scanners. */ -int yylex_destroy (void) -{ - - /* Pop the buffer stack, destroying each element. */ - while(YY_CURRENT_BUFFER){ - yy_delete_buffer(YY_CURRENT_BUFFER ); - YY_CURRENT_BUFFER_LVALUE = NULL; - yypop_buffer_state(); - } - - /* Destroy the stack itself. */ - yyfree((yy_buffer_stack) ); - (yy_buffer_stack) = NULL; - - return 0; -} - -/* - * Internal utility routines. - */ - -#ifndef yytext_ptr -static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) -{ - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; -} -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen (yyconst char * s ) -{ - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; -} -#endif - -void *yyalloc (yy_size_t size ) -{ - return (void *) malloc( size ); -} - -void *yyrealloc (void * ptr, yy_size_t size ) -{ - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); -} - -void yyfree (void * ptr ) -{ - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ -} - -#define YYTABLES_NAME "yytables" - -#undef YY_NEW_FILE -#undef YY_FLUSH_BUFFER -#undef yy_set_bol -#undef yy_new_buffer -#undef yy_set_interactive -#undef yytext_ptr -#undef YY_DO_BEFORE_ACTION - -#ifdef YY_DECL_IS_OURS -#undef YY_DECL_IS_OURS -#undef YY_DECL -#endif -#line 684 "goom_script_lex.l" - - - -static void reset_scanner(GoomScriptScanner *gss) { - - gss->num_lines = 0; - gss->instr = NULL; - iflow_clean(gss->iflow); - gss->current_flow = gss->iflow; - - /* reset variables */ - goom_hash_free(gss->vars); - gss->vars = goom_hash_new(); - - gss->compilationOK = 1; -} - -static void calculate_labels(InstructionFlow *iflow) { - int i = 0; - while (i < iflow->number) { - Instruction *instr = iflow->instr[i]; - if (instr->jump_label) { - HashValue *label = goom_hash_get(iflow->labels,instr->jump_label); - if (label) { - instr->data.jump_offset = -instr->address + label->i; - } - else { - fprintf(stderr, "ERROR: could not find label %s\n", instr->jump_label); - instr->id = INSTR_NOP; - } - } - ++i; - } -} - -void goom_script_scanner_compile(GoomScriptScanner *_currentScanner, PluginInfo *pluginInfo, const char *script) { - -#ifdef VERBOSE - printf("\n=== Starting Compilation ===\n"); -#endif - - /* 0- reset */ - currentScanner = _currentScanner; - reset_scanner(currentScanner); - currentScanner->pluginInfo = pluginInfo; - - /* 1- create the syntaxic tree */ - yy_scan_string(script); - yyparse(); - - /* 2- generate code */ - gsl_commit_compilation(); - - /* 3- resolve symbols */ - calculate_labels(currentScanner->iflow); - -#ifdef VERBOSE - printf("=== Compilation done. # of lines: %d. # of instr: %d ===\n", currentScanner->num_lines, currentScanner->iflow->number); -#endif -} - -void goom_script_scanner_execute(GoomScriptScanner *scanner) { - - ScriptExecEnv exec_env; - exec_env.vars = scanner->vars; - if (scanner->compilationOK) - iflow_execute(scanner->iflow, &exec_env); -} - -GoomScriptScanner *goom_script_scanner_new() { - - GoomScriptScanner *gss = (GoomScriptScanner*)malloc(sizeof(GoomScriptScanner)); - - gss->iflow = iflow_new(); - gss->vars = goom_hash_new(); - - reset_scanner(gss); - gss->compilationOK = 0; - return gss; -} - -int goom_script_scanner_is_compiled(GoomScriptScanner *gss) { - return gss->compilationOK; -} - -void goom_script_scanner_free(GoomScriptScanner *gss) { - free(gss); -} - -int yywrap(void) { return 1; } - - diff --git a/src/post/goom/goom_script_scanner.h b/src/post/goom/goom_script_scanner.h deleted file mode 100644 index 40360dc24..000000000 --- a/src/post/goom/goom_script_scanner.h +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef _GOOM_SCRIPT_SCANNER_H -#define _GOOM_SCRIPT_SCANNER_H - -#include "goom_plugin_info.h" - -void goom_script_scanner_compile(GoomScriptScanner *scanner, PluginInfo *pluginInfo, const char *script); -void goom_script_scanner_execute(GoomScriptScanner *scanner); -int goom_script_scanner_is_compiled(GoomScriptScanner *gss); - -GoomScriptScanner *goom_script_scanner_new(void); -void goom_script_scanner_free(GoomScriptScanner *gss); - - -/* -- internal use -- */ - -#include "goom_hash.h" - -#define EMPTY_NODE 0 -#define CONST_INT_NODE 1 -#define CONST_FLOAT_NODE 2 -#define VAR_NODE 3 -#define PARAM_NODE 4 -#define READ_PARAM_NODE 5 -#define OPR_NODE 6 - -#define OPR_SET 1 -#define OPR_DECLARE_INT 2 -#define OPR_DECLARE_FLOAT 3 -#define OPR_IF 4 -#define OPR_BLOCK 5 -#define OPR_ADD 6 -#define OPR_MUL 7 -#define OPR_EQU 8 -#define OPR_LOW 9 -#define OPR_DIV 10 -#define OPR_SUB 11 -#define OPR_FUNC_INTRO 12 -#define OPR_FUNC_OUTRO 13 -#define OPR_CALL 14 - -typedef struct { -/* char *name;*/ -} ParamNodeType; - -typedef struct { -/* char *name;*/ -} VarNodeType; - -typedef struct { - int val; -} ConstIntNodeType; - -typedef struct { - float val; -} ConstFloatNodeType; - -typedef struct { - int type; - int nbOp; - struct _NODE_TYPE *op[3]; /* maximal number of operand needed */ - struct _NODE_TYPE *next; -} OprNodeType; - -typedef struct _NODE_TYPE{ - int type; - char *str; - union { - ParamNodeType param; - VarNodeType var; - ConstIntNodeType constInt; - ConstFloatNodeType constFloat; - OprNodeType opr; - } unode; -} NodeType; - -void gsl_commit_compilation(void); - -/* ------------- SCRIPT_EXEC_ENV ------------ */ - -typedef struct _SCRIPT_EXEC_ENV { - int ip; - GoomHash *vars; -} ScriptExecEnv; - -/* ------------- INSTRUCTIONS -------------- */ - -typedef struct _INSTRUCTION { - - int id; - GoomScriptScanner *parent; - const char *name; /* name of the instruction */ - - char **params; /* parametres de l'instruction */ - int *types; /* type des parametres de l'instruction */ - int cur_param; - int nb_param; - - int address; - char *jump_label; - - union { - - /* PARAM - INTEGER */ - struct { - PluginParam *param; - int value; - } p_i; - - /* PARAM - FLOAT */ - struct { - PluginParam *param; - float value; - } p_f; - - /* VAR - PARAM */ - struct { - PluginParam *param; - HashValue *var; - } v_p; - - /* VAR - INTEGER */ - struct { - HashValue *var; - int value; - } v_i; - - /* VAR - FLOAT */ - struct { - HashValue *var; - float value; - } v_f; - - /* VAR - VAR */ - struct { - HashValue *var_src; - HashValue *var_dest; - } v_v; - - /* VAR */ - struct { - int jump_offset; - HashValue *var; - } v; - - int jump_offset; - - } data; - -} Instruction; - -Instruction *instr_init(GoomScriptScanner *parent, const char *name, int id, int nb_param); -void instr_add_param(Instruction *_this, char *param, int type); -void instr_display(Instruction *_this); - -/* ----------- INSTRUCTION_FLOW ------------- */ - -typedef struct _INSTRUCTION_FLOW { - - Instruction **instr; - int number; - int tabsize; - GoomHash *labels; - -} InstructionFlow; - -/* ----------- GOOM SCRIPT SCANNER ------------- */ - -struct _GoomScriptScanner { - int num_lines; - Instruction *instr; /* instruction en cours de construction */ - - InstructionFlow *iflow; /* flow d'instruction racine */ - GoomHash *vars; /* table de variables */ - InstructionFlow *current_flow; - - PluginInfo *pluginInfo; - int compilationOK; -}; - -/* #define TYPE_PARAM 1 - #define TYPE_INTEGER 2 - #define TYPE_FLOAT 3 - #define TYPE_VAR 4 */ -#define TYPE_LABEL 5 -#define TYPE_OP_EQUAL 6 - -#define INSTR_JUMP 6 - -#define INSTR_SETI 10001 -#define INSTR_SETF 10002 -#define INSTR_INT 10003 -#define INSTR_LABEL 10004 -#define INSTR_ISLOWERI 10005 -#define INSTR_ISLOWERF 10006 -#define INSTR_ADDI 10007 -#define INSTR_ADDF 10008 -#define INSTR_MULI 10009 -#define INSTR_MULF 10010 -#define INSTR_DIVF 10011 -#define INSTR_SUBF 10012 -#define INSTR_ISEQUALI 10013 -#define INSTR_ISEQUALF 10014 -#define INSTR_JZERO 29 -#define INSTR_CALL 34 -#define INSTR_RET 35 - -#endif diff --git a/src/post/goom/goom_script_yacc.c b/src/post/goom/goom_script_yacc.c deleted file mode 100644 index 50a1ec90f..000000000 --- a/src/post/goom/goom_script_yacc.c +++ /dev/null @@ -1,1797 +0,0 @@ -/* A Bison parser, made by GNU Bison 1.875a. */ - -/* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* Written by Richard Stallman by simplifying the original so called - ``semantic'' parser. */ - -/* All symbols defined below should begin with yy or YY, to avoid - infringing on user name space. This should be done even for local - variables, as they might otherwise be expanded by user macros. - There are some unavoidable exceptions within include files to - define necessary library symbols; they are noted "INFRINGES ON - USER NAME SPACE" below. */ - -/* Identify Bison output. */ -#define YYBISON 1 - -/* Skeleton name. */ -#define YYSKELETON_NAME "yacc.c" - -/* Pure parsers. */ -#define YYPURE 0 - -/* Using locations. */ -#define YYLSP_NEEDED 0 - - - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - TYPE_INTEGER = 258, - TYPE_FLOAT = 259, - TYPE_VAR = 260, - TYPE_PARAM = 261, - INT_TK = 262, - FLOAT_TK = 263, - ARROW_TK = 264 - }; -#endif -#define TYPE_INTEGER 258 -#define TYPE_FLOAT 259 -#define TYPE_VAR 260 -#define TYPE_PARAM 261 -#define INT_TK 262 -#define FLOAT_TK 263 -#define ARROW_TK 264 - - - - -/* Copy the first part of user declarations. */ -#line 6 "goom_script_yacc.y" - - #include <stdio.h> - #include <string.h> - #include "goom_script_scanner.h" - - int yylex(void); - void yyerror(char *); - extern GoomScriptScanner *currentScanner; - - static NodeType *nodeNew(const char *str, int type); - static void nodeFreeInternals(NodeType *node); - static void nodeFree(NodeType *node); - - static void commit_node(NodeType *node); - static void precommit_node(NodeType *node); - - static NodeType *new_constInt(const char *str); - static NodeType *new_constFloat(const char *str); - static NodeType *new_var(const char *str); - static NodeType *new_param(const char *str); - static NodeType *new_read_param(const char *str); - static NodeType *new_nop(const char *str); - static NodeType *new_op(const char *str, int type, int nbOp); - - static int allocateLabel(void); - #define allocateTemp allocateLabel - - /* SETTER */ - static NodeType *new_set(NodeType *lvalue, NodeType *expression) { - NodeType *set = new_op("set", OPR_SET, 2); - set->unode.opr.op[0] = lvalue; - set->unode.opr.op[1] = expression; - return set; - } - static void commit_set(NodeType *set) { - precommit_node(set->unode.opr.op[1]); -#ifdef VERBOSE - printf("set.f %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); -#endif - currentScanner->instr = instr_init(currentScanner, "set.f", INSTR_SETF, 2); - commit_node(set->unode.opr.op[0]); - commit_node(set->unode.opr.op[1]); - } - - /* FLOAT */ - static NodeType *new_float_decl(NodeType *name) { - NodeType *fld = new_op("float", OPR_DECLARE_FLOAT, 1); - fld->unode.opr.op[0] = name; - return fld; - } - static void commit_float(NodeType *var) { -#ifdef VERBOSE - printf("float %s\n", var->unode.opr.op[0]->str); -#endif - currentScanner->instr = instr_init(currentScanner, "float", INSTR_INT, 1); - commit_node(var->unode.opr.op[0]); - } - - /* INT */ - static NodeType *new_int_decl(NodeType *name) { - NodeType *intd = new_op("int", OPR_DECLARE_INT, 1); - intd->unode.opr.op[0] = name; - return intd; - } - static void commit_int(NodeType *var) { -#ifdef VERBOSE - printf("int %s\n", var->unode.opr.op[0]->str); -#endif - currentScanner->instr = instr_init(currentScanner, "int", INSTR_INT, 1); - commit_node(var->unode.opr.op[0]); - } - - /* precommit read_param: a read param is a param for reading. - * precommit copy it to a temporary variable. - */ - static void precommit_read_param(NodeType *rparam) { - char stmp[256]; - NodeType *tmp; - - /* declare a float to store the result */ - sprintf(stmp,"__tmp%i",allocateTemp()); - commit_node(new_float_decl(new_var(stmp))); - /* set the float to the value of "op1" */ - commit_node(new_set(new_var(stmp),new_param(rparam->str))); - - /* redefine the ADD node now as the computed variable */ - nodeFreeInternals(rparam); - tmp = new_var(stmp); - *rparam = *tmp; - free(tmp); - } - - /* commodity method for add, mult, ... */ - - static int is_tmp_expr(NodeType *node) { - return node->str && !strncmp(node->str,"__tmp",5); - } - - static void precommit_expr(NodeType *expr, const char *type, int instr_id) { - - char stmp[256]; - NodeType *tmp; - int toAdd; - - /* compute "left" and "right" */ - precommit_node(expr->unode.opr.op[0]); - precommit_node(expr->unode.opr.op[1]); - - if (is_tmp_expr(expr->unode.opr.op[0])) { - strcpy(stmp, expr->unode.opr.op[0]->str); - toAdd = 1; - } - else if (is_tmp_expr(expr->unode.opr.op[1])) { - strcpy(stmp,expr->unode.opr.op[1]->str); - toAdd = 0; - } - else { - /* declare a float to store the result */ - sprintf(stmp,"__tmp%i",allocateTemp()); - commit_node(new_float_decl(new_var(stmp))); - /* set the float to the value of "op1" */ - commit_node(new_set(new_var(stmp),expr->unode.opr.op[0])); - toAdd = 1; - } - - /* add op2 to tmp */ -#ifdef VERBOSE - printf("%s %s %s\n", type, stmp, expr->unode.opr.op[toAdd]->str); -#endif - currentScanner->instr = instr_init(currentScanner, type, instr_id, 2); - commit_node(new_var(stmp)); - commit_node(expr->unode.opr.op[toAdd]); - - /* redefine the ADD node now as the computed variable */ - nodeFreeInternals(expr); - tmp = new_var(stmp); - *expr = *tmp; - free(tmp); - } - - static NodeType *new_expr2(const char *name, int id, NodeType *expr1, NodeType *expr2) { - NodeType *add = new_op(name, id, 2); - add->unode.opr.op[0] = expr1; - add->unode.opr.op[1] = expr2; - return add; - } - - /* ADD */ - static NodeType *new_add(NodeType *expr1, NodeType *expr2) { - return new_expr2("add.f", OPR_ADD, expr1, expr2); - } - static void precommit_add(NodeType *add) { - precommit_expr(add,"add.f",INSTR_ADDF); - } - - /* SUB */ - static NodeType *new_sub(NodeType *expr1, NodeType *expr2) { - return new_expr2("sub.f", OPR_SUB, expr1, expr2); - } - static void precommit_sub(NodeType *sub) { - precommit_expr(sub,"sub.f",INSTR_SUBF); - } - - /* MUL */ - static NodeType *new_mul(NodeType *expr1, NodeType *expr2) { - return new_expr2("mul.f", OPR_MUL, expr1, expr2); - } - static void precommit_mul(NodeType *mul) { - precommit_expr(mul,"mul.f",INSTR_MULF); - } - - /* DIV */ - static NodeType *new_div(NodeType *expr1, NodeType *expr2) { - return new_expr2("div.f", OPR_DIV, expr1, expr2); - } - static void precommit_div(NodeType *mul) { - precommit_expr(mul,"div.f",INSTR_DIVF); - } - - /* EQU */ - static NodeType *new_equ(NodeType *expr1, NodeType *expr2) { - return new_expr2("isequal.f", OPR_EQU, expr1, expr2); - } - static void precommit_equ(NodeType *mul) { - precommit_expr(mul,"isequal.f",INSTR_ISEQUALF); - } - - /* INF */ - static NodeType *new_low(NodeType *expr1, NodeType *expr2) { - return new_expr2("islower.f", OPR_LOW, expr1, expr2); - } - static void precommit_low(NodeType *mul) { - precommit_expr(mul,"islower.f",INSTR_ISLOWERF); - } - - /* IF */ - static NodeType *new_if(NodeType *expression, NodeType *instr) { - NodeType *node = new_op("if", OPR_IF, 2); - node->unode.opr.op[0] = expression; - node->unode.opr.op[1] = instr; - return node; - } - static void commit_if(NodeType *node) { - - char slab[1024]; - precommit_node(node->unode.opr.op[0]); - - /* jzero.i <expression> <endif> */ - sprintf(slab, "|eif%d|", allocateLabel()); -#ifdef VERBOSE - printf("jzero.i %s %s\n", node->unode.opr.op[0]->str, slab); -#endif - currentScanner->instr = instr_init(currentScanner, "jzero.i", INSTR_JZERO, 2); - commit_node(node->unode.opr.op[0]); - instr_add_param(currentScanner->instr, slab, TYPE_LABEL); - - /* [... instrs of the if ...] */ - commit_node(node->unode.opr.op[1]); - /* label <endif> */ -#ifdef VERBOSE - printf("label %s\n", slab); -#endif - currentScanner->instr = instr_init(currentScanner, "label", INSTR_LABEL, 1); - instr_add_param(currentScanner->instr, slab, TYPE_LABEL); - } - - /* BLOCK */ - static NodeType *new_block(NodeType *lastNode) { - NodeType *blk = new_op("block", OPR_BLOCK, 2); - blk->unode.opr.op[0] = new_nop("start_of_block"); - blk->unode.opr.op[1] = lastNode; - return blk; - } - static void commit_block(NodeType *node) { - commit_node(node->unode.opr.op[0]->unode.opr.next); - } - - /* FUNCTION INTRO */ - static NodeType *new_function_intro(const char *name) { - char stmp[256]; - if (strlen(name) < 200) { - sprintf(stmp, "|__func_%s|", name); - } - return new_op(stmp, OPR_FUNC_INTRO, 0); - } - static void commit_function_intro(NodeType *node) { - currentScanner->instr = instr_init(currentScanner, "label", INSTR_LABEL, 1); - instr_add_param(currentScanner->instr, node->str, TYPE_LABEL); -#ifdef VERBOSE - printf("label %s\n", node->str); -#endif - } - - /* FUNCTION OUTRO */ - static NodeType *new_function_outro(void) { - return new_op("ret", OPR_FUNC_OUTRO, 0); - } - static void commit_function_outro(NodeType *node) { - currentScanner->instr = instr_init(currentScanner, "ret", INSTR_RET, 1); - instr_add_param(currentScanner->instr, "|dummy|", TYPE_LABEL); -#ifdef VERBOSE - printf("ret\n"); -#endif - } - - /* FUNCTION CALL */ - static NodeType *new_call(const char *name) { - char stmp[256]; - if (strlen(name) < 200) { - sprintf(stmp, "|__func_%s|", name); - } - return new_op(stmp, OPR_CALL, 0); - } - static void commit_call(NodeType *node) { - currentScanner->instr = instr_init(currentScanner, "call", INSTR_CALL, 1); - instr_add_param(currentScanner->instr, node->str, TYPE_LABEL); -#ifdef VERBOSE - printf("call %s\n", node->str); -#endif - } - - - /** **/ - - static NodeType *rootNode = 0; // TODO: reinitialiser a chaque compilation. - static NodeType *lastNode = 0; - static NodeType *gsl_append(NodeType *curNode) { - if (lastNode) - lastNode->unode.opr.next = curNode; - lastNode = curNode; - while(lastNode->unode.opr.next) lastNode = lastNode->unode.opr.next; - if (rootNode == 0) - rootNode = curNode; - return curNode; - } - - static int lastLabel = 0; - int allocateLabel(void) { - return ++lastLabel; - } - - void gsl_commit_compilation(void) { - commit_node(rootNode); - rootNode = 0; - lastNode = 0; - } - - void precommit_node(NodeType *node) { - /* do here stuff for expression.. for exemple */ - switch(node->type) { - case OPR_NODE: - switch(node->unode.opr.type) { - case OPR_ADD: precommit_add(node); break; - case OPR_SUB: precommit_sub(node); break; - case OPR_MUL: precommit_mul(node); break; - case OPR_DIV: precommit_div(node); break; - case OPR_EQU: precommit_equ(node); break; - case OPR_LOW: precommit_low(node); break; - } - break; - case READ_PARAM_NODE: - precommit_read_param(node); break; - } - } - - void commit_node(NodeType *node) { - - if (node == 0) return; - - switch(node->type) { - case OPR_NODE: - switch(node->unode.opr.type) { - case OPR_DECLARE_FLOAT: commit_float(node); break; - case OPR_DECLARE_INT: commit_int(node); break; - case OPR_SET: commit_set(node); break; - case OPR_IF: commit_if(node); break; - case OPR_BLOCK: commit_block(node); break; - case OPR_FUNC_INTRO: commit_function_intro(node); break; - case OPR_FUNC_OUTRO: commit_function_outro(node); break; - case OPR_CALL: commit_call(node); break; -#ifdef VERBOSE - case EMPTY_NODE: printf("NOP\n"); break; -#endif - } - - commit_node(node->unode.opr.next); /* recursive for the moment, maybe better to do something iterative? */ - break; - - case PARAM_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_PARAM); break; - case VAR_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_VAR); break; - case CONST_INT_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_INTEGER); break; - case CONST_FLOAT_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_FLOAT); break; - } - nodeFree(node); - } - - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG 0 -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE 0 -#endif - -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 361 "goom_script_yacc.y" -typedef union YYSTYPE { - int intValue; - float floatValue; - char charValue; - char strValue[2048]; - NodeType *nPtr; - } YYSTYPE; -/* Line 191 of yacc.c. */ -#line 457 "y.tab.c" -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 -#endif - - - -/* Copy the second part of user declarations. */ - - -/* Line 214 of yacc.c. */ -#line 469 "y.tab.c" - -#if ! defined (yyoverflow) || YYERROR_VERBOSE - -/* The parser invokes alloca or malloc; define the necessary symbols. */ - -# if YYSTACK_USE_ALLOCA -# define YYSTACK_ALLOC alloca -# else -# ifndef YYSTACK_USE_ALLOCA -# if defined (alloca) || defined (_ALLOCA_H) -# define YYSTACK_ALLOC alloca -# else -# ifdef __GNUC__ -# define YYSTACK_ALLOC __builtin_alloca -# endif -# endif -# endif -# endif - -# ifdef YYSTACK_ALLOC - /* Pacify GCC's `empty if-body' warning. */ -# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) -# else -# if defined (__STDC__) || defined (__cplusplus) -# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -# define YYSTACK_ALLOC malloc -# define YYSTACK_FREE free -# endif -#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ - - -#if (! defined (yyoverflow) \ - && (! defined (__cplusplus) \ - || (YYSTYPE_IS_TRIVIAL))) - -/* A type that is properly aligned for any stack member. */ -union yyalloc -{ - short yyss; - YYSTYPE yyvs; - }; - -/* The size of the maximum gap between one aligned stack and the next. */ -# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) - -/* The size of an array large to enough to hold all stacks, each with - N elements. */ -# define YYSTACK_BYTES(N) \ - ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ - + YYSTACK_GAP_MAXIMUM) - -/* Copy COUNT objects from FROM to TO. The source and destination do - not overlap. */ -# ifndef YYCOPY -# if 1 < __GNUC__ -# define YYCOPY(To, From, Count) \ - __builtin_memcpy (To, From, (Count) * sizeof (*(From))) -# else -# define YYCOPY(To, From, Count) \ - do \ - { \ - register YYSIZE_T yyi; \ - for (yyi = 0; yyi < (Count); yyi++) \ - (To)[yyi] = (From)[yyi]; \ - } \ - while (0) -# endif -# endif - -/* Relocate STACK from its old location to the new one. The - local variables YYSIZE and YYSTACKSIZE give the old and new number of - elements in the stack, and YYPTR gives the new location of the - stack. Advance YYPTR to a properly aligned location for the next - stack. */ -# define YYSTACK_RELOCATE(Stack) \ - do \ - { \ - YYSIZE_T yynewbytes; \ - YYCOPY (&yyptr->Stack, Stack, yysize); \ - Stack = &yyptr->Stack; \ - yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ - yyptr += yynewbytes / sizeof (*yyptr); \ - } \ - while (0) - -#endif - -#if defined (__STDC__) || defined (__cplusplus) - typedef signed char yysigned_char; -#else - typedef short yysigned_char; -#endif - -/* YYFINAL -- State number of the termination state. */ -#define YYFINAL 3 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 80 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 23 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 13 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 34 -/* YYNRULES -- Number of states. */ -#define YYNSTATES 65 - -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 264 - -#define YYTRANSLATE(YYX) \ - ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) - -/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ -static const unsigned 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, 2, 2, 2, - 18, 19, 15, 13, 2, 14, 2, 16, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 17, - 11, 10, 12, 20, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 21, 2, 22, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 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, 8, 9 -}; - -#if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const unsigned char yyprhs[] = -{ - 0, 0, 3, 7, 10, 11, 14, 15, 19, 23, - 24, 29, 35, 39, 43, 49, 54, 58, 60, 61, - 63, 65, 69, 73, 77, 81, 85, 89, 93, 97, - 99, 101, 103, 105, 107 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yysigned_char yyrhs[] = -{ - 24, 0, -1, 25, 29, 26, -1, 25, 30, -1, - -1, 26, 27, -1, -1, 28, 25, 29, -1, 11, - 5, 12, -1, -1, 34, 10, 32, 17, -1, 8, - 5, 10, 32, 17, -1, 8, 5, 17, -1, 7, - 5, 17, -1, 18, 32, 19, 20, 30, -1, 21, - 31, 24, 22, -1, 9, 5, 17, -1, 17, -1, - -1, 33, -1, 35, -1, 32, 15, 32, -1, 32, - 16, 32, -1, 32, 13, 32, -1, 32, 14, 32, - -1, 32, 10, 32, -1, 32, 11, 32, -1, 32, - 12, 32, -1, 18, 32, 19, -1, 5, -1, 6, - -1, 5, -1, 6, -1, 4, -1, 3, -1 -}; - -/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ -static const unsigned short yyrline[] = -{ - 0, 384, 384, 386, 387, 390, 391, 394, 396, 397, - 399, 400, 402, 403, 404, 405, 406, 407, 410, 413, - 414, 415, 416, 417, 418, 419, 420, 421, 422, 425, - 426, 429, 430, 433, 434 -}; -#endif - -#if YYDEBUG || YYERROR_VERBOSE -/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. - First, the terminals, then, starting at YYNTOKENS, nonterminals. */ -static const char *const yytname[] = -{ - "$end", "error", "$undefined", "TYPE_INTEGER", "TYPE_FLOAT", "TYPE_VAR", - "TYPE_PARAM", "INT_TK", "FLOAT_TK", "ARROW_TK", "'='", "'<'", "'>'", - "'+'", "'-'", "'*'", "'/'", "';'", "'('", "')'", "'?'", "'{'", "'}'", - "$accept", "gsl", "gsl_code", "gsl_def_functions", "function", - "function_intro", "function_outro", "instruction", "start_block", - "expression", "read_variable", "write_variable", "constValue", 0 -}; -#endif - -# ifdef YYPRINT -/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to - token YYLEX-NUM. */ -static const unsigned short yytoknum[] = -{ - 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, - 61, 60, 62, 43, 45, 42, 47, 59, 40, 41, - 63, 123, 125 -}; -# endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const unsigned char yyr1[] = -{ - 0, 23, 24, 25, 25, 26, 26, 27, 28, 29, - 30, 30, 30, 30, 30, 30, 30, 30, 31, 32, - 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, - 33, 34, 34, 35, 35 -}; - -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const unsigned char yyr2[] = -{ - 0, 2, 3, 2, 0, 2, 0, 3, 3, 0, - 4, 5, 3, 3, 5, 4, 3, 1, 0, 1, - 1, 3, 3, 3, 3, 3, 3, 3, 3, 1, - 1, 1, 1, 1, 1 -}; - -/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state - STATE-NUM when YYTABLE doesn't specify something else to do. Zero - means the default is an error. */ -static const unsigned char yydefact[] = -{ - 4, 0, 9, 1, 31, 32, 0, 0, 0, 17, - 0, 18, 6, 3, 0, 0, 0, 0, 34, 33, - 29, 30, 0, 0, 19, 20, 4, 2, 0, 13, - 0, 12, 16, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 5, 4, 0, 0, 28, 25, - 26, 27, 23, 24, 21, 22, 0, 15, 0, 9, - 10, 11, 14, 8, 7 -}; - -/* YYDEFGOTO[NTERM-NUM]. */ -static const yysigned_char yydefgoto[] = -{ - -1, 1, 2, 27, 44, 45, 12, 13, 26, 23, - 24, 14, 25 -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -23 -static const yysigned_char yypact[] = -{ - -23, 1, 14, -23, -23, -23, 0, 2, 5, -23, - 21, -23, -23, -23, 18, -6, -8, 12, -23, -23, - -23, -23, 21, 30, -23, -23, -23, 19, 21, -23, - 21, -23, -23, 40, 21, 21, 21, 21, 21, 21, - 21, 13, 15, 29, -23, -23, 50, 58, -23, 63, - 63, 63, -12, -12, 20, -23, 14, -23, 26, 14, - -23, -23, -23, -23, -23 -}; - -/* YYPGOTO[NTERM-NUM]. */ -static const yysigned_char yypgoto[] = -{ - -23, 22, 35, -23, -23, -23, -2, -9, -23, -22, - -23, -23, -23 -}; - -/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If - positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. - If YYTABLE_NINF, syntax error. */ -#define YYTABLE_NINF -1 -static const unsigned char yytable[] = -{ - 33, 3, 30, 39, 40, 15, 46, 16, 47, 31, - 17, 29, 49, 50, 51, 52, 53, 54, 55, 4, - 5, 6, 7, 8, 18, 19, 20, 21, 28, 32, - 43, 9, 10, 56, 58, 11, 40, 57, 63, 22, - 34, 35, 36, 37, 38, 39, 40, 62, 42, 41, - 34, 35, 36, 37, 38, 39, 40, 64, 0, 48, - 34, 35, 36, 37, 38, 39, 40, 60, 34, 35, - 36, 37, 38, 39, 40, 61, 37, 38, 39, 40, - 59 -}; - -static const yysigned_char yycheck[] = -{ - 22, 0, 10, 15, 16, 5, 28, 5, 30, 17, - 5, 17, 34, 35, 36, 37, 38, 39, 40, 5, - 6, 7, 8, 9, 3, 4, 5, 6, 10, 17, - 11, 17, 18, 20, 5, 21, 16, 22, 12, 18, - 10, 11, 12, 13, 14, 15, 16, 56, 26, 19, - 10, 11, 12, 13, 14, 15, 16, 59, -1, 19, - 10, 11, 12, 13, 14, 15, 16, 17, 10, 11, - 12, 13, 14, 15, 16, 17, 13, 14, 15, 16, - 45 -}; - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const unsigned char yystos[] = -{ - 0, 24, 25, 0, 5, 6, 7, 8, 9, 17, - 18, 21, 29, 30, 34, 5, 5, 5, 3, 4, - 5, 6, 18, 32, 33, 35, 31, 26, 10, 17, - 10, 17, 17, 32, 10, 11, 12, 13, 14, 15, - 16, 19, 24, 11, 27, 28, 32, 32, 19, 32, - 32, 32, 32, 32, 32, 32, 20, 22, 5, 25, - 17, 17, 30, 12, 29 -}; - -#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) -# define YYSIZE_T __SIZE_TYPE__ -#endif -#if ! defined (YYSIZE_T) && defined (size_t) -# define YYSIZE_T size_t -#endif -#if ! defined (YYSIZE_T) -# if defined (__STDC__) || defined (__cplusplus) -# include <stddef.h> /* INFRINGES ON USER NAME SPACE */ -# define YYSIZE_T size_t -# endif -#endif -#if ! defined (YYSIZE_T) -# define YYSIZE_T unsigned int -#endif - -#define yyerrok (yyerrstatus = 0) -#define yyclearin (yychar = YYEMPTY) -#define YYEMPTY (-2) -#define YYEOF 0 - -#define YYACCEPT goto yyacceptlab -#define YYABORT goto yyabortlab -#define YYERROR goto yyerrlab1 - - -/* Like YYERROR except do call yyerror. This remains here temporarily - to ease the transition to the new meaning of YYERROR, for GCC. - Once GCC version 2 has supplanted version 1, this can go. */ - -#define YYFAIL goto yyerrlab - -#define YYRECOVERING() (!!yyerrstatus) - -#define YYBACKUP(Token, Value) \ -do \ - if (yychar == YYEMPTY && yylen == 1) \ - { \ - yychar = (Token); \ - yylval = (Value); \ - yytoken = YYTRANSLATE (yychar); \ - YYPOPSTACK; \ - goto yybackup; \ - } \ - else \ - { \ - yyerror ("syntax error: cannot back up");\ - YYERROR; \ - } \ -while (0) - -#define YYTERROR 1 -#define YYERRCODE 256 - -/* YYLLOC_DEFAULT -- Compute the default location (before the actions - are run). */ - -#ifndef YYLLOC_DEFAULT -# define YYLLOC_DEFAULT(Current, Rhs, N) \ - Current.first_line = Rhs[1].first_line; \ - Current.first_column = Rhs[1].first_column; \ - Current.last_line = Rhs[N].last_line; \ - Current.last_column = Rhs[N].last_column; -#endif - -/* YYLEX -- calling `yylex' with the right arguments. */ - -#ifdef YYLEX_PARAM -# define YYLEX yylex (YYLEX_PARAM) -#else -# define YYLEX yylex () -#endif - -/* Enable debugging if requested. */ -#if YYDEBUG - -# ifndef YYFPRINTF -# include <stdio.h> /* INFRINGES ON USER NAME SPACE */ -# define YYFPRINTF fprintf -# endif - -# define YYDPRINTF(Args) \ -do { \ - if (yydebug) \ - YYFPRINTF Args; \ -} while (0) - -# define YYDSYMPRINT(Args) \ -do { \ - if (yydebug) \ - yysymprint Args; \ -} while (0) - -# define YYDSYMPRINTF(Title, Token, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yysymprint (stderr, \ - Token, Value); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) - -/*------------------------------------------------------------------. -| yy_stack_print -- Print the state stack from its BOTTOM up to its | -| TOP (cinluded). | -`------------------------------------------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yy_stack_print (short *bottom, short *top) -#else -static void -yy_stack_print (bottom, top) - short *bottom; - short *top; -#endif -{ - YYFPRINTF (stderr, "Stack now"); - for (/* Nothing. */; bottom <= top; ++bottom) - YYFPRINTF (stderr, " %d", *bottom); - YYFPRINTF (stderr, "\n"); -} - -# define YY_STACK_PRINT(Bottom, Top) \ -do { \ - if (yydebug) \ - yy_stack_print ((Bottom), (Top)); \ -} while (0) - - -/*------------------------------------------------. -| Report that the YYRULE is going to be reduced. | -`------------------------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yy_reduce_print (int yyrule) -#else -static void -yy_reduce_print (yyrule) - int yyrule; -#endif -{ - int yyi; - unsigned int yylineno = yyrline[yyrule]; - YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", - yyrule - 1, yylineno); - /* Print the symbols being reduced, and their result. */ - for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) - YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); - YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); -} - -# define YY_REDUCE_PRINT(Rule) \ -do { \ - if (yydebug) \ - yy_reduce_print (Rule); \ -} while (0) - -/* Nonzero means print parse trace. It is left uninitialized so that - multiple parsers can coexist. */ -int yydebug; -#else /* !YYDEBUG */ -# define YYDPRINTF(Args) -# define YYDSYMPRINT(Args) -# define YYDSYMPRINTF(Title, Token, Value, Location) -# define YY_STACK_PRINT(Bottom, Top) -# define YY_REDUCE_PRINT(Rule) -#endif /* !YYDEBUG */ - - -/* YYINITDEPTH -- initial size of the parser's stacks. */ -#ifndef YYINITDEPTH -# define YYINITDEPTH 200 -#endif - -/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only - if the built-in stack extension method is used). - - Do not make this value too large; the results are undefined if - SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) - evaluated with infinite-precision integer arithmetic. */ - -#if YYMAXDEPTH == 0 -# undef YYMAXDEPTH -#endif - -#ifndef YYMAXDEPTH -# define YYMAXDEPTH 10000 -#endif - - - -#if YYERROR_VERBOSE - -# ifndef yystrlen -# if defined (__GLIBC__) && defined (_STRING_H) -# define yystrlen strlen -# else -/* Return the length of YYSTR. */ -static YYSIZE_T -# if defined (__STDC__) || defined (__cplusplus) -yystrlen (const char *yystr) -# else -yystrlen (yystr) - const char *yystr; -# endif -{ - register const char *yys = yystr; - - while (*yys++ != '\0') - continue; - - return yys - yystr - 1; -} -# endif -# endif - -# ifndef yystpcpy -# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) -# define yystpcpy stpcpy -# else -/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in - YYDEST. */ -static char * -# if defined (__STDC__) || defined (__cplusplus) -yystpcpy (char *yydest, const char *yysrc) -# else -yystpcpy (yydest, yysrc) - char *yydest; - const char *yysrc; -# endif -{ - register char *yyd = yydest; - register const char *yys = yysrc; - - while ((*yyd++ = *yys++) != '\0') - continue; - - return yyd - 1; -} -# endif -# endif - -#endif /* !YYERROR_VERBOSE */ - - - -#if YYDEBUG -/*--------------------------------. -| Print this symbol on YYOUTPUT. | -`--------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) -#else -static void -yysymprint (yyoutput, yytype, yyvaluep) - FILE *yyoutput; - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; - - if (yytype < YYNTOKENS) - { - YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); -# ifdef YYPRINT - YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); -# endif - } - else - YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); - - switch (yytype) - { - default: - break; - } - YYFPRINTF (yyoutput, ")"); -} - -#endif /* ! YYDEBUG */ -/*-----------------------------------------------. -| Release the memory associated to this symbol. | -`-----------------------------------------------*/ - -#if defined (__STDC__) || defined (__cplusplus) -static void -yydestruct (int yytype, YYSTYPE *yyvaluep) -#else -static void -yydestruct (yytype, yyvaluep) - int yytype; - YYSTYPE *yyvaluep; -#endif -{ - /* Pacify ``unused variable'' warnings. */ - (void) yyvaluep; - - switch (yytype) - { - - default: - break; - } -} - - -/* Prevent warnings from -Wmissing-prototypes. */ - -#ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) -int yyparse (void *YYPARSE_PARAM); -# else -int yyparse (); -# endif -#else /* ! YYPARSE_PARAM */ -#if defined (__STDC__) || defined (__cplusplus) -int yyparse (void); -#else -int yyparse (); -#endif -#endif /* ! YYPARSE_PARAM */ - - - -/* The lookahead symbol. */ -int yychar; - -/* The semantic value of the lookahead symbol. */ -YYSTYPE yylval; - -/* Number of syntax errors so far. */ -int yynerrs; - - - -/*----------. -| yyparse. | -`----------*/ - -#ifdef YYPARSE_PARAM -# if defined (__STDC__) || defined (__cplusplus) -int yyparse (void *YYPARSE_PARAM) -# else -int yyparse (YYPARSE_PARAM) - void *YYPARSE_PARAM; -# endif -#else /* ! YYPARSE_PARAM */ -#if defined (__STDC__) || defined (__cplusplus) -int -yyparse (void) -#else -int -yyparse () - -#endif -#endif -{ - - register int yystate; - register int yyn; - int yyresult; - /* Number of tokens to shift before error messages enabled. */ - int yyerrstatus; - /* Lookahead token as an internal (translated) token number. */ - int yytoken = 0; - - /* Three stacks and their tools: - `yyss': related to states, - `yyvs': related to semantic values, - `yyls': related to locations. - - Refer to the stacks thru separate pointers, to allow yyoverflow - to reallocate them elsewhere. */ - - /* The state stack. */ - short yyssa[YYINITDEPTH]; - short *yyss = yyssa; - register short *yyssp; - - /* The semantic value stack. */ - YYSTYPE yyvsa[YYINITDEPTH]; - YYSTYPE *yyvs = yyvsa; - register YYSTYPE *yyvsp; - - - -#define YYPOPSTACK (yyvsp--, yyssp--) - - YYSIZE_T yystacksize = YYINITDEPTH; - - /* The variables used to return semantic value and location from the - action routines. */ - YYSTYPE yyval; - - - /* When reducing, the number of symbols on the RHS of the reduced - rule. */ - int yylen; - - YYDPRINTF ((stderr, "Starting parse\n")); - - 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. - The wasted elements are never initialized. */ - - yyssp = yyss; - yyvsp = yyvs; - - goto yysetstate; - -/*------------------------------------------------------------. -| yynewstate -- Push a new state, which is found in yystate. | -`------------------------------------------------------------*/ - yynewstate: - /* In all cases, when you get here, the value and location stacks - have just been pushed. so pushing a state here evens the stacks. - */ - yyssp++; - - yysetstate: - *yyssp = yystate; - - if (yyss + yystacksize - 1 <= yyssp) - { - /* Get the current used size of the three stacks, in elements. */ - YYSIZE_T yysize = yyssp - yyss + 1; - -#ifdef yyoverflow - { - /* 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; - - - /* Each stack pointer address is followed by the size of the - data in use in that stack, in bytes. This used to be a - conditional around just the two extra args, but that might - be undefined if yyoverflow is a macro. */ - yyoverflow ("parser stack overflow", - &yyss1, yysize * sizeof (*yyssp), - &yyvs1, yysize * sizeof (*yyvsp), - - &yystacksize); - - yyss = yyss1; - yyvs = yyvs1; - } -#else /* no yyoverflow */ -# ifndef YYSTACK_RELOCATE - goto yyoverflowlab; -# else - /* Extend the stack our own way. */ - if (YYMAXDEPTH <= yystacksize) - goto yyoverflowlab; - yystacksize *= 2; - if (YYMAXDEPTH < yystacksize) - yystacksize = YYMAXDEPTH; - - { - short *yyss1 = yyss; - union yyalloc *yyptr = - (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); - if (! yyptr) - goto yyoverflowlab; - YYSTACK_RELOCATE (yyss); - YYSTACK_RELOCATE (yyvs); - -# undef YYSTACK_RELOCATE - if (yyss1 != yyssa) - YYSTACK_FREE (yyss1); - } -# endif -#endif /* no yyoverflow */ - - yyssp = yyss + yysize - 1; - yyvsp = yyvs + yysize - 1; - - - YYDPRINTF ((stderr, "Stack size increased to %lu\n", - (unsigned long int) yystacksize)); - - if (yyss + yystacksize - 1 <= yyssp) - YYABORT; - } - - YYDPRINTF ((stderr, "Entering state %d\n", yystate)); - - goto yybackup; - -/*-----------. -| yybackup. | -`-----------*/ -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 == YYPACT_NINF) - goto yydefault; - - /* Not known => get a lookahead token if don't already have one. */ - - /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ - if (yychar == YYEMPTY) - { - YYDPRINTF ((stderr, "Reading a token: ")); - yychar = YYLEX; - } - - if (yychar <= YYEOF) - { - yychar = yytoken = YYEOF; - YYDPRINTF ((stderr, "Now at end of input.\n")); - } - else - { - yytoken = YYTRANSLATE (yychar); - YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); - } - - /* If the proper action on seeing token YYTOKEN is to reduce or to - detect an error, take that action. */ - yyn += yytoken; - if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) - goto yydefault; - yyn = yytable[yyn]; - if (yyn <= 0) - { - if (yyn == 0 || yyn == YYTABLE_NINF) - goto yyerrlab; - yyn = -yyn; - goto yyreduce; - } - - if (yyn == YYFINAL) - YYACCEPT; - - /* Shift the lookahead token. */ - YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); - - /* 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; - - -/*-----------------------------------------------------------. -| yydefault -- do the default action for the current state. | -`-----------------------------------------------------------*/ -yydefault: - yyn = yydefact[yystate]; - if (yyn == 0) - goto yyerrlab; - goto yyreduce; - - -/*-----------------------------. -| yyreduce -- Do a reduction. | -`-----------------------------*/ -yyreduce: - /* yyn is the number of a rule to reduce with. */ - yylen = yyr2[yyn]; - - /* If YYLEN is nonzero, implement the default value of the action: - `$$ = $1'. - - Otherwise, the following line sets YYVAL to garbage. - This behavior is undocumented and Bison - users should not rely upon it. Assigning to YYVAL - unconditionally makes the parser a bit smaller, and it avoids a - GCC warning that YYVAL may be used uninitialized. */ - yyval = yyvsp[1-yylen]; - - - YY_REDUCE_PRINT (yyn); - switch (yyn) - { - case 3: -#line 386 "goom_script_yacc.y" - { gsl_append(yyvsp[0].nPtr); } - break; - - case 8: -#line 396 "goom_script_yacc.y" - { gsl_append(new_function_intro(yyvsp[-1].strValue)); } - break; - - case 9: -#line 397 "goom_script_yacc.y" - { gsl_append(new_function_outro()); } - break; - - case 10: -#line 399 "goom_script_yacc.y" - { yyval.nPtr = new_set(yyvsp[-3].nPtr,yyvsp[-1].nPtr); } - break; - - case 11: -#line 400 "goom_script_yacc.y" - { yyval.nPtr = new_float_decl(new_var(yyvsp[-3].strValue)); - yyval.nPtr->unode.opr.next = new_set(new_var(yyvsp[-3].strValue), yyvsp[-1].nPtr); } - break; - - case 12: -#line 402 "goom_script_yacc.y" - { yyval.nPtr = new_float_decl(new_var(yyvsp[-1].strValue)); } - break; - - case 13: -#line 403 "goom_script_yacc.y" - { yyval.nPtr = new_int_decl(new_var(yyvsp[-1].strValue)); } - break; - - case 14: -#line 404 "goom_script_yacc.y" - { yyval.nPtr = new_if(yyvsp[-3].nPtr,yyvsp[0].nPtr); } - break; - - case 15: -#line 405 "goom_script_yacc.y" - { lastNode = yyvsp[-2].nPtr->unode.opr.op[1]; yyval.nPtr=yyvsp[-2].nPtr; } - break; - - case 16: -#line 406 "goom_script_yacc.y" - { yyval.nPtr = new_call(yyvsp[-1].strValue); } - break; - - case 17: -#line 407 "goom_script_yacc.y" - { yyval.nPtr = new_nop("nop"); } - break; - - case 18: -#line 410 "goom_script_yacc.y" - { yyval.nPtr = new_block(lastNode); lastNode = yyval.nPtr->unode.opr.op[0]; } - break; - - case 19: -#line 413 "goom_script_yacc.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 20: -#line 414 "goom_script_yacc.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 21: -#line 415 "goom_script_yacc.y" - { yyval.nPtr = new_mul(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 22: -#line 416 "goom_script_yacc.y" - { yyval.nPtr = new_div(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 23: -#line 417 "goom_script_yacc.y" - { yyval.nPtr = new_add(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 24: -#line 418 "goom_script_yacc.y" - { yyval.nPtr = new_sub(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 25: -#line 419 "goom_script_yacc.y" - { yyval.nPtr = new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 26: -#line 420 "goom_script_yacc.y" - { yyval.nPtr = new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 27: -#line 421 "goom_script_yacc.y" - { yyval.nPtr = new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr); } - break; - - case 28: -#line 422 "goom_script_yacc.y" - { yyval.nPtr = yyvsp[-1].nPtr; } - break; - - case 29: -#line 425 "goom_script_yacc.y" - { yyval.nPtr = new_var(yyvsp[0].strValue); } - break; - - case 30: -#line 426 "goom_script_yacc.y" - { yyval.nPtr = new_read_param(yyvsp[0].strValue); } - break; - - case 31: -#line 429 "goom_script_yacc.y" - { yyval.nPtr = new_var(yyvsp[0].strValue); } - break; - - case 32: -#line 430 "goom_script_yacc.y" - { yyval.nPtr = new_param(yyvsp[0].strValue); } - break; - - case 33: -#line 433 "goom_script_yacc.y" - { yyval.nPtr = new_constFloat(yyvsp[0].strValue); } - break; - - case 34: -#line 434 "goom_script_yacc.y" - { yyval.nPtr = new_constInt(yyvsp[0].strValue); } - break; - - - } - -/* Line 999 of yacc.c. */ -#line 1536 "y.tab.c" - - yyvsp -= yylen; - yyssp -= yylen; - - - YY_STACK_PRINT (yyss, yyssp); - - *++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 - YYNTOKENS] + *yyssp; - if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) - yystate = yytable[yystate]; - else - yystate = yydefgoto[yyn - YYNTOKENS]; - - goto yynewstate; - - -/*------------------------------------. -| yyerrlab -- here on detecting error | -`------------------------------------*/ -yyerrlab: - /* If not already recovering from an error, report this error. */ - if (!yyerrstatus) - { - ++yynerrs; -#if YYERROR_VERBOSE - yyn = yypact[yystate]; - - if (YYPACT_NINF < yyn && yyn < YYLAST) - { - YYSIZE_T yysize = 0; - int yytype = YYTRANSLATE (yychar); - char *yymsg; - int yyx, yycount; - - yycount = 0; - /* Start YYX at -YYN if negative to avoid negative indexes in - YYCHECK. */ - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - yysize += yystrlen (yytname[yyx]) + 15, yycount++; - yysize += yystrlen ("syntax error, unexpected ") + 1; - yysize += yystrlen (yytname[yytype]); - yymsg = (char *) YYSTACK_ALLOC (yysize); - if (yymsg != 0) - { - char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); - yyp = yystpcpy (yyp, yytname[yytype]); - - if (yycount < 5) - { - yycount = 0; - for (yyx = yyn < 0 ? -yyn : 0; - yyx < (int) (sizeof (yytname) / sizeof (char *)); - yyx++) - if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) - { - const char *yyq = ! yycount ? ", expecting " : " or "; - yyp = yystpcpy (yyp, yyq); - yyp = yystpcpy (yyp, yytname[yyx]); - yycount++; - } - } - yyerror (yymsg); - YYSTACK_FREE (yymsg); - } - else - yyerror ("syntax error; also virtual memory exhausted"); - } - else -#endif /* YYERROR_VERBOSE */ - yyerror ("syntax error"); - } - - - - 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) - { - /* Pop the error token. */ - YYPOPSTACK; - /* Pop the rest of the stack. */ - while (yyss < yyssp) - { - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[*yyssp], yyvsp); - YYPOPSTACK; - } - YYABORT; - } - - YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); - yydestruct (yytoken, &yylval); - yychar = YYEMPTY; - - } - - /* Else will try to reuse lookahead token after shifting the error - token. */ - goto yyerrlab1; - - -/*----------------------------------------------------. -| yyerrlab1 -- error raised explicitly by an action. | -`----------------------------------------------------*/ -yyerrlab1: - yyerrstatus = 3; /* Each real token shifted decrements this. */ - - for (;;) - { - yyn = yypact[yystate]; - if (yyn != YYPACT_NINF) - { - yyn += YYTERROR; - if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) - { - yyn = yytable[yyn]; - if (0 < yyn) - break; - } - } - - /* Pop the current state because it cannot handle the error token. */ - if (yyssp == yyss) - YYABORT; - - YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); - yydestruct (yystos[yystate], yyvsp); - yyvsp--; - yystate = *--yyssp; - - YY_STACK_PRINT (yyss, yyssp); - } - - if (yyn == YYFINAL) - YYACCEPT; - - YYDPRINTF ((stderr, "Shifting error token, ")); - - *++yyvsp = yylval; - - - yystate = yyn; - goto yynewstate; - - -/*-------------------------------------. -| yyacceptlab -- YYACCEPT comes here. | -`-------------------------------------*/ -yyacceptlab: - yyresult = 0; - goto yyreturn; - -/*-----------------------------------. -| yyabortlab -- YYABORT comes here. | -`-----------------------------------*/ -yyabortlab: - yyresult = 1; - goto yyreturn; - -#ifndef yyoverflow -/*----------------------------------------------. -| yyoverflowlab -- parser overflow comes here. | -`----------------------------------------------*/ -yyoverflowlab: - yyerror ("parser stack overflow"); - yyresult = 2; - /* Fall through. */ -#endif - -yyreturn: -#ifndef yyoverflow - if (yyss != yyssa) - YYSTACK_FREE (yyss); -#endif - return yyresult; -} - - -#line 437 "goom_script_yacc.y" - - - NodeType *nodeNew(const char *str, int type) { - NodeType *node = (NodeType*)malloc(sizeof(NodeType)); - node->type = type; - node->str = (char*)malloc(strlen(str)+1); - strcpy(node->str, str); - return node; - } - - void nodeFreeInternals(NodeType *node) { - free(node->str); - } - - void nodeFree(NodeType *node) { - nodeFreeInternals(node); - free(node); - } - - NodeType *new_constInt(const char *str) { - NodeType *node = nodeNew(str, CONST_INT_NODE); - node->unode.constInt.val = atoi(str); - return node; - } - - NodeType *new_constFloat(const char *str) { - NodeType *node = nodeNew(str, CONST_FLOAT_NODE); - node->unode.constFloat.val = atof(str); - return node; - } - - NodeType *new_var(const char *str) { - NodeType *node = nodeNew(str, VAR_NODE); - return node; - } - - NodeType *new_read_param(const char *str) { - NodeType *node = nodeNew(str, READ_PARAM_NODE); - return node; - } - - NodeType *new_param(const char *str) { - NodeType *node = nodeNew(str, PARAM_NODE); - return node; - } - - NodeType *new_nop(const char *str) { - NodeType *node = new_op(str, EMPTY_NODE, 0); - return node; - } - - NodeType *new_op(const char *str, int type, int nbOp) { - int i; - NodeType *node = nodeNew(str, OPR_NODE); - node->unode.opr.next = 0; - node->unode.opr.type = type; - node->unode.opr.nbOp = nbOp; - for (i=0;i<nbOp;++i) node->unode.opr.op[i] = 0; - return node; - } - -void yyerror(char *str) { - fprintf(stderr, "GSL ERROR: %s\n", str); -} - - diff --git a/src/post/goom/goom_script_yacc.h b/src/post/goom/goom_script_yacc.h deleted file mode 100644 index e35d93f82..000000000 --- a/src/post/goom/goom_script_yacc.h +++ /dev/null @@ -1,71 +0,0 @@ -/* A Bison parser, made by GNU Bison 1.875a. */ - -/* Skeleton parser for Yacc-like parsing with Bison, - Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ - -/* As a special exception, when this file is copied by Bison into a - Bison output file, you may use that output file without restriction. - This special exception was added by the Free Software Foundation - in version 1.24 of Bison. */ - -/* Tokens. */ -#ifndef YYTOKENTYPE -# define YYTOKENTYPE - /* Put the tokens into the symbol table, so that GDB and other debuggers - know about them. */ - enum yytokentype { - TYPE_INTEGER = 258, - TYPE_FLOAT = 259, - TYPE_VAR = 260, - TYPE_PARAM = 261, - INT_TK = 262, - FLOAT_TK = 263, - ARROW_TK = 264 - }; -#endif -#define TYPE_INTEGER 258 -#define TYPE_FLOAT 259 -#define TYPE_VAR 260 -#define TYPE_PARAM 261 -#define INT_TK 262 -#define FLOAT_TK 263 -#define ARROW_TK 264 - - - - -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 361 "goom_script_yacc.y" -typedef union YYSTYPE { - int intValue; - float floatValue; - char charValue; - char strValue[2048]; - NodeType *nPtr; - } YYSTYPE; -/* Line 1240 of yacc.c. */ -#line 63 "y.tab.h" -# define yystype YYSTYPE /* obsolescent; will be withdrawn */ -# define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 -#endif - -extern YYSTYPE yylval; - - - diff --git a/src/post/goom/goom_tools.c b/src/post/goom/goom_tools.c index 45bbca3f0..ec7ec1934 100644 --- a/src/post/goom/goom_tools.c +++ b/src/post/goom/goom_tools.c @@ -3,7 +3,6 @@ GoomRandom *goom_random_init(int i) { GoomRandom *grandom = (GoomRandom*)malloc(sizeof(GoomRandom)); - srand (i); grandom->pos = 1; goom_random_update_array(grandom, GOOM_NB_RAND); return grandom; diff --git a/src/post/goom/goom_typedefs.h b/src/post/goom/goom_typedefs.h index 0abbb6b1c..76036504b 100644 --- a/src/post/goom/goom_typedefs.h +++ b/src/post/goom/goom_typedefs.h @@ -7,6 +7,5 @@ typedef struct _GMLINE GMLine; typedef struct _GMUNITPOINTER GMUnitPointer; typedef struct _ZOOM_FILTER_DATA ZoomFilterData; typedef struct _VISUAL_FX VisualFX; -typedef struct _GoomScriptScanner GoomScriptScanner; #endif diff --git a/src/post/goom/goomsl.c b/src/post/goom/goomsl.c new file mode 100644 index 000000000..c136b657d --- /dev/null +++ b/src/post/goom/goomsl.c @@ -0,0 +1,1189 @@ +#include <math.h> +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include "goomsl.h" +#include "goomsl_private.h" +#include "goomsl_yacc.h" + +/* #define TRACE_SCRIPT */ + + /* {{{ definition of the instructions number */ +#define INSTR_SETI_VAR_INTEGER 1 +#define INSTR_SETI_VAR_VAR 2 +#define INSTR_SETF_VAR_FLOAT 3 +#define INSTR_SETF_VAR_VAR 4 +#define INSTR_NOP 5 +/* #define INSTR_JUMP 6 */ +#define INSTR_SETP_VAR_PTR 7 +#define INSTR_SETP_VAR_VAR 8 +#define INSTR_SUBI_VAR_INTEGER 9 +#define INSTR_SUBI_VAR_VAR 10 +#define INSTR_SUBF_VAR_FLOAT 11 +#define INSTR_SUBF_VAR_VAR 12 +#define INSTR_ISLOWERF_VAR_VAR 13 +#define INSTR_ISLOWERF_VAR_FLOAT 14 +#define INSTR_ISLOWERI_VAR_VAR 15 +#define INSTR_ISLOWERI_VAR_INTEGER 16 +#define INSTR_ADDI_VAR_INTEGER 17 +#define INSTR_ADDI_VAR_VAR 18 +#define INSTR_ADDF_VAR_FLOAT 19 +#define INSTR_ADDF_VAR_VAR 20 +#define INSTR_MULI_VAR_INTEGER 21 +#define INSTR_MULI_VAR_VAR 22 +#define INSTR_MULF_VAR_FLOAT 23 +#define INSTR_MULF_VAR_VAR 24 +#define INSTR_DIVI_VAR_INTEGER 25 +#define INSTR_DIVI_VAR_VAR 26 +#define INSTR_DIVF_VAR_FLOAT 27 +#define INSTR_DIVF_VAR_VAR 28 +/* #define INSTR_JZERO 29 */ +#define INSTR_ISEQUALP_VAR_VAR 30 +#define INSTR_ISEQUALP_VAR_PTR 31 +#define INSTR_ISEQUALI_VAR_VAR 32 +#define INSTR_ISEQUALI_VAR_INTEGER 33 +#define INSTR_ISEQUALF_VAR_VAR 34 +#define INSTR_ISEQUALF_VAR_FLOAT 35 +/* #define INSTR_CALL 36 */ +/* #define INSTR_RET 37 */ +/* #define INSTR_EXT_CALL 38 */ +#define INSTR_NOT_VAR 39 +/* #define INSTR_JNZERO 40 */ + /* }}} */ +/* {{{ definition of the validation error types */ +static const char *VALIDATE_OK = "ok"; +#define VALIDATE_ERROR "error while validating " +#define VALIDATE_TODO "todo" +#define VALIDATE_SYNTHAX_ERROR "synthax error" +#define VALIDATE_NO_SUCH_INT "no such integer variable" +#define VALIDATE_NO_SUCH_VAR "no such variable" +#define VALIDATE_NO_SUCH_DEST_VAR "no such destination variable" +#define VALIDATE_NO_SUCH_SRC_VAR "no such src variable" +/* }}} */ + + /***********************************/ + /* PROTOTYPE OF INTERNAL FUNCTIONS */ +/***********************************/ + +/* {{{ */ +static void gsl_instr_free(Instruction *_this); +static const char *gsl_instr_validate(Instruction *_this); +static void gsl_instr_display(Instruction *_this); + +static InstructionFlow *iflow_new(void); +static void iflow_add_instr(InstructionFlow *_this, Instruction *instr); +static void iflow_clean(InstructionFlow *_this); +static void iflow_free(InstructionFlow *_this); +static void iflow_execute(FastInstructionFlow *_this, GoomSL *gsl); +/* }}} */ + + /************************************/ + /* DEFINITION OF INTERNAL FUNCTIONS */ +/************************************/ + +void iflow_free(InstructionFlow *_this) +{ /* {{{ */ + goom_hash_free(_this->labels); + free(_this); /*TODO: finir cette fonction */ +} /* }}} */ + +void iflow_clean(InstructionFlow *_this) +{ /* {{{ */ + /* TODO: clean chaque instruction du flot */ + _this->number = 0; + goom_hash_free(_this->labels); + _this->labels = goom_hash_new(); +} /* }}} */ + +InstructionFlow *iflow_new(void) +{ /* {{{ */ + InstructionFlow *_this = (InstructionFlow*)malloc(sizeof(InstructionFlow)); + _this->number = 0; + _this->tabsize = 6; + _this->instr = (Instruction**)malloc(_this->tabsize * sizeof(Instruction*)); + _this->labels = goom_hash_new(); + + return _this; +} /* }}} */ + +void iflow_add_instr(InstructionFlow *_this, Instruction *instr) +{ /* {{{ */ + if (_this->number == _this->tabsize) { + _this->tabsize *= 2; + _this->instr = (Instruction**)realloc(_this->instr, _this->tabsize * sizeof(Instruction*)); + } + _this->instr[_this->number] = instr; + instr->address = _this->number; + _this->number++; +} /* }}} */ + +void gsl_instr_set_namespace(Instruction *_this, GoomHash *ns) +{ /* {{{ */ + if (_this->cur_param <= 0) { + fprintf(stderr, "ERROR: Line %d, No more params to instructions\n", _this->line_number); + exit(1); + } + _this->vnamespace[_this->cur_param-1] = ns; +} /* }}} */ + +void gsl_instr_add_param(Instruction *instr, char *param, int type) +{ /* {{{ */ + int len; + if (instr==NULL) + return; + if (instr->cur_param==0) + return; + --instr->cur_param; + len = strlen(param); + instr->params[instr->cur_param] = (char*)malloc(len+1); + strcpy(instr->params[instr->cur_param], param); + instr->types[instr->cur_param] = type; + if (instr->cur_param == 0) { + + const char *result = gsl_instr_validate(instr); + if (result != VALIDATE_OK) { + printf("ERROR: Line %d: ", instr->parent->num_lines + 1); + gsl_instr_display(instr); + printf("... %s\n", result); + instr->parent->compilationOK = 0; + exit(1); + } + +#if USE_JITC_X86 + iflow_add_instr(instr->parent->iflow, instr); +#else + if (instr->id != INSTR_NOP) + iflow_add_instr(instr->parent->iflow, instr); + else + gsl_instr_free(instr); +#endif + } +} /* }}} */ + +Instruction *gsl_instr_init(GoomSL *parent, const char *name, int id, int nb_param, int line_number) +{ /* {{{ */ + Instruction *instr = (Instruction*)malloc(sizeof(Instruction)); + instr->params = (char**)malloc(nb_param*sizeof(char*)); + instr->vnamespace = (GoomHash**)malloc(nb_param*sizeof(GoomHash*)); + instr->types = (int*)malloc(nb_param*sizeof(int)); + instr->cur_param = instr->nb_param = nb_param; + instr->parent = parent; + instr->id = id; + instr->name = name; + instr->jump_label = NULL; + instr->line_number = line_number; + return instr; +} /* }}} */ + +void gsl_instr_free(Instruction *_this) +{ /* {{{ */ + int i; + free(_this->types); + for (i=_this->cur_param; i<_this->nb_param; ++i) + free(_this->params[i]); + free(_this->params); + free(_this); +} /* }}} */ + +void gsl_instr_display(Instruction *_this) +{ /* {{{ */ + int i=_this->nb_param-1; + printf("%s", _this->name); + while(i>=_this->cur_param) { + printf(" %s", _this->params[i]); + --i; + } +} /* }}} */ + + /****************************************/ + /* VALIDATION OF INSTRUCTION PARAMETERS */ +/****************************************/ + +static const char *validate_v_v(Instruction *_this) +{ /* {{{ */ + _this->data.v_v.var_dest = goom_hash_get(_this->vnamespace[1], _this->params[1]); + _this->data.v_v.var_src = goom_hash_get(_this->vnamespace[0], _this->params[0]); + + if (_this->data.v_v.var_dest == NULL) { + return VALIDATE_NO_SUCH_DEST_VAR; + } + if (_this->data.v_v.var_src == NULL) { + return VALIDATE_NO_SUCH_SRC_VAR; + } + return VALIDATE_OK; +} /* }}} */ + +static const char *validate_v_i(Instruction *_this) +{ /* {{{ */ + _this->data.v_i.var = goom_hash_get(_this->vnamespace[1], _this->params[1]); + _this->data.v_i.value = strtol(_this->params[0],NULL,0); + + if (_this->data.v_i.var == NULL) { + return VALIDATE_NO_SUCH_INT; + } + return VALIDATE_OK; +} /* }}} */ + +static const char *validate_v_p(Instruction *_this) +{ /* {{{ */ + _this->data.v_p.var = goom_hash_get(_this->vnamespace[1], _this->params[1]); + _this->data.v_p.value = strtol(_this->params[0],NULL,0); + + if (_this->data.v_p.var == NULL) { + return VALIDATE_NO_SUCH_INT; + } + return VALIDATE_OK; +} /* }}} */ + +static const char *validate_v_f(Instruction *_this) +{ /* {{{ */ + _this->data.v_f.var = goom_hash_get(_this->vnamespace[1], _this->params[1]); + _this->data.v_f.value = atof(_this->params[0]); + + if (_this->data.v_f.var == NULL) { + return VALIDATE_NO_SUCH_VAR; + } + return VALIDATE_OK; +} /* }}} */ + +static const char *validate(Instruction *_this, int vf_f_id, int vf_v_id, int vi_i_id, int vi_v_id, int vp_p_id, int vp_v_id) +{ /* {{{ */ + if ((_this->types[1] == TYPE_FVAR) && (_this->types[0] == TYPE_FLOAT)) { + _this->id = vf_f_id; + return validate_v_f(_this); + } + else if ((_this->types[1] == TYPE_FVAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = vf_v_id; + return validate_v_v(_this); + } + else if ((_this->types[1] == TYPE_IVAR) && (_this->types[0] == TYPE_INTEGER)) { + _this->id = vi_i_id; + return validate_v_i(_this); + } + else if ((_this->types[1] == TYPE_IVAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = vi_v_id; + return validate_v_v(_this); + } + else if ((_this->types[1] == TYPE_PVAR) && (_this->types[0] == TYPE_PTR)) { + if (vp_p_id == INSTR_NOP) return VALIDATE_ERROR; + _this->id = vp_p_id; + return validate_v_p(_this); + } + else if ((_this->types[1] == TYPE_PVAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = vp_v_id; + if (vp_v_id == INSTR_NOP) return VALIDATE_ERROR; + return validate_v_v(_this); + } + return VALIDATE_ERROR; +} /* }}} */ + +const char *gsl_instr_validate(Instruction *_this) +{ /* {{{ */ + if (_this->id != INSTR_EXT_CALL) { + int i; + for (i=_this->nb_param-1;i>=0;--i) + if (_this->types[i] == TYPE_VAR) { + HashValue *val = goom_hash_get(_this->vnamespace[i], _this->params[i]); + if (val && val->i == INSTR_INT) + _this->types[i] = TYPE_IVAR; + else if (val && val->i == INSTR_FLOAT) + _this->types[i] = TYPE_FVAR; + else if (val && val->i == INSTR_PTR) + _this->types[i] = TYPE_PVAR; + else fprintf(stderr,"WARNING: Line %d, %s has no namespace\n", _this->line_number, _this->params[i]); + break; + } + } + + switch (_this->id) { + + /* set */ + case INSTR_SET: + return validate(_this, + INSTR_SETF_VAR_FLOAT, INSTR_SETF_VAR_VAR, + INSTR_SETI_VAR_INTEGER, INSTR_SETI_VAR_VAR, + INSTR_SETP_VAR_PTR, INSTR_SETP_VAR_VAR); + + /* extcall */ + case INSTR_EXT_CALL: + if (_this->types[0] == TYPE_VAR) { + HashValue *fval = goom_hash_get(_this->parent->functions, _this->params[0]); + if (fval) { + _this->data.external_function = (struct _ExternalFunctionStruct*)fval->ptr; + return VALIDATE_OK; + } + } + return VALIDATE_ERROR; + + /* call */ + case INSTR_CALL: + if (_this->types[0] == TYPE_LABEL) { + _this->jump_label = _this->params[0]; + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* ret */ + case INSTR_RET: + return VALIDATE_OK; + + /* jump */ + case INSTR_JUMP: + + if (_this->types[0] == TYPE_LABEL) { + _this->jump_label = _this->params[0]; + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* jzero / jnzero */ + case INSTR_JZERO: + case INSTR_JNZERO: + + if (_this->types[0] == TYPE_LABEL) { + _this->jump_label = _this->params[0]; + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* label */ + case INSTR_LABEL: + + if (_this->types[0] == TYPE_LABEL) { + _this->id = INSTR_NOP; + _this->nop_label = _this->params[0]; + goom_hash_put_int(_this->parent->iflow->labels, _this->params[0], _this->parent->iflow->number); + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* isequal */ + case INSTR_ISEQUAL: + return validate(_this, + INSTR_ISEQUALF_VAR_FLOAT, INSTR_ISEQUALF_VAR_VAR, + INSTR_ISEQUALI_VAR_INTEGER, INSTR_ISEQUALI_VAR_VAR, + INSTR_ISEQUALP_VAR_PTR, INSTR_ISEQUALP_VAR_VAR); + + /* not */ + case INSTR_NOT: + _this->id = INSTR_NOT_VAR; + return VALIDATE_OK; + + /* islower */ + case INSTR_ISLOWER: + return validate(_this, + INSTR_ISLOWERF_VAR_FLOAT, INSTR_ISLOWERF_VAR_VAR, + INSTR_ISLOWERI_VAR_INTEGER, INSTR_ISLOWERI_VAR_VAR, + INSTR_NOP, INSTR_NOP); + + /* add */ + case INSTR_ADD: + return validate(_this, + INSTR_ADDF_VAR_FLOAT, INSTR_ADDF_VAR_VAR, + INSTR_ADDI_VAR_INTEGER, INSTR_ADDI_VAR_VAR, + INSTR_NOP, INSTR_NOP); + + /* mul */ + case INSTR_MUL: + return validate(_this, + INSTR_MULF_VAR_FLOAT, INSTR_MULF_VAR_VAR, + INSTR_MULI_VAR_INTEGER, INSTR_MULI_VAR_VAR, + INSTR_NOP, INSTR_NOP); + + /* sub */ + case INSTR_SUB: + return validate(_this, + INSTR_SUBF_VAR_FLOAT, INSTR_SUBF_VAR_VAR, + INSTR_SUBI_VAR_INTEGER, INSTR_SUBI_VAR_VAR, + INSTR_NOP, INSTR_NOP); + + /* div */ + case INSTR_DIV: + return validate(_this, + INSTR_DIVF_VAR_FLOAT, INSTR_DIVF_VAR_VAR, + INSTR_DIVI_VAR_INTEGER, INSTR_DIVI_VAR_VAR, + INSTR_NOP,INSTR_NOP); + + default: + return VALIDATE_TODO; + } + return VALIDATE_ERROR; +} /* }}} */ + + /*************/ + /* EXECUTION */ +/*************/ +void iflow_execute(FastInstructionFlow *_this, GoomSL *gsl) +{ /* {{{ */ + int flag = 0; + int ip = 0; + FastInstruction *instr = _this->instr; + int stack[0x10000]; + int stack_pointer = 0; + + stack[stack_pointer++] = -1; + + while (1) { +#ifdef TRACE_SCRIPT + printf("execute "); gsl_instr_display(instr[ip].proto); printf("\n"); +#endif + switch (instr[ip].id) { + + /* SET.I */ + case INSTR_SETI_VAR_INTEGER: + instr[ip].data.v_i.var->i = instr[ip].data.v_i.value; + ++ip; break; + + case INSTR_SETI_VAR_VAR: + instr[ip].data.v_v.var_dest->i = instr[ip].data.v_v.var_src->i; + ++ip; break; + + /* SET.F */ + case INSTR_SETF_VAR_FLOAT: + instr[ip].data.v_f.var->f = instr[ip].data.v_f.value; + ++ip; break; + + case INSTR_SETF_VAR_VAR: + instr[ip].data.v_v.var_dest->f = instr[ip].data.v_v.var_src->f; + ++ip; break; + + /* SET.P */ + case INSTR_SETP_VAR_VAR: + instr[ip].data.v_v.var_dest->ptr = instr[ip].data.v_v.var_src->ptr; + ++ip; break; + + case INSTR_SETP_VAR_PTR: + instr[ip].data.v_p.var->i = instr[ip].data.v_p.value; + ++ip; break; + + /* JUMP */ + case INSTR_JUMP: + ip += instr[ip].data.jump_offset; break; + + /* JZERO */ + case INSTR_JZERO: + ip += (flag ? 1 : instr[ip].data.jump_offset); break; + + case INSTR_NOP: + ++ip; break; + + /* ISEQUAL.P */ + case INSTR_ISEQUALP_VAR_VAR: + flag = (instr[ip].data.v_v.var_dest->i == instr[ip].data.v_v.var_src->i); + ++ip; break; + + case INSTR_ISEQUALP_VAR_PTR: + flag = (instr[ip].data.v_p.var->i == instr[ip].data.v_p.value); + ++ip; break; + + /* ISEQUAL.I */ + case INSTR_ISEQUALI_VAR_VAR: + flag = (instr[ip].data.v_v.var_dest->i == instr[ip].data.v_v.var_src->i); + ++ip; break; + + case INSTR_ISEQUALI_VAR_INTEGER: + flag = (instr[ip].data.v_i.var->i == instr[ip].data.v_i.value); + ++ip; break; + + /* ISEQUAL.F */ + case INSTR_ISEQUALF_VAR_VAR: + flag = (instr[ip].data.v_v.var_dest->f == instr[ip].data.v_v.var_src->f); + ++ip; break; + + case INSTR_ISEQUALF_VAR_FLOAT: + flag = (instr[ip].data.v_f.var->f == instr[ip].data.v_f.value); + ++ip; break; + + /* ISLOWER.I */ + case INSTR_ISLOWERI_VAR_VAR: + flag = (instr[ip].data.v_v.var_dest->i < instr[ip].data.v_v.var_src->i); + ++ip; break; + + case INSTR_ISLOWERI_VAR_INTEGER: + flag = (instr[ip].data.v_i.var->i < instr[ip].data.v_i.value); + ++ip; break; + + /* ISLOWER.F */ + case INSTR_ISLOWERF_VAR_VAR: + flag = (instr[ip].data.v_v.var_dest->f < instr[ip].data.v_v.var_src->f); + ++ip; break; + + case INSTR_ISLOWERF_VAR_FLOAT: + flag = (instr[ip].data.v_f.var->f < instr[ip].data.v_f.value); + ++ip; break; + + /* ADD.I */ + case INSTR_ADDI_VAR_VAR: + instr[ip].data.v_v.var_dest->i += instr[ip].data.v_v.var_src->i; + ++ip; break; + + case INSTR_ADDI_VAR_INTEGER: + instr[ip].data.v_i.var->i += instr[ip].data.v_i.value; + ++ip; break; + + /* ADD.F */ + case INSTR_ADDF_VAR_VAR: + instr[ip].data.v_v.var_dest->f += instr[ip].data.v_v.var_src->f; + ++ip; break; + + case INSTR_ADDF_VAR_FLOAT: + instr[ip].data.v_f.var->f += instr[ip].data.v_f.value; + ++ip; break; + + /* MUL.I */ + case INSTR_MULI_VAR_VAR: + instr[ip].data.v_v.var_dest->i *= instr[ip].data.v_v.var_src->i; + ++ip; break; + + case INSTR_MULI_VAR_INTEGER: + instr[ip].data.v_i.var->i *= instr[ip].data.v_i.value; + ++ip; break; + + /* MUL.F */ + case INSTR_MULF_VAR_FLOAT: + instr[ip].data.v_f.var->f *= instr[ip].data.v_f.value; + ++ip; break; + + case INSTR_MULF_VAR_VAR: + instr[ip].data.v_v.var_dest->f *= instr[ip].data.v_v.var_src->f; + ++ip; break; + + /* DIV.I */ + case INSTR_DIVI_VAR_VAR: + instr[ip].data.v_v.var_dest->i /= instr[ip].data.v_v.var_src->i; + ++ip; break; + + case INSTR_DIVI_VAR_INTEGER: + instr[ip].data.v_i.var->i /= instr[ip].data.v_i.value; + ++ip; break; + + /* DIV.F */ + case INSTR_DIVF_VAR_FLOAT: + instr[ip].data.v_f.var->f /= instr[ip].data.v_f.value; + ++ip; break; + + case INSTR_DIVF_VAR_VAR: + instr[ip].data.v_v.var_dest->f /= instr[ip].data.v_v.var_src->f; + ++ip; break; + + /* SUB.I */ + case INSTR_SUBI_VAR_VAR: + instr[ip].data.v_v.var_dest->i -= instr[ip].data.v_v.var_src->i; + ++ip; break; + + case INSTR_SUBI_VAR_INTEGER: + instr[ip].data.v_i.var->i -= instr[ip].data.v_i.value; + ++ip; break; + + /* SUB.F */ + case INSTR_SUBF_VAR_FLOAT: + instr[ip].data.v_f.var->f -= instr[ip].data.v_f.value; + ++ip; break; + + case INSTR_SUBF_VAR_VAR: + instr[ip].data.v_v.var_dest->f -= instr[ip].data.v_v.var_src->f; + ++ip; break; + + /* CALL */ + case INSTR_CALL: + stack[stack_pointer++] = ip + 1; + ip += instr[ip].data.jump_offset; break; + + /* RET */ + case INSTR_RET: + ip = stack[--stack_pointer]; + if (ip<0) return; + break; + + /* EXT_CALL */ + case INSTR_EXT_CALL: + instr[ip].data.external_function->function(gsl, gsl->vars, instr[ip].data.external_function->vars); + ++ip; break; + + /* NOT */ + case INSTR_NOT_VAR: + flag = !flag; + ++ip; break; + + /* JNZERO */ + case INSTR_JNZERO: + ip += (flag ? instr[ip].data.jump_offset : 1); break; + + default: + printf("NOT IMPLEMENTED : %d\n", instr[ip].id); + ++ip; + exit(1); + } + } +} /* }}} */ + +int gsl_malloc(GoomSL *_this, int size) +{ /* {{{ */ + if (_this->nbPtr >= _this->ptrArraySize) { + _this->ptrArraySize *= 2; + _this->ptrArray = (void**)realloc(_this->ptrArray, sizeof(void*) * _this->ptrArraySize); + } + _this->ptrArray[_this->nbPtr] = malloc(size); + return _this->nbPtr++; +} /* }}} */ + +void *gsl_get_ptr(GoomSL *_this, int id) +{ /* {{{ */ + if ((id>=0)&&(id<_this->nbPtr)) + return _this->ptrArray[id]; + fprintf(stderr,"INVALID GET PTR %d\n", id); + return NULL; +} /* }}} */ + +void gsl_free_ptr(GoomSL *_this, int id) +{ /* {{{ */ + if ((id>=0)&&(id<_this->nbPtr)) { + free(_this->ptrArray[id]); + _this->ptrArray[id] = 0; + } +} /* }}} */ + +void gsl_enternamespace(const char *name) +{ /* {{{ */ + HashValue *val = goom_hash_get(currentGoomSL->functions, name); + if (val) { + ExternalFunctionStruct *function = (ExternalFunctionStruct*)val->ptr; + currentGoomSL->currentNS++; + currentGoomSL->namespaces[currentGoomSL->currentNS] = function->vars; + } + else { + fprintf(stderr, "ERROR: Line %d, Could not find namespace: %s\n", currentGoomSL->num_lines, name); + exit(1); + } +} /* }}} */ + +void gsl_leavenamespace(void) +{ /* {{{ */ + currentGoomSL->currentNS--; +} /* }}} */ + +GoomHash *gsl_find_namespace(const char *name) +{ /* {{{ */ + int i; + for (i=currentGoomSL->currentNS;i>=0;--i) { + if (goom_hash_get(currentGoomSL->namespaces[i], name)) + return currentGoomSL->namespaces[i]; + } + return NULL; +} /* }}} */ + +void gsl_declare_task(const char *name) +{ /* {{{ */ + if (goom_hash_get(currentGoomSL->functions, name)) { + return; + } + else { + ExternalFunctionStruct *gef = (ExternalFunctionStruct*)malloc(sizeof(ExternalFunctionStruct)); + gef->function = 0; + gef->vars = goom_hash_new(); + gef->is_extern = 0; + goom_hash_put_ptr(currentGoomSL->functions, name, (void*)gef); + } +} /* }}} */ + +void gsl_declare_external_task(const char *name) +{ /* {{{ */ + if (goom_hash_get(currentGoomSL->functions, name)) { + fprintf(stderr, "ERROR: Line %d, Duplicate declaration of %s\n", currentGoomSL->num_lines, name); + return; + } + else { + ExternalFunctionStruct *gef = (ExternalFunctionStruct*)malloc(sizeof(ExternalFunctionStruct)); + gef->function = 0; + gef->vars = goom_hash_new(); + gef->is_extern = 1; + goom_hash_put_ptr(currentGoomSL->functions, name, (void*)gef); + } +} /* }}} */ + +static void reset_scanner(GoomSL *gss) +{ /* {{{ */ + gss->num_lines = 0; + gss->instr = NULL; + iflow_clean(gss->iflow); + + /* reset variables */ + goom_hash_free(gss->vars); + gss->vars = goom_hash_new(); + gss->currentNS = 0; + gss->namespaces[0] = gss->vars; + + gss->compilationOK = 1; +} /* }}} */ + +static void calculate_labels(InstructionFlow *iflow) +{ /* {{{ */ + int i = 0; + while (i < iflow->number) { + Instruction *instr = iflow->instr[i]; + if (instr->jump_label) { + HashValue *label = goom_hash_get(iflow->labels,instr->jump_label); + if (label) { + instr->data.jump_offset = -instr->address + label->i; + } + else { + fprintf(stderr, "ERROR: Line %d, Could not find label %s\n", instr->line_number, instr->jump_label); + instr->id = INSTR_NOP; + instr->nop_label = 0; + exit(1); + } + } + ++i; + } +} /* }}} */ + +/* Cree un flow d'instruction optimise */ +static void gsl_create_fast_iflow(void) +{ /* {{{ */ + int number = currentGoomSL->iflow->number; + int i; +#ifdef USE_JITC_X86 + JitcX86Env *jitc; + if (currentGoomSL->jitc != NULL) + jitc_x86_delete(currentGoomSL->jitc); + jitc = currentGoomSL->jitc = jitc_x86_env_new(0xffff); + currentGoomSL->jitc_func = jitc_prepare_func(jitc); + + JITC_JUMP_LABEL(jitc, "__very_end__"); + JITC_ADD_LABEL (jitc, "__very_start__"); + + for (i=0;i<number;++i) { + Instruction *instr = currentGoomSL->iflow->instr[i]; + switch (instr->id) { + case INSTR_SETI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EAX, instr->data.v_i.value); /* eax = value */ + JITC_LOAD_REG_IMM32(jitc, EBX, &instr->data.v_i.var->i); /* ebx = &dest */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_SETI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_src->i)); /* eax = &src */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_dest->i)); /* ebx = &dest */ + JITC_LOAD_REG_pREG (jitc, EAX, EAX); /* eax = *eax */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + /* SET.F */ + case INSTR_SETF_VAR_FLOAT : + JITC_LOAD_REG_IMM32(jitc, EAX, *(int*)&(instr->data.v_f.value)); /* eax = value */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_f.var->f)); /* ebx = &dest */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_SETF_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_src->f)); /* eax = &src */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_dest->f)); /* ebx = &dest */ + JITC_LOAD_REG_pREG (jitc, EAX, EAX); /* eax = *eax */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_NOP : + if (instr->nop_label != 0) + JITC_ADD_LABEL(jitc, instr->nop_label); + break; + case INSTR_JUMP : + JITC_JUMP_LABEL(jitc,instr->jump_label); + break; + case INSTR_SETP_VAR_PTR : + JITC_LOAD_REG_IMM32(jitc, EAX, instr->data.v_p.value); /* eax = value */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_p.var->ptr)); /* ebx = &dest */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_SETP_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_src->ptr)); /* eax = &src */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_dest->ptr)); /* ebx = &dest */ + JITC_LOAD_REG_pREG (jitc, EAX, EAX); /* eax = *eax */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_SUBI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_i.var->i)); /* ebx = &var */ + JITC_LOAD_REG_pREG (jitc, EAX, EBX); /* eax = *ebx */ + JITC_SUB_REG_IMM32(jitc, EAX, instr->data.v_i.value); /* eax -= value */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_SUBI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, ECX, &(instr->data.v_v.var_dest->i)); /* ecx = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->i)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, ECX); /* eax = *ecx */ + JITC_LOAD_REG_pREG (jitc, EBX, EBX); /* ebx = *ebx */ + JITC_SUB_REG_REG (jitc, EAX, EBX); /* eax -= ebx */ + JITC_LOAD_pREG_REG (jitc, ECX, EAX); /* *ecx = eax */ + break; + case INSTR_SUBF_VAR_FLOAT : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_SUBF_VAR_VAR : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_ISLOWERF_VAR_VAR : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_ISLOWERF_VAR_FLOAT : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_ISLOWERI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_dest->i)); + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->i)); + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_LOAD_REG_pREG (jitc, EBX, EBX); + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_CMP_REG_REG (jitc, EAX, EBX); + JITC_JUMP_COND (jitc, COND_NOT_BELOW, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ISLOWERI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_i.var->i)); + JITC_LOAD_REG_IMM32(jitc, EBX, instr->data.v_i.value); + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_CMP_REG_REG (jitc, EAX, EBX); + JITC_JUMP_COND (jitc, COND_NOT_BELOW, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ADDI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_i.var->i)); /* ebx = &var */ + JITC_LOAD_REG_pREG (jitc, EAX, EBX); /* eax = *ebx */ + JITC_ADD_REG_IMM32(jitc, EAX, instr->data.v_i.value); /* eax += value */ + JITC_LOAD_pREG_REG (jitc, EBX, EAX); /* *ebx = eax */ + break; + case INSTR_ADDI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, ECX, &(instr->data.v_v.var_dest->i)); /* ecx = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->i)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, ECX); /* eax = *ecx */ + JITC_LOAD_REG_pREG (jitc, EBX, EBX); /* ebx = *ebx */ + JITC_ADD_REG_REG (jitc, EAX, EBX); /* eax = eax + ebx */ + JITC_LOAD_pREG_REG (jitc, ECX, EAX); /* *ecx = eax */ + break; + case INSTR_ADDF_VAR_FLOAT : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_ADDF_VAR_VAR : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_MULI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_i.var->i)); + JITC_LOAD_REG_IMM32(jitc, ECX, instr->data.v_i.value); + JITC_LOAD_REG_pREG (jitc, EAX, EBX); + JITC_IMUL_EAX_REG (jitc, ECX); + JITC_LOAD_pREG_REG (jitc, EBX, EAX); + break; + case INSTR_MULI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, ECX, &(instr->data.v_v.var_dest->i)); /* ecx = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->i)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, ECX); /* eax = *ecx */ + JITC_LOAD_REG_pREG (jitc, EBX, EBX); /* ebx = *ebx */ + JITC_IMUL_EAX_REG (jitc, EBX); /* eax = eax * ebx */ + JITC_LOAD_pREG_REG (jitc, ECX, EAX); /* *ecx = eax */ + break; + case INSTR_MULF_VAR_FLOAT : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_MULF_VAR_VAR : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_DIVI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_i.var->i)); + JITC_LOAD_REG_IMM32(jitc, ECX, instr->data.v_i.value); + JITC_LOAD_REG_pREG (jitc, EAX, EBX); + JITC_IDIV_EAX_REG (jitc, ECX); + JITC_LOAD_pREG_REG (jitc, EBX, EAX); + break; + case INSTR_DIVI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, ECX, &(instr->data.v_v.var_dest->i)); /* ecx = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->i)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, ECX); /* eax = *ecx */ + JITC_LOAD_REG_pREG (jitc, EBX, EBX); /* ebx = *ebx */ + JITC_IDIV_EAX_REG (jitc, EBX); /* eax = eax * ebx */ + JITC_LOAD_pREG_REG (jitc, ECX, EAX); /* *ecx = eax */ + break; + case INSTR_DIVF_VAR_FLOAT : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_DIVF_VAR_VAR : + printf("NOT IMPLEMENTED : %d\n", instr->id); + break; + case INSTR_JZERO : + JITC_CMP_REG_IMM32(jitc,EDX,1); + JITC_JUMP_COND_LABEL(jitc,COND_NOT_EQUAL,instr->jump_label); + break; + case INSTR_ISEQUALP_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_dest->ptr)); /* eax = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->ptr)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_LOAD_REG_pREG (jitc, EBX, EBX); + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_CMP_REG_REG (jitc, EAX, EBX); + JITC_JUMP_COND (jitc, COND_NOT_EQUAL, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ISEQUALP_VAR_PTR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_p.var->ptr)); /* eax = &dest */ + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_CMP_REG_IMM32 (jitc, EAX, instr->data.v_p.value); + JITC_JUMP_COND (jitc, COND_NOT_EQUAL, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ISEQUALI_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_dest->i)); /* eax = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->i)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_LOAD_REG_pREG (jitc, EBX, EBX); + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_CMP_REG_REG (jitc, EAX, EBX); + JITC_JUMP_COND (jitc, COND_NOT_EQUAL, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ISEQUALI_VAR_INTEGER : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_i.var->i)); /* eax = &dest */ + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_CMP_REG_IMM32 (jitc, EAX, instr->data.v_i.value); + JITC_JUMP_COND (jitc, COND_NOT_EQUAL, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ISEQUALF_VAR_VAR : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_v.var_dest->f)); /* eax = &dest */ + JITC_LOAD_REG_IMM32(jitc, EBX, &(instr->data.v_v.var_src->f)); /* ebx = &src */ + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_LOAD_REG_pREG (jitc, EBX, EBX); + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_CMP_REG_REG (jitc, EAX, EBX); + JITC_JUMP_COND (jitc, COND_NOT_EQUAL, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_ISEQUALF_VAR_FLOAT : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.v_f.var->f)); /* eax = &dest */ + JITC_LOAD_REG_IMM32(jitc, EDX, 0); + JITC_LOAD_REG_pREG (jitc, EAX, EAX); + JITC_CMP_REG_IMM32 (jitc, EAX, *(int*)(&instr->data.v_f.value)); + JITC_JUMP_COND (jitc, COND_NOT_EQUAL, 1); + JITC_INC_REG (jitc, EDX); + break; + case INSTR_CALL : + JITC_CALL_LABEL(jitc, instr->jump_label); + break; + case INSTR_RET : + JITC_RETURN_FUNCTION(jitc); + break; + case INSTR_EXT_CALL : + JITC_LOAD_REG_IMM32(jitc, EAX, &(instr->data.external_function->vars)); + JITC_LOAD_REG_pREG(jitc,EAX,EAX); + JITC_PUSH_REG(jitc,EAX); + + JITC_LOAD_REG_IMM32(jitc, EAX, &(currentGoomSL->vars)); + JITC_LOAD_REG_pREG(jitc,EAX,EAX); + JITC_PUSH_REG(jitc,EAX); + + JITC_LOAD_REG_IMM32(jitc, EAX, &(currentGoomSL)); + JITC_LOAD_REG_pREG(jitc,EAX,EAX); + JITC_PUSH_REG(jitc,EAX); + + JITC_LOAD_REG_IMM32(jitc,EAX,&(instr->data.external_function)); + JITC_LOAD_REG_pREG(jitc,EAX,EAX); + JITC_LOAD_REG_pREG(jitc,EAX,EAX); + + JITC_CALL_pREG(jitc,EAX); + + JITC_POP_REG(jitc,EAX); + JITC_POP_REG(jitc,EAX); + JITC_POP_REG(jitc,EAX); + break; + case INSTR_NOT_VAR : + JITC_LOAD_REG_REG(jitc,EAX,EDX); + JITC_LOAD_REG_IMM32(jitc,EDX,1); + JITC_SUB_REG_REG(jitc,EDX,EAX); + break; + case INSTR_JNZERO : + JITC_CMP_REG_IMM32(jitc,EDX,1); + JITC_JUMP_COND_LABEL(jitc,COND_EQUAL,instr->jump_label); + break; + } + } + + JITC_ADD_LABEL (jitc, "__very_end__"); + JITC_CALL_LABEL(jitc, "__very_start__"); + JITC_LOAD_REG_IMM32(jitc, EAX, 0); + jitc_validate_func(jitc); +#else + InstructionFlow *iflow = currentGoomSL->iflow; + FastInstructionFlow *fastiflow = (FastInstructionFlow*)malloc(sizeof(FastInstructionFlow)); + fastiflow->mallocedInstr = calloc(number*16, sizeof(FastInstruction)); + /* fastiflow->instr = (FastInstruction*)(((int)fastiflow->mallocedInstr) + 16 - (((int)fastiflow->mallocedInstr)%16)); */ + fastiflow->instr = (FastInstruction*)fastiflow->mallocedInstr; + fastiflow->number = number; + for(i=0;i<number;++i) { + fastiflow->instr[i].id = iflow->instr[i]->id; + fastiflow->instr[i].data = iflow->instr[i]->data; + fastiflow->instr[i].proto = iflow->instr[i]; + } + currentGoomSL->fastiflow = fastiflow; +#endif +} /* }}} */ + +void yy_scan_string(const char *str); +void yyparse(void); + +void gsl_compile(GoomSL *_currentGoomSL, const char *script) +{ /* {{{ */ +#ifdef VERBOSE + printf("\n=== Starting Compilation ===\n"); +#endif + + /* 0- reset */ + currentGoomSL = _currentGoomSL; + reset_scanner(currentGoomSL); + + /* 1- create the syntaxic tree */ + yy_scan_string(script); + yyparse(); + + /* 2- generate code */ + gsl_commit_compilation(); + + /* 3- resolve symbols */ + calculate_labels(currentGoomSL->iflow); + + /* 4- optimize code */ + gsl_create_fast_iflow(); + +#ifdef VERBOSE + printf("=== Compilation done. # of lines: %d. # of instr: %d ===\n", currentGoomSL->num_lines, currentGoomSL->iflow->number); +#endif +} /* }}} */ + +void gsl_execute(GoomSL *scanner) +{ /* {{{ */ + if (scanner->compilationOK) { +#if USE_JITC_X86 + scanner->jitc_func(); +#else + iflow_execute(scanner->fastiflow, scanner); +#endif + } +} /* }}} */ + +GoomSL *gsl_new(void) +{ /* {{{ */ + GoomSL *gss = (GoomSL*)malloc(sizeof(GoomSL)); + + gss->iflow = iflow_new(); + gss->vars = goom_hash_new(); + gss->functions = goom_hash_new(); + gss->currentNS = 0; + gss->namespaces[0] = gss->vars; + reset_scanner(gss); + gss->compilationOK = 0; + gss->nbPtr=0; + gss->ptrArraySize=256; + gss->ptrArray = (void**)malloc(gss->ptrArraySize * sizeof(void*)); +#ifdef USE_JITC_X86 + gss->jitc = NULL; +#endif + return gss; +} /* }}} */ + +void gsl_bind_function(GoomSL *gss, const char *fname, GoomSL_ExternalFunction func) +{ /* {{{ */ + HashValue *val = goom_hash_get(gss->functions, fname); + if (val) { + ExternalFunctionStruct *gef = (ExternalFunctionStruct*)val->ptr; + gef->function = func; + } + else fprintf(stderr, "Unable to bind function %s\n", fname); +} /* }}} */ + +int gsl_is_compiled(GoomSL *gss) +{ /* {{{ */ + return gss->compilationOK; +} /* }}} */ + +void gsl_free(GoomSL *gss) +{ /* {{{ */ + iflow_free(gss->iflow); + free(gss->vars); + free(gss->functions); + free(gss); +} /* }}} */ + + +static int gsl_nb_import; +static char gsl_already_imported[256][256]; + +char *gsl_init_buffer(const char *fname) +{ + char *fbuffer; + fbuffer = (char*)malloc(512); + fbuffer[0]=0; + gsl_nb_import = 0; + if (fname) + gsl_append_file_to_buffer(fname,&fbuffer); + return fbuffer; +} + +static char *gsl_read_file(const char *fname) +{ + FILE *f; + char *buffer; + int fsize; + f = fopen(fname,"rt"); + if (!f) { + fprintf(stderr, "ERROR: Could not load file %s\n", fname); + exit(1); + } + fseek(f,0,SEEK_END); + fsize = ftell(f); + rewind(f); + buffer = (char*)malloc(fsize+512); + fread(buffer,1,fsize,f); + fclose(f); + buffer[fsize]=0; + return buffer; +} + +void gsl_append_file_to_buffer(const char *fname, char **buffer) +{ + char *fbuffer; + int size,fsize,i=0; + char reset_msg[256]; + + /* look if the file have not been already imported */ + for (i=0;i<gsl_nb_import;++i) { + if (strcmp(gsl_already_imported[i], fname) == 0) + return; + } + + /* add fname to the already imported files. */ + strcpy(gsl_already_imported[gsl_nb_import++], fname); + + /* load the file */ + fbuffer = gsl_read_file(fname); + fsize = strlen(fbuffer); + + /* look for #import */ + while (fbuffer[i]) { + if ((fbuffer[i]=='#') && (fbuffer[i+1]=='i')) { + char impName[256]; + int j; + while (fbuffer[i] && (fbuffer[i]!=' ')) + i++; + i++; + j=0; + while (fbuffer[i] && (fbuffer[i]!='\n')) + impName[j++] = fbuffer[i++]; + impName[j++] = 0; + gsl_append_file_to_buffer(impName, buffer); + } + i++; + } + + sprintf(reset_msg, "\n#FILE %s#\n#RST_LINE#\n", fname); + strcat(*buffer, reset_msg); + size=strlen(*buffer); + *buffer = (char*)realloc(*buffer, size+fsize+256); + strcat((*buffer)+size, fbuffer); + free(fbuffer); +} + + diff --git a/src/post/goom/goomsl.h b/src/post/goom/goomsl.h new file mode 100644 index 000000000..45dcce0fa --- /dev/null +++ b/src/post/goom/goomsl.h @@ -0,0 +1,32 @@ +#ifndef _GOOMSL_H +#define _GOOMSL_H + +#include "goomsl_hash.h" + +typedef struct _GoomSL GoomSL; +typedef void (*GoomSL_ExternalFunction)(GoomSL *gsl, GoomHash *global_vars, GoomHash *local_vars); + +GoomSL*gsl_new(void); +void gsl_free(GoomSL *gss); + +char *gsl_init_buffer(const char *file_name); +void gsl_append_file_to_buffer(const char *file_name, char **buffer); + +void gsl_compile (GoomSL *scanner, const char *script); +void gsl_execute (GoomSL *scanner); +int gsl_is_compiled (GoomSL *gss); +void gsl_bind_function(GoomSL *gss, const char *fname, GoomSL_ExternalFunction func); + +int gsl_malloc (GoomSL *_this, int size); +void *gsl_get_ptr (GoomSL *_this, int id); +void gsl_free_ptr(GoomSL *_this, int id); + +#define gsl_local_ptr(gsl,local,name) gsl_get_ptr(gsl, goom_hash_get(local,name)->i) +#define gsl_local_int(gsl,local,name) goom_hash_get(local,name)->i +#define gsl_local_float(gsl,local,name) goom_hash_get(local,name)->i + +#define gsl_global_ptr(gsl,global,name) gsl_get_ptr(gsl, goom_hash_get(global,name)->i) +#define gsl_global_int(gsl,global,name) goom_hash_get(global,name)->i +#define gsl_global_float(gsl,global,name) goom_hash_get(global,name)->i + +#endif diff --git a/src/post/goom/goom_hash.c b/src/post/goom/goomsl_hash.c index f21a6d6c3..b723726ca 100644 --- a/src/post/goom/goom_hash.c +++ b/src/post/goom/goomsl_hash.c @@ -1,4 +1,4 @@ -#include "goom_hash.h" +#include "goomsl_hash.h" #include <string.h> #include <stdlib.h> @@ -76,6 +76,7 @@ void goom_hash_put(GoomHash *_this, const char *key, HashValue value) { } HashValue *goom_hash_get(GoomHash *_this, const char *key) { + if (_this == NULL) return NULL; return entry_get(_this->root,key); } diff --git a/src/post/goom/goom_hash.h b/src/post/goom/goomsl_hash.h index c8eae37ed..7ce496d8e 100644 --- a/src/post/goom/goom_hash.h +++ b/src/post/goom/goomsl_hash.h @@ -1,18 +1,18 @@ -#ifndef _GOOM_HASH_H -#define _GOOM_HASH_H +#ifndef _GOOMSL_HASH_H +#define _GOOMSL_HASH_H typedef struct GOOM_HASH_ENTRY GoomHashEntry; typedef struct GOOM_HASH GoomHash; typedef union { void *ptr; - int i; + int i; float f; } HashValue; struct GOOM_HASH_ENTRY { - char *key; - HashValue value; + char *key; + HashValue value; GoomHashEntry *lower; GoomHashEntry *upper; }; @@ -22,13 +22,13 @@ struct GOOM_HASH { }; GoomHash *goom_hash_new(void); -void goom_hash_free(GoomHash *gh); +void goom_hash_free(GoomHash *gh); void goom_hash_put(GoomHash *gh, const char *key, HashValue value); HashValue *goom_hash_get(GoomHash *gh, const char *key); -void goom_hash_put_int(GoomHash *_this, const char *key, int i); +void goom_hash_put_int (GoomHash *_this, const char *key, int i); void goom_hash_put_float(GoomHash *_this, const char *key, float f); -void goom_hash_put_ptr(GoomHash *_this, const char *key, void *ptr); +void goom_hash_put_ptr (GoomHash *_this, const char *key, void *ptr); #endif /* _GOOM_HASH_H */ diff --git a/src/post/goom/goomsl_lex.c b/src/post/goom/goomsl_lex.c new file mode 100644 index 000000000..e0b0841b0 --- /dev/null +++ b/src/post/goom/goomsl_lex.c @@ -0,0 +1,1820 @@ +/* A lexical scanner generated by flex */ + +/* Scanner skeleton version: + * $Header: /nfshome/cvs/xine-lib/src/post/goom/goomsl_lex.c,v 1.1 2004/11/21 15:10:40 mroi Exp $ + */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 + +#include <stdio.h> + + +/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ +#ifdef c_plusplus +#ifndef __cplusplus +#define __cplusplus +#endif +#endif + + +#ifdef __cplusplus + +#include <stdlib.h> +#include <unistd.h> + +/* Use prototypes in function declarations. */ +#define YY_USE_PROTOS + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_PROTOS +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef __TURBOC__ + #pragma warn -rch + #pragma warn -use +#include <io.h> +#include <stdlib.h> +#define YY_USE_CONST +#define YY_USE_PROTOS +#endif + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + + +#ifdef YY_USE_PROTOS +#define YY_PROTO(proto) proto +#else +#define YY_PROTO(proto) () +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN yy_start = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START ((yy_start - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart( yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#define YY_BUF_SIZE 16384 + +typedef struct yy_buffer_state *YY_BUFFER_STATE; + +extern int yyleng; +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + +/* The funky do-while in the following #define is used to turn the definition + * int a single C statement (which needs a semi-colon terminator). This + * avoids problems with code like: + * + * if ( condition_holds ) + * yyless( 5 ); + * else + * do_something_else(); + * + * Prior to using the do-while the compiler would get upset at the + * "else" because it interpreted the "if" statement as being all + * done when it reached the ';' after the yyless() call. + */ + +/* Return all but the first 'n' matched characters back to the input stream. */ + +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + *yy_cp = yy_hold_char; \ + YY_RESTORE_YY_MORE_OFFSET \ + yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, yytext_ptr ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ +typedef unsigned int yy_size_t; + + +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + }; + +static YY_BUFFER_STATE yy_current_buffer = 0; + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + */ +#define YY_CURRENT_BUFFER yy_current_buffer + + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; + +static int yy_n_chars; /* number of characters read into yy_ch_buf */ + + +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart YY_PROTO(( FILE *input_file )); + +void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); +void yy_load_buffer_state YY_PROTO(( void )); +YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); +void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); +void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); +void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); +#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) + +YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); +YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); +YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); + +static void *yy_flex_alloc YY_PROTO(( yy_size_t )); +static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); +static void yy_flex_free YY_PROTO(( void * )); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! yy_current_buffer ) \ + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ + yy_current_buffer->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) + +typedef unsigned char YY_CHAR; +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; +typedef int yy_state_type; +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state YY_PROTO(( void )); +static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); +static int yy_get_next_buffer YY_PROTO(( void )); +static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + yytext_ptr = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + yy_hold_char = *yy_cp; \ + *yy_cp = '\0'; \ + yy_c_buf_p = yy_cp; + +#define YY_NUM_RULES 39 +#define YY_END_OF_BUFFER 40 +static yyconst short int yy_accept[125] = + { 0, + 0, 0, 0, 0, 0, 0, 0, 0, 40, 38, + 37, 4, 12, 9, 38, 38, 38, 38, 27, 27, + 38, 38, 26, 26, 26, 26, 26, 26, 26, 26, + 26, 37, 1, 38, 6, 39, 6, 6, 1, 6, + 3, 1, 16, 15, 16, 37, 9, 9, 9, 32, + 31, 0, 33, 10, 11, 34, 30, 29, 27, 0, + 35, 36, 26, 26, 25, 26, 26, 26, 26, 26, + 26, 26, 37, 1, 0, 11, 5, 0, 0, 14, + 13, 9, 9, 29, 28, 26, 26, 26, 18, 23, + 19, 26, 26, 0, 2, 9, 9, 26, 26, 26, + + 26, 26, 9, 9, 26, 26, 17, 26, 24, 9, + 9, 26, 26, 20, 9, 8, 9, 21, 26, 9, + 22, 9, 7, 0 + } ; + +static yyconst int yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 4, 1, 5, 6, 1, 7, 1, 1, 1, + 1, 8, 9, 1, 10, 11, 12, 13, 14, 14, + 14, 14, 14, 14, 14, 14, 14, 1, 1, 15, + 16, 17, 1, 1, 18, 18, 18, 18, 19, 20, + 18, 18, 21, 18, 18, 22, 18, 23, 18, 18, + 18, 24, 25, 26, 18, 18, 18, 18, 18, 18, + 1, 27, 1, 1, 28, 1, 29, 30, 31, 32, + + 33, 34, 35, 36, 37, 18, 18, 38, 18, 39, + 40, 41, 18, 42, 43, 44, 18, 18, 45, 46, + 18, 18, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst int yy_meta[47] = + { 0, + 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 3, 3, 1, 1, 1, 4, 4, 4, + 4, 4, 4, 4, 4, 4, 1, 4, 3, 3, + 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, + 4, 4, 4, 4, 4, 4 + } ; + +static yyconst short int yy_base[132] = + { 0, + 0, 45, 47, 50, 199, 57, 60, 61, 201, 203, + 66, 203, 203, 47, 184, 183, 59, 66, 70, 78, + 182, 181, 0, 46, 150, 157, 155, 153, 148, 147, + 154, 91, 203, 88, 203, 203, 177, 95, 203, 176, + 203, 203, 203, 203, 51, 104, 0, 166, 161, 203, + 203, 98, 203, 203, 203, 203, 203, 88, 106, 0, + 203, 203, 0, 154, 0, 140, 143, 138, 137, 138, + 137, 141, 119, 203, 165, 173, 203, 122, 172, 203, + 203, 152, 147, 101, 0, 134, 138, 141, 0, 0, + 0, 132, 130, 164, 203, 147, 137, 135, 121, 118, + + 122, 127, 155, 136, 115, 115, 0, 109, 0, 127, + 111, 97, 100, 0, 122, 121, 95, 0, 72, 61, + 0, 70, 0, 203, 134, 138, 142, 144, 48, 148, + 152 + } ; + +static yyconst short int yy_def[132] = + { 0, + 124, 1, 125, 125, 125, 125, 126, 126, 124, 124, + 124, 124, 124, 127, 124, 124, 124, 124, 124, 124, + 124, 124, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 127, 127, 127, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 129, + 124, 124, 128, 128, 128, 128, 128, 128, 128, 128, + 128, 128, 124, 124, 124, 130, 124, 124, 130, 124, + 124, 127, 127, 124, 129, 128, 128, 128, 128, 128, + 128, 128, 128, 130, 124, 127, 127, 128, 128, 128, + + 128, 128, 127, 127, 128, 128, 128, 128, 128, 131, + 127, 128, 128, 128, 131, 131, 127, 128, 128, 127, + 128, 127, 127, 0, 124, 124, 124, 124, 124, 124, + 124 + } ; + +static yyconst short int yy_nxt[250] = + { 0, + 10, 11, 12, 11, 13, 14, 10, 15, 16, 17, + 10, 18, 19, 20, 21, 10, 22, 23, 23, 23, + 23, 23, 23, 23, 23, 23, 10, 23, 23, 23, + 23, 24, 25, 26, 23, 23, 27, 23, 28, 23, + 29, 23, 30, 23, 31, 23, 32, 33, 32, 36, + 85, 38, 39, 38, 37, 80, 34, 37, 38, 42, + 38, 40, 36, 36, 44, 44, 48, 46, 40, 46, + 49, 52, 52, 54, 53, 123, 57, 55, 64, 122, + 58, 56, 59, 59, 57, 65, 45, 45, 58, 81, + 59, 59, 73, 74, 73, 54, 78, 74, 78, 76, + + 84, 84, 75, 56, 57, 46, 75, 46, 58, 121, + 52, 52, 57, 84, 84, 60, 58, 120, 59, 59, + 73, 74, 73, 78, 74, 78, 116, 116, 119, 118, + 75, 117, 116, 75, 35, 35, 35, 35, 43, 43, + 43, 43, 47, 114, 47, 47, 63, 63, 94, 94, + 94, 94, 115, 113, 115, 115, 112, 111, 110, 109, + 108, 107, 106, 105, 104, 103, 95, 102, 101, 100, + 99, 98, 97, 96, 95, 95, 79, 93, 92, 91, + 90, 89, 88, 87, 86, 83, 82, 79, 77, 72, + 71, 70, 69, 68, 67, 66, 62, 61, 51, 50, + + 124, 41, 9, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124 + } ; + +static yyconst short int yy_chk[250] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, + 129, 4, 4, 4, 3, 45, 2, 4, 6, 6, + 6, 4, 7, 8, 7, 8, 14, 11, 6, 11, + 14, 17, 17, 18, 17, 122, 19, 18, 24, 120, + 19, 18, 19, 19, 20, 24, 7, 8, 20, 45, + 20, 20, 32, 32, 32, 34, 38, 38, 38, 34, + + 58, 58, 32, 34, 52, 46, 38, 46, 52, 119, + 52, 52, 59, 84, 84, 19, 59, 117, 59, 59, + 73, 73, 73, 78, 78, 78, 116, 115, 113, 112, + 73, 111, 110, 78, 125, 125, 125, 125, 126, 126, + 126, 126, 127, 108, 127, 127, 128, 128, 130, 130, + 130, 130, 131, 106, 131, 131, 105, 104, 103, 102, + 101, 100, 99, 98, 97, 96, 94, 93, 92, 88, + 87, 86, 83, 82, 79, 76, 75, 72, 71, 70, + 69, 68, 67, 66, 64, 49, 48, 40, 37, 31, + 30, 29, 28, 27, 26, 25, 22, 21, 16, 15, + + 9, 5, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124, 124, + 124, 124, 124, 124, 124, 124, 124, 124, 124 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "goomsl_lex.l" +#define INITIAL 0 +#line 2 "goomsl_lex.l" + +#include <math.h> +#include <stdlib.h> +#include <string.h> +#include "goomsl.h" +#include "goomsl_private.h" +#include "goomsl_yacc.h" +void yyerror(char *); +void yyparse(void); + +GoomSL *currentGoomSL; +static int string_size; +static char string[1024]; +#define C_COMMENT 1 + +#define LINE_COMMENT 2 + +#define STRING 3 + +#line 480 "goomsl_lex.c" + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap YY_PROTO(( void )); +#else +extern int yywrap YY_PROTO(( void )); +#endif +#endif + +#ifndef YY_NO_UNPUT +static void yyunput YY_PROTO(( int c, char *buf_ptr )); +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen YY_PROTO(( yyconst char * )); +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus +static int yyinput YY_PROTO(( void )); +#else +static int input YY_PROTO(( void )); +#endif +#endif + +#if YY_STACK_USED +static int yy_start_stack_ptr = 0; +static int yy_start_stack_depth = 0; +static int *yy_start_stack = 0; +#ifndef YY_NO_PUSH_STATE +static void yy_push_state YY_PROTO(( int new_state )); +#endif +#ifndef YY_NO_POP_STATE +static void yy_pop_state YY_PROTO(( void )); +#endif +#ifndef YY_NO_TOP_STATE +static int yy_top_state YY_PROTO(( void )); +#endif + +#else +#define YY_NO_PUSH_STATE 1 +#define YY_NO_POP_STATE 1 +#define YY_NO_TOP_STATE 1 +#endif + +#ifdef YY_MALLOC_DECL +YY_MALLOC_DECL +#else +#if __STDC__ +#ifndef __cplusplus +#include <stdlib.h> +#endif +#else +/* Just try to get by without declaring the routines. This will fail + * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) + * or sizeof(void*) != sizeof(int). + */ +#endif +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ + +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( yy_current_buffer->yy_is_interactive ) \ + { \ + int c = '*', n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ + && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL int yylex YY_PROTO(( void )) +#endif + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + if ( yyleng > 0 ) \ + yy_current_buffer->yy_at_bol = \ + (yytext[yyleng - 1] == '\n'); \ + YY_USER_ACTION + +YY_DECL; +YY_DECL + { + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 25 "goomsl_lex.l" + + +#line 637 "goomsl_lex.c" + + if ( yy_init ) + { + yy_init = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! yy_start ) + yy_start = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! yy_current_buffer ) + yy_current_buffer = + yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_load_buffer_state(); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = yy_c_buf_p; + + /* Support of yytext. */ + *yy_cp = yy_hold_char; + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = yy_start; + yy_current_state += YY_AT_BOL(); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 125 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 203 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + + +do_action: /* This label is used only to access EOF actions. */ + + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = yy_hold_char; + yy_cp = yy_last_accepting_cpos; + yy_current_state = yy_last_accepting_state; + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 27 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; /* Ignore empty lines */ } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 28 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; /* Ignore empty lines */ } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 30 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; yylval.charValue=*yytext; BEGIN INITIAL; return '\n'; } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 31 "goomsl_lex.l" +{ ++currentGoomSL->num_lines; yylval.charValue=*yytext; return '\n'; } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 33 "goomsl_lex.l" +{ BEGIN INITIAL; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 34 "goomsl_lex.l" +{ /* eat up comment */ } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 36 "goomsl_lex.l" +{ currentGoomSL->num_lines = 0; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 37 "goomsl_lex.l" +{ currentGoomSL->num_lines = 0; printf("%s\n", yytext); } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 38 "goomsl_lex.l" +{ /* ignore preprocessor lines */ } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 40 "goomsl_lex.l" +{ BEGIN C_COMMENT; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 41 "goomsl_lex.l" +{ BEGIN LINE_COMMENT; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 42 "goomsl_lex.l" +{ BEGIN STRING; string_size=0; } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 44 "goomsl_lex.l" +{ string[string_size++] = '\n'; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 45 "goomsl_lex.l" +{ string[string_size++] = '\"'; } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 46 "goomsl_lex.l" +{ /* fin de la chaine: on cree le pointeur qui va bien */ + unsigned int tmp; + BEGIN INITIAL; + string[string_size]=0; + tmp = gsl_malloc(currentGoomSL, string_size+1); + strcpy((char*)currentGoomSL->ptrArray[tmp],string); + sprintf(yylval.strValue, "0x%08x", tmp); + return TYPE_PTR; + } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 55 "goomsl_lex.l" +{ string[string_size++] = *yytext; } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 57 "goomsl_lex.l" +{ return FLOAT_TK; } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 58 "goomsl_lex.l" +{ return INT_TK; } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 59 "goomsl_lex.l" +{ return PTR_TK; } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 60 "goomsl_lex.l" +{ return PTR_TK; } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 61 "goomsl_lex.l" +{ return DECLARE; } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 62 "goomsl_lex.l" +{ return EXTERNAL; } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 63 "goomsl_lex.l" +{ return NOT; } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 64 "goomsl_lex.l" +{ return WHILE; } + YY_BREAK +case 25: +YY_RULE_SETUP +#line 65 "goomsl_lex.l" +{ return DO; } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 66 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_VAR; } + YY_BREAK +case 27: +YY_RULE_SETUP +#line 67 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_INTEGER; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 68 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_INTEGER; } + YY_BREAK +case 29: +YY_RULE_SETUP +#line 69 "goomsl_lex.l" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_FLOAT; } + YY_BREAK +case 30: +YY_RULE_SETUP +#line 70 "goomsl_lex.l" +{ sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return TYPE_FLOAT; } + YY_BREAK +case 31: +YY_RULE_SETUP +#line 71 "goomsl_lex.l" +{ return PLUS_EQ; } + YY_BREAK +case 32: +YY_RULE_SETUP +#line 72 "goomsl_lex.l" +{ return PLUS_EQ; } + YY_BREAK +case 33: +YY_RULE_SETUP +#line 73 "goomsl_lex.l" +{ return PLUS_EQ; } + YY_BREAK +case 34: +YY_RULE_SETUP +#line 74 "goomsl_lex.l" +{ return PLUS_EQ; } + YY_BREAK +case 35: +YY_RULE_SETUP +#line 75 "goomsl_lex.l" +{ return LOW_EQ; } + YY_BREAK +case 36: +YY_RULE_SETUP +#line 76 "goomsl_lex.l" +{ return SUP_EQ; } + YY_BREAK +case 37: +YY_RULE_SETUP +#line 77 "goomsl_lex.l" +/* eat up whitespace */ + YY_BREAK +case 38: +YY_RULE_SETUP +#line 78 "goomsl_lex.l" +{ yylval.charValue = *yytext; return *yytext; } + YY_BREAK +case 39: +YY_RULE_SETUP +#line 80 "goomsl_lex.l" +ECHO; + YY_BREAK +#line 924 "goomsl_lex.c" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(C_COMMENT): +case YY_STATE_EOF(LINE_COMMENT): +case YY_STATE_EOF(STRING): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = yy_hold_char; + YY_RESTORE_YY_MORE_OFFSET + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between yy_current_buffer and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + yy_n_chars = yy_current_buffer->yy_n_chars; + yy_current_buffer->yy_input_file = yyin; + yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = yytext_ptr + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++yy_c_buf_p; + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = yy_c_buf_p; + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer() ) + { + case EOB_ACT_END_OF_FILE: + { + yy_did_buffer_switch_on_eof = 0; + + if ( yywrap() ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = + yytext_ptr + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + yy_c_buf_p = + &yy_current_buffer->yy_ch_buf[yy_n_chars]; + + yy_current_state = yy_get_previous_state(); + + yy_cp = yy_c_buf_p; + yy_bp = yytext_ptr + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of yylex */ + + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ + +static int yy_get_next_buffer() + { + register char *dest = yy_current_buffer->yy_ch_buf; + register char *source = yytext_ptr; + register int number_to_move, i; + int ret_val; + + if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( yy_current_buffer->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + yy_current_buffer->yy_n_chars = yy_n_chars = 0; + + else + { + int num_to_read = + yy_current_buffer->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ +#ifdef YY_USES_REJECT + YY_FATAL_ERROR( +"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); +#else + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = yy_current_buffer; + + int yy_c_buf_p_offset = + (int) (yy_c_buf_p - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yy_flex_realloc( (void *) b->yy_ch_buf, + b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = yy_current_buffer->yy_buf_size - + number_to_move - 1; +#endif + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), + yy_n_chars, num_to_read ); + + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + if ( yy_n_chars == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart( yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + yy_current_buffer->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + yy_n_chars += number_to_move; + yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; + yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; + + yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; + + return ret_val; + } + + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + +static yy_state_type yy_get_previous_state() + { + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = yy_start; + yy_current_state += YY_AT_BOL(); + + for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 125 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; + } + + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + +#ifdef YY_USE_PROTOS +static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) +#else +static yy_state_type yy_try_NUL_trans( yy_current_state ) +yy_state_type yy_current_state; +#endif + { + register int yy_is_jam; + register char *yy_cp = yy_c_buf_p; + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + yy_last_accepting_state = yy_current_state; + yy_last_accepting_cpos = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 125 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 124); + + return yy_is_jam ? 0 : yy_current_state; + } + + +#ifndef YY_NO_UNPUT +#ifdef YY_USE_PROTOS +static void yyunput( int c, register char *yy_bp ) +#else +static void yyunput( c, yy_bp ) +int c; +register char *yy_bp; +#endif + { + register char *yy_cp = yy_c_buf_p; + + /* undo effects of setting up yytext */ + *yy_cp = yy_hold_char; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = yy_n_chars + 2; + register char *dest = &yy_current_buffer->yy_ch_buf[ + yy_current_buffer->yy_buf_size + 2]; + register char *source = + &yy_current_buffer->yy_ch_buf[number_to_move]; + + while ( source > yy_current_buffer->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + yy_current_buffer->yy_n_chars = + yy_n_chars = yy_current_buffer->yy_buf_size; + + if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + + yytext_ptr = yy_bp; + yy_hold_char = *yy_cp; + yy_c_buf_p = yy_cp; + } +#endif /* ifndef YY_NO_UNPUT */ + + +#ifdef __cplusplus +static int yyinput() +#else +static int input() +#endif + { + int c; + + *yy_c_buf_p = yy_hold_char; + + if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) + /* This was really a NUL. */ + *yy_c_buf_p = '\0'; + + else + { /* need more input */ + int offset = yy_c_buf_p - yytext_ptr; + ++yy_c_buf_p; + + switch ( yy_get_next_buffer() ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart( yyin ); + + /* fall through */ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap() ) + return EOF; + + if ( ! yy_did_buffer_switch_on_eof ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + yy_c_buf_p = yytext_ptr + offset; + break; + } + } + } + + c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ + *yy_c_buf_p = '\0'; /* preserve yytext */ + yy_hold_char = *++yy_c_buf_p; + + yy_current_buffer->yy_at_bol = (c == '\n'); + + return c; + } + + +#ifdef YY_USE_PROTOS +void yyrestart( FILE *input_file ) +#else +void yyrestart( input_file ) +FILE *input_file; +#endif + { + if ( ! yy_current_buffer ) + yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); + + yy_init_buffer( yy_current_buffer, input_file ); + yy_load_buffer_state(); + } + + +#ifdef YY_USE_PROTOS +void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) +#else +void yy_switch_to_buffer( new_buffer ) +YY_BUFFER_STATE new_buffer; +#endif + { + if ( yy_current_buffer == new_buffer ) + return; + + if ( yy_current_buffer ) + { + /* Flush out information for old buffer. */ + *yy_c_buf_p = yy_hold_char; + yy_current_buffer->yy_buf_pos = yy_c_buf_p; + yy_current_buffer->yy_n_chars = yy_n_chars; + } + + yy_current_buffer = new_buffer; + yy_load_buffer_state(); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + yy_did_buffer_switch_on_eof = 1; + } + + +#ifdef YY_USE_PROTOS +void yy_load_buffer_state( void ) +#else +void yy_load_buffer_state() +#endif + { + yy_n_chars = yy_current_buffer->yy_n_chars; + yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; + yyin = yy_current_buffer->yy_input_file; + yy_hold_char = *yy_c_buf_p; + } + + +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) +#else +YY_BUFFER_STATE yy_create_buffer( file, size ) +FILE *file; +int size; +#endif + { + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer( b, file ); + + return b; + } + + +#ifdef YY_USE_PROTOS +void yy_delete_buffer( YY_BUFFER_STATE b ) +#else +void yy_delete_buffer( b ) +YY_BUFFER_STATE b; +#endif + { + if ( ! b ) + return; + + if ( b == yy_current_buffer ) + yy_current_buffer = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yy_flex_free( (void *) b->yy_ch_buf ); + + yy_flex_free( (void *) b ); + } + + +#ifndef YY_ALWAYS_INTERACTIVE +#ifndef YY_NEVER_INTERACTIVE +extern int isatty YY_PROTO(( int )); +#endif +#endif + +#ifdef YY_USE_PROTOS +void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) +#else +void yy_init_buffer( b, file ) +YY_BUFFER_STATE b; +FILE *file; +#endif + + + { + yy_flush_buffer( b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + +#if YY_ALWAYS_INTERACTIVE + b->yy_is_interactive = 1; +#else +#if YY_NEVER_INTERACTIVE + b->yy_is_interactive = 0; +#else + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; +#endif +#endif + } + + +#ifdef YY_USE_PROTOS +void yy_flush_buffer( YY_BUFFER_STATE b ) +#else +void yy_flush_buffer( b ) +YY_BUFFER_STATE b; +#endif + + { + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == yy_current_buffer ) + yy_load_buffer_state(); + } + + +#ifndef YY_NO_SCAN_BUFFER +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) +#else +YY_BUFFER_STATE yy_scan_buffer( base, size ) +char *base; +yy_size_t size; +#endif + { + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer( b ); + + return b; + } +#endif + + +#ifndef YY_NO_SCAN_STRING +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) +#else +YY_BUFFER_STATE yy_scan_string( yy_str ) +yyconst char *yy_str; +#endif + { + int len; + for ( len = 0; yy_str[len]; ++len ) + ; + + return yy_scan_bytes( yy_str, len ); + } +#endif + + +#ifndef YY_NO_SCAN_BYTES +#ifdef YY_USE_PROTOS +YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) +#else +YY_BUFFER_STATE yy_scan_bytes( bytes, len ) +yyconst char *bytes; +int len; +#endif + { + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yy_flex_alloc( n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer( buf, n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; + } +#endif + + +#ifndef YY_NO_PUSH_STATE +#ifdef YY_USE_PROTOS +static void yy_push_state( int new_state ) +#else +static void yy_push_state( new_state ) +int new_state; +#endif + { + if ( yy_start_stack_ptr >= yy_start_stack_depth ) + { + yy_size_t new_size; + + yy_start_stack_depth += YY_START_STACK_INCR; + new_size = yy_start_stack_depth * sizeof( int ); + + if ( ! yy_start_stack ) + yy_start_stack = (int *) yy_flex_alloc( new_size ); + + else + yy_start_stack = (int *) yy_flex_realloc( + (void *) yy_start_stack, new_size ); + + if ( ! yy_start_stack ) + YY_FATAL_ERROR( + "out of memory expanding start-condition stack" ); + } + + yy_start_stack[yy_start_stack_ptr++] = YY_START; + + BEGIN(new_state); + } +#endif + + +#ifndef YY_NO_POP_STATE +static void yy_pop_state() + { + if ( --yy_start_stack_ptr < 0 ) + YY_FATAL_ERROR( "start-condition stack underflow" ); + + BEGIN(yy_start_stack[yy_start_stack_ptr]); + } +#endif + + +#ifndef YY_NO_TOP_STATE +static int yy_top_state() + { + return yy_start_stack[yy_start_stack_ptr - 1]; + } +#endif + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +#ifdef YY_USE_PROTOS +static void yy_fatal_error( yyconst char msg[] ) +#else +static void yy_fatal_error( msg ) +char msg[]; +#endif + { + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); + } + + + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + yytext[yyleng] = yy_hold_char; \ + yy_c_buf_p = yytext + n; \ + yy_hold_char = *yy_c_buf_p; \ + *yy_c_buf_p = '\0'; \ + yyleng = n; \ + } \ + while ( 0 ) + + +/* Internal utility routines. */ + +#ifndef yytext_ptr +#ifdef YY_USE_PROTOS +static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) +#else +static void yy_flex_strncpy( s1, s2, n ) +char *s1; +yyconst char *s2; +int n; +#endif + { + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; + } +#endif + +#ifdef YY_NEED_STRLEN +#ifdef YY_USE_PROTOS +static int yy_flex_strlen( yyconst char *s ) +#else +static int yy_flex_strlen( s ) +yyconst char *s; +#endif + { + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; + } +#endif + + +#ifdef YY_USE_PROTOS +static void *yy_flex_alloc( yy_size_t size ) +#else +static void *yy_flex_alloc( size ) +yy_size_t size; +#endif + { + return (void *) malloc( size ); + } + +#ifdef YY_USE_PROTOS +static void *yy_flex_realloc( void *ptr, yy_size_t size ) +#else +static void *yy_flex_realloc( ptr, size ) +void *ptr; +yy_size_t size; +#endif + { + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); + } + +#ifdef YY_USE_PROTOS +static void yy_flex_free( void *ptr ) +#else +static void yy_flex_free( ptr ) +void *ptr; +#endif + { + free( ptr ); + } + +#if YY_MAIN +int main() + { + yylex(); + return 0; + } +#endif +#line 80 "goomsl_lex.l" + + + +int yywrap(void) { return 1; yyunput(0,0); } + diff --git a/src/post/goom/goomsl_private.h b/src/post/goom/goomsl_private.h new file mode 100644 index 000000000..0b3c419d5 --- /dev/null +++ b/src/post/goom/goomsl_private.h @@ -0,0 +1,217 @@ +#ifndef _GSL_PRIVATE_H +#define _GSL_PRIVATE_H + +/* -- internal use -- */ + +#include "goomsl.h" + +#ifdef USE_JITC_X86 +#include "jitc_x86.h" +#endif + +/* {{{ type of nodes */ +#define EMPTY_NODE 0 +#define CONST_INT_NODE 1 +#define CONST_FLOAT_NODE 2 +#define CONST_PTR_NODE 3 +#define VAR_NODE 4 +#define PARAM_NODE 5 +#define READ_PARAM_NODE 6 +#define OPR_NODE 7 +/* }}} */ +/* {{{ type of operations */ +#define OPR_SET 1 +#define OPR_IF 2 +#define OPR_WHILE 3 +#define OPR_BLOCK 4 +#define OPR_ADD 5 +#define OPR_MUL 6 +#define OPR_EQU 7 +#define OPR_NOT 8 +#define OPR_LOW 9 +#define OPR_DIV 10 +#define OPR_SUB 11 +#define OPR_FUNC_INTRO 12 +#define OPR_FUNC_OUTRO 13 +#define OPR_CALL 14 +#define OPR_EXT_CALL 15 +#define OPR_PLUS_EQ 16 +#define OPR_SUB_EQ 17 +#define OPR_MUL_EQ 18 +#define OPR_DIV_EQ 19 +#define OPR_CALL_EXPR 20 +#define OPR_AFFECT_LIST 21 + +/* }}} */ + +typedef struct _ConstIntNodeType { /* {{{ */ + int val; +} ConstIntNodeType; /* }}} */ +typedef struct _ConstFloatNodeType { /* {{{ */ + float val; +} ConstFloatNodeType; /* }}} */ +typedef struct _ConstPtrNodeType { /* {{{ */ + int id; +} ConstPtrNodeType; /* }}} */ +typedef struct _OprNodeType { /* {{{ */ + int type; + int nbOp; + struct _NODE_TYPE *op[3]; /* maximal number of operand needed */ + struct _NODE_TYPE *next; +} OprNodeType; /* }}} */ +typedef struct _NODE_TYPE { /* {{{ */ + int type; + char *str; + GoomHash *vnamespace; + int line_number; + union { + ConstIntNodeType constInt; + ConstFloatNodeType constFloat; + ConstPtrNodeType constPtr; + OprNodeType opr; + } unode; +} NodeType; /* }}} */ +typedef union _INSTRUCTION_DATA { /* {{{ */ + + /* VAR - PTR */ + struct { + HashValue *var; + int value; + } v_p; + /* VAR - INTEGER */ + struct { + HashValue *var; + int value; + } v_i; + /* VAR - FLOAT */ + struct { + HashValue *var; + float value; + } v_f; + /* VAR - VAR */ + struct { + HashValue *var_src; + HashValue *var_dest; + } v_v; + /* VAR */ + struct { + int jump_offset; + HashValue *var; + } v; + int jump_offset; + struct _ExternalFunctionStruct *external_function; +} InstructionData; +/* }}} */ +typedef struct _INSTRUCTION { /* {{{ */ + + int id; + InstructionData data; + GoomSL *parent; + const char *name; /* name of the instruction */ + + char **params; /* parametres de l'instruction */ + GoomHash **vnamespace; + int *types; /* type des parametres de l'instruction */ + int cur_param; + int nb_param; + + int address; + char *jump_label; + char *nop_label; + + int line_number; + +} Instruction; /* }}} */ +typedef struct _INSTRUCTION_FLOW { /* {{{ */ + + Instruction **instr; + int number; + int tabsize; + GoomHash *labels; +} InstructionFlow; /* }}} */ +typedef struct _FAST_INSTRUCTION { /* {{{ */ + int id; + InstructionData data; + Instruction *proto; +} FastInstruction; /* }}} */ +typedef struct _FastInstructionFlow { /* {{{ */ + int number; + FastInstruction *instr; + void *mallocedInstr; +} FastInstructionFlow; /* }}} */ +typedef struct _ExternalFunctionStruct { /* {{{ */ + GoomSL_ExternalFunction function; + GoomHash *vars; + int is_extern; +} ExternalFunctionStruct; /* }}} */ +struct _GoomSL { /* {{{ */ + int num_lines; + Instruction *instr; /* instruction en cours de construction */ + + InstructionFlow *iflow; /* flow d'instruction 'normal' */ + FastInstructionFlow *fastiflow; /* flow d'instruction optimise */ + + GoomHash *vars; /* table de variables */ + int currentNS; + GoomHash *namespaces[16]; + + GoomHash *functions; /* table des fonctions externes */ + + int nbPtr; + int ptrArraySize; + void **ptrArray; + + int compilationOK; +#ifdef USE_JITC_X86 + JitcX86Env *jitc; + JitcFunc jitc_func; +#endif +}; /* }}} */ + +extern GoomSL *currentGoomSL; + +Instruction *gsl_instr_init(GoomSL *parent, const char *name, int id, int nb_param, int line_number); +void gsl_instr_add_param(Instruction *_this, char *param, int type); +void gsl_instr_set_namespace(Instruction *_this, GoomHash *ns); + +void gsl_declare_task(const char *name); +void gsl_declare_external_task(const char *name); + +void gsl_enternamespace(const char *name); +void gsl_leavenamespace(void); +GoomHash *gsl_find_namespace(const char *name); + +void gsl_commit_compilation(void); + +/* #define TYPE_PARAM 1 + #define TYPE_INTEGER 2 + #define TYPE_FLOAT 3 + #define TYPE_VAR 4 */ +#define TYPE_LABEL 5 +#define TYPE_OP_EQUAL 6 +#define TYPE_IVAR 7 +#define TYPE_FVAR 8 +#define TYPE_PVAR 9 + +#define INSTR_JUMP 6 +#define INSTR_JZERO 29 +#define INSTR_CALL 36 +#define INSTR_RET 37 +#define INSTR_EXT_CALL 38 +#define INSTR_JNZERO 40 + +#define INSTR_SET 10001 +#define INSTR_INT 10002 +#define INSTR_FLOAT 10003 +#define INSTR_PTR 10004 +#define INSTR_LABEL 10005 +#define INSTR_ISLOWER 10006 +#define INSTR_ADD 10007 +#define INSTR_MUL 10008 +#define INSTR_DIV 10009 +#define INSTR_SUB 10010 +#define INSTR_ISEQUAL 10011 +#define INSTR_NOT 10012 + + +#endif diff --git a/src/post/goom/goomsl_yacc.c b/src/post/goom/goomsl_yacc.c new file mode 100644 index 000000000..b29d5caef --- /dev/null +++ b/src/post/goom/goomsl_yacc.c @@ -0,0 +1,2069 @@ + +/* A Bison parser, made from goomsl_yacc.y + by GNU Bison version 1.28 */ + +#define YYBISON 1 /* Identify Bison output. */ + +#define TYPE_INTEGER 257 +#define TYPE_FLOAT 258 +#define TYPE_VAR 259 +#define TYPE_PTR 260 +#define PTR_TK 261 +#define INT_TK 262 +#define FLOAT_TK 263 +#define DECLARE 264 +#define EXTERNAL 265 +#define WHILE 266 +#define DO 267 +#define NOT 268 +#define PLUS_EQ 269 +#define SUB_EQ 270 +#define DIV_EQ 271 +#define MUL_EQ 272 +#define SUP_EQ 273 +#define LOW_EQ 274 + +#line 6 "goomsl_yacc.y" + + #include <stdio.h> + #include <stdlib.h> + #include <string.h> + #include "goomsl.h" + #include "goomsl_private.h" + + int yylex(void); + void yyerror(char *); + extern GoomSL *currentGoomSL; + + static NodeType *nodeNew(const char *str, int type, int line_number); + static NodeType *nodeClone(NodeType *node); + static void nodeFreeInternals(NodeType *node); + static void nodeFree(NodeType *node); + + static void commit_node(NodeType *node, int releaseIfTemp); + static void precommit_node(NodeType *node); + + static NodeType *new_constInt(const char *str, int line_number); + static NodeType *new_constFloat(const char *str, int line_number); + static NodeType *new_constPtr(const char *str, int line_number); + static NodeType *new_var(const char *str, int line_number); + static NodeType *new_nop(const char *str); + static NodeType *new_op(const char *str, int type, int nbOp); + + static int allocateLabel(void); + static int allocateTemp(void); + static void releaseTemp(int n); + static void releaseAllTemps(void); + + static int is_tmp_expr(NodeType *node) { + if (node->str) { + return (!strncmp(node->str,"_i_tmp_",7)) + || (!strncmp(node->str,"_f_tmp_",7)) + || (!strncmp(node->str,"_p_tmp",7)); + } + return 0; + } + /* pre: is_tmp_expr(node); */ + static int get_tmp_id(NodeType *node) { return atoi((node->str)+5); } + + static int is_commutative_expr(int itype) + { /* {{{ */ + return (itype == INSTR_ADD) + || (itype == INSTR_MUL) + || (itype == INSTR_ISEQUAL); + } /* }}} */ + + static void GSL_PUT_LABEL(char *name, int line_number) + { /* {{{ */ +#ifdef VERBOSE + printf("label %s\n", name); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "label", INSTR_LABEL, 1, line_number); + gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); + } /* }}} */ + static void GSL_PUT_JUMP(char *name, int line_number) + { /* {{{ */ +#ifdef VERBOSE + printf("jump %s\n", name); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "jump", INSTR_JUMP, 1, line_number); + gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); + } /* }}} */ + + static void GSL_PUT_JXXX(char *name, char *iname, int instr_id, int line_number) + { /* {{{ */ +#ifdef VERBOSE + printf("%s %s\n", iname, name); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, iname, instr_id, 1, line_number); + gsl_instr_add_param(currentGoomSL->instr, name, TYPE_LABEL); + } /* }}} */ + static void GSL_PUT_JZERO(char *name,int line_number) + { /* {{{ */ + GSL_PUT_JXXX(name,"jzero.i",INSTR_JZERO,line_number); + } /* }}} */ + static void GSL_PUT_JNZERO(char *name, int line_number) + { /* {{{ */ + GSL_PUT_JXXX(name,"jnzero.i",INSTR_JNZERO,line_number); + } /* }}} */ + + /* FLOAT */ + #define gsl_float_decl_global(name) goom_hash_put_int(currentGoomSL->vars,name,INSTR_FLOAT) + #define gsl_int_decl_global(name) goom_hash_put_int(currentGoomSL->vars,name,INSTR_INT) + #define gsl_ptr_decl_global(name) goom_hash_put_int(currentGoomSL->vars,name,INSTR_PTR) + static void gsl_float_decl(const char *name) + { + goom_hash_put_int(currentGoomSL->namespaces[currentGoomSL->currentNS],name,INSTR_FLOAT); + } + /* INT */ + static void gsl_int_decl(const char *name) + { + goom_hash_put_int(currentGoomSL->namespaces[currentGoomSL->currentNS],name,INSTR_INT); + } + /* PTR */ + static void gsl_ptr_decl(const char *name) + { + goom_hash_put_int(currentGoomSL->namespaces[currentGoomSL->currentNS],name,INSTR_PTR); + } + + static void commit_test2(NodeType *set,const char *type, int instr); + static NodeType *new_call(const char *name, NodeType *affect_list); + + /* SETTER */ + static NodeType *new_set(NodeType *lvalue, NodeType *expression) + { /* {{{ */ + NodeType *set = new_op("set", OPR_SET, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } /* }}} */ + static void commit_set(NodeType *set) + { /* {{{ */ + commit_test2(set,"set",INSTR_SET); + } /* }}} */ + + /* PLUS_EQ */ + static NodeType *new_plus_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("plus_eq", OPR_PLUS_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_plus_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("add %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "add", INSTR_ADD, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* SUB_EQ */ + static NodeType *new_sub_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("sub_eq", OPR_SUB_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_sub_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("sub %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "sub", INSTR_SUB, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* MUL_EQ */ + static NodeType *new_mul_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("mul_eq", OPR_MUL_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_mul_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("mul %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "mul", INSTR_MUL, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* DIV_EQ */ + static NodeType *new_div_eq(NodeType *lvalue, NodeType *expression) /* {{{ */ + { + NodeType *set = new_op("div_eq", OPR_PLUS_EQ, 2); + set->unode.opr.op[0] = lvalue; + set->unode.opr.op[1] = expression; + return set; + } + static void commit_div_eq(NodeType *set) + { + precommit_node(set->unode.opr.op[1]); +#ifdef VERBOSE + printf("div %s %s\n", set->unode.opr.op[0]->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "div", INSTR_DIV, 2, set->line_number); + commit_node(set->unode.opr.op[0],0); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* commodity method for add, mult, ... */ + + static void precommit_expr(NodeType *expr, const char *type, int instr_id) + { /* {{{ */ + NodeType *tmp, *tmpcpy; + int toAdd; + + /* compute "left" and "right" */ + switch (expr->unode.opr.nbOp) { + case 2: + precommit_node(expr->unode.opr.op[1]); + case 1: + precommit_node(expr->unode.opr.op[0]); + } + + if (is_tmp_expr(expr->unode.opr.op[0])) { + tmp = expr->unode.opr.op[0]; + toAdd = 1; + } + else if (is_commutative_expr(instr_id) && (expr->unode.opr.nbOp==2) && is_tmp_expr(expr->unode.opr.op[1])) { + tmp = expr->unode.opr.op[1]; + toAdd = 0; + } + else { + char stmp[256]; + /* declare a float to store the result */ + if (expr->unode.opr.op[0]->type == CONST_INT_NODE) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (expr->unode.opr.op[0]->type == CONST_FLOAT_NODE) { + sprintf(stmp,"_f_tmp%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (expr->unode.opr.op[0]->type == CONST_PTR_NODE) { + sprintf(stmp,"_p_tmp%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + else { + HashValue *val = goom_hash_get(expr->unode.opr.op[0]->vnamespace, expr->unode.opr.op[0]->str); + if (val && (val->i == INSTR_FLOAT)) { + sprintf(stmp,"_f_tmp_%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (val && (val->i == INSTR_PTR)) { + sprintf(stmp,"_p_tmp_%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + else if (val && (val->i == INSTR_INT)) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (val == 0) { + fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", expr->line_number, expr->unode.opr.op[0]->str); + exit(1); + } + } + tmp = new_var(stmp,expr->line_number); + + /* set the tmp to the value of "op1" */ + tmpcpy = nodeClone(tmp); + commit_node(new_set(tmp,expr->unode.opr.op[0]),0); + toAdd = 1; + + tmp = tmpcpy; + } + + /* add op2 to tmp */ +#ifdef VERBOSE + if (expr->unode.opr.nbOp == 2) + printf("%s %s %s\n", type, tmp->str, expr->unode.opr.op[toAdd]->str); + else + printf("%s %s\n", type, tmp->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, type, instr_id, expr->unode.opr.nbOp, expr->line_number); + tmpcpy = nodeClone(tmp); + commit_node(tmp,0); + if (expr->unode.opr.nbOp == 2) { + commit_node(expr->unode.opr.op[toAdd],1); + } + + /* redefine the ADD node now as the computed variable */ + nodeFreeInternals(expr); + *expr = *tmpcpy; + free(tmpcpy); + } /* }}} */ + + static NodeType *new_expr1(const char *name, int id, NodeType *expr1) + { /* {{{ */ + NodeType *add = new_op(name, id, 1); + add->unode.opr.op[0] = expr1; + return add; + } /* }}} */ + + static NodeType *new_expr2(const char *name, int id, NodeType *expr1, NodeType *expr2) + { /* {{{ */ + NodeType *add = new_op(name, id, 2); + add->unode.opr.op[0] = expr1; + add->unode.opr.op[1] = expr2; + return add; + } /* }}} */ + + /* ADD */ + static NodeType *new_add(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("add", OPR_ADD, expr1, expr2); + } + static void precommit_add(NodeType *add) { + precommit_expr(add,"add",INSTR_ADD); + } /* }}} */ + + /* SUB */ + static NodeType *new_sub(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("sub", OPR_SUB, expr1, expr2); + } + static void precommit_sub(NodeType *sub) { + precommit_expr(sub,"sub",INSTR_SUB); + } /* }}} */ + + /* MUL */ + static NodeType *new_mul(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("mul", OPR_MUL, expr1, expr2); + } + static void precommit_mul(NodeType *mul) { + precommit_expr(mul,"mul",INSTR_MUL); + } /* }}} */ + + /* DIV */ + static NodeType *new_div(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("div", OPR_DIV, expr1, expr2); + } + static void precommit_div(NodeType *mul) { + precommit_expr(mul,"div",INSTR_DIV); + } /* }}} */ + + /* CALL EXPRESSION */ + static NodeType *new_call_expr(const char *name, NodeType *affect_list) { /* {{{ */ + NodeType *call = new_call(name,affect_list); + NodeType *node = new_expr1(name, OPR_CALL_EXPR, call); + node->vnamespace = gsl_find_namespace(name); + if (node->vnamespace == NULL) + fprintf(stderr, "ERROR: Line %d, No return type for: '%s'\n", currentGoomSL->num_lines, name); + return node; + } + static void precommit_call_expr(NodeType *call) { + char stmp[256]; + NodeType *tmp,*tmpcpy; + HashValue *val = goom_hash_get(call->vnamespace, call->str); + if (val && (val->i == INSTR_FLOAT)) { + sprintf(stmp,"_f_tmp_%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (val && (val->i == INSTR_PTR)) { + sprintf(stmp,"_p_tmp_%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + else if (val && (val->i == INSTR_INT)) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (val == 0) { + fprintf(stderr, "ERROR: Line %d, Could not find variable '%s'\n", call->line_number, call->str); + exit(1); + } + tmp = new_var(stmp,call->line_number); + commit_node(call->unode.opr.op[0],0); + tmpcpy = nodeClone(tmp); + commit_node(new_set(tmp,new_var(call->str,call->line_number)),0); + + nodeFreeInternals(call); + *call = *tmpcpy; + free(tmpcpy); + } /* }}} */ + + static void commit_test2(NodeType *set,const char *type, int instr) + { /* {{{ */ + NodeType *tmp; + char stmp[256]; + precommit_node(set->unode.opr.op[0]); + precommit_node(set->unode.opr.op[1]); + tmp = set->unode.opr.op[0]; + + stmp[0] = 0; + if (set->unode.opr.op[0]->type == CONST_INT_NODE) { + sprintf(stmp,"_i_tmp_%i",allocateTemp()); + gsl_int_decl_global(stmp); + } + else if (set->unode.opr.op[0]->type == CONST_FLOAT_NODE) { + sprintf(stmp,"_f_tmp%i",allocateTemp()); + gsl_float_decl_global(stmp); + } + else if (set->unode.opr.op[0]->type == CONST_PTR_NODE) { + sprintf(stmp,"_p_tmp%i",allocateTemp()); + gsl_ptr_decl_global(stmp); + } + if (stmp[0]) { + NodeType *tmpcpy; + tmp = new_var(stmp, set->line_number); + tmpcpy = nodeClone(tmp); + commit_node(new_set(tmp,set->unode.opr.op[0]),0); + tmp = tmpcpy; + } + +#ifdef VERBOSE + printf("%s %s %s\n", type, tmp->str, set->unode.opr.op[1]->str); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, type, instr, 2, set->line_number); + commit_node(tmp,instr!=INSTR_SET); + commit_node(set->unode.opr.op[1],1); + } /* }}} */ + + /* NOT */ + static NodeType *new_not(NodeType *expr1) { /* {{{ */ + return new_expr1("not", OPR_NOT, expr1); + } + static void commit_not(NodeType *set) + { + commit_node(set->unode.opr.op[0],0); +#ifdef VERBOSE + printf("not\n"); +#endif + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "not", INSTR_NOT, 1, set->line_number); + gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); + } /* }}} */ + + /* EQU */ + static NodeType *new_equ(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("isequal", OPR_EQU, expr1, expr2); + } + static void commit_equ(NodeType *mul) { + commit_test2(mul,"isequal",INSTR_ISEQUAL); + } /* }}} */ + + /* INF */ + static NodeType *new_low(NodeType *expr1, NodeType *expr2) { /* {{{ */ + return new_expr2("islower", OPR_LOW, expr1, expr2); + } + static void commit_low(NodeType *mul) { + commit_test2(mul,"islower",INSTR_ISLOWER); + } /* }}} */ + + /* WHILE */ + static NodeType *new_while(NodeType *expression, NodeType *instr) { /* {{{ */ + NodeType *node = new_op("while", OPR_WHILE, 2); + node->unode.opr.op[0] = expression; + node->unode.opr.op[1] = instr; + return node; + } + + static void commit_while(NodeType *node) + { + int lbl = allocateLabel(); + char start_while[1024], test_while[1024]; + sprintf(start_while, "|start_while_%d|", lbl); + sprintf(test_while, "|test_while_%d|", lbl); + + GSL_PUT_JUMP(test_while,node->line_number); + GSL_PUT_LABEL(start_while,node->line_number); + + /* code */ + commit_node(node->unode.opr.op[1],0); + + GSL_PUT_LABEL(test_while,node->line_number); + commit_node(node->unode.opr.op[0],0); + GSL_PUT_JNZERO(start_while,node->line_number); + } /* }}} */ + + /* IF */ + static NodeType *new_if(NodeType *expression, NodeType *instr) { /* {{{ */ + NodeType *node = new_op("if", OPR_IF, 2); + node->unode.opr.op[0] = expression; + node->unode.opr.op[1] = instr; + return node; + } + static void commit_if(NodeType *node) { + + char slab[1024]; + sprintf(slab, "|eif%d|", allocateLabel()); + commit_node(node->unode.opr.op[0],0); + GSL_PUT_JZERO(slab,node->line_number); + /* code */ + commit_node(node->unode.opr.op[1],0); + GSL_PUT_LABEL(slab,node->line_number); + } /* }}} */ + + /* BLOCK */ + static NodeType *new_block(NodeType *lastNode) { /* {{{ */ + NodeType *blk = new_op("block", OPR_BLOCK, 2); + blk->unode.opr.op[0] = new_nop("start_of_block"); + blk->unode.opr.op[1] = lastNode; + return blk; + } + static void commit_block(NodeType *node) { + commit_node(node->unode.opr.op[0]->unode.opr.next,0); + } /* }}} */ + + /* FUNCTION INTRO */ + static NodeType *new_function_intro(const char *name) { /* {{{ */ + char stmp[256]; + if (strlen(name) < 200) { + sprintf(stmp, "|__func_%s|", name); + } + return new_op(stmp, OPR_FUNC_INTRO, 0); + } + static void commit_function_intro(NodeType *node) { + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "label", INSTR_LABEL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_LABEL); +#ifdef VERBOSE + printf("label %s\n", node->str); +#endif + } /* }}} */ + + /* FUNCTION OUTRO */ + static NodeType *new_function_outro(void) { /* {{{ */ + return new_op("ret", OPR_FUNC_OUTRO, 0); + } + static void commit_function_outro(NodeType *node) { + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "ret", INSTR_RET, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, "|dummy|", TYPE_LABEL); + releaseAllTemps(); +#ifdef VERBOSE + printf("ret\n"); +#endif + } /* }}} */ + + /* FUNCTION CALL */ + static NodeType *new_call(const char *name, NodeType *affect_list) { /* {{{ */ + HashValue *fval; + fval = goom_hash_get(currentGoomSL->functions, name); + if (!fval) { + gsl_declare_task(name); + fval = goom_hash_get(currentGoomSL->functions, name); + } + if (!fval) { + fprintf(stderr, "ERROR: Line %d, Could not find function %s\n", currentGoomSL->num_lines, name); + exit(1); + return NULL; + } + else { + ExternalFunctionStruct *gef = (ExternalFunctionStruct*)fval->ptr; + if (gef->is_extern) { + NodeType *node = new_op(name, OPR_EXT_CALL, 1); + node->unode.opr.op[0] = affect_list; + return node; + } + else { + NodeType *node; + char stmp[256]; + if (strlen(name) < 200) { + sprintf(stmp, "|__func_%s|", name); + } + node = new_op(stmp, OPR_CALL, 1); + node->unode.opr.op[0] = affect_list; + return node; + } + } + } + static void commit_ext_call(NodeType *node) { + commit_node(node->unode.opr.op[0],0); + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "extcall", INSTR_EXT_CALL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_VAR); +#ifdef VERBOSE + printf("extcall %s\n", node->str); +#endif + } + static void commit_call(NodeType *node) { + commit_node(node->unode.opr.op[0],0); + currentGoomSL->instr = gsl_instr_init(currentGoomSL, "call", INSTR_CALL, 1, node->line_number); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_LABEL); +#ifdef VERBOSE + printf("call %s\n", node->str); +#endif + } /* }}} */ + + /* AFFECTATION LIST */ + static NodeType *new_affec_list(NodeType *set, NodeType *next) + { + NodeType *node = new_op("affect_list", OPR_AFFECT_LIST, 2); + node->unode.opr.op[0] = set; + node->unode.opr.op[1] = next; + return node; + } + static void commit_affect_list(NodeType *node) + { + NodeType *cur = node; + while(cur != NULL) { + NodeType *set = cur->unode.opr.op[0]; + precommit_node(set->unode.opr.op[0]); + precommit_node(set->unode.opr.op[1]); + cur = cur->unode.opr.op[1]; + } + cur = node; + while(cur != NULL) { + NodeType *set = cur->unode.opr.op[0]; + commit_node(set,0); + cur = cur->unode.opr.op[1]; + } + } + + /** **/ + + static NodeType *rootNode = 0; /* TODO: reinitialiser a chaque compilation. */ + static NodeType *lastNode = 0; + static NodeType *gsl_append(NodeType *curNode) { + if (curNode == 0) return 0; /* {{{ */ + if (lastNode) + lastNode->unode.opr.next = curNode; + lastNode = curNode; + while(lastNode->unode.opr.next) lastNode = lastNode->unode.opr.next; + if (rootNode == 0) + rootNode = curNode; + return curNode; + } /* }}} */ + +#if 1 + static int allocateTemp(void) { + return allocateLabel(); + } + static void releaseAllTemps(void) {} + static void releaseTemp(int n) {} +#else + static int nbTemp = 0; + static int *tempArray = 0; + static int tempArraySize = 0; + static int allocateTemp(void) { /* TODO: allocateITemp, allocateFTemp */ + int i = 0; /* {{{ */ + if (tempArray == 0) { + tempArraySize = 256; + tempArray = (int*)malloc(tempArraySize * sizeof(int)); + } + while (1) { + int j; + for (j=0;j<nbTemp;++j) { + if (tempArray[j] == i) break; + } + if (j == nbTemp) { + if (nbTemp == tempArraySize) { + tempArraySize *= 2; + tempArray = (int*)realloc(tempArray,tempArraySize * sizeof(int)); + } + tempArray[nbTemp++] = i; + return i; + } + i++; + } + } /* }}} */ + static void releaseAllTemps(void) { + nbTemp = 0; /* {{{ */ + } /* }}} */ + static void releaseTemp(int n) { + int j; /* {{{ */ + for (j=0;j<nbTemp;++j) { + if (tempArray[j] == n) { + tempArray[j] = tempArray[--nbTemp]; + break; + } + } + } /* }}} */ +#endif + + static int lastLabel = 0; + static int allocateLabel(void) { + return ++lastLabel; /* {{{ */ + } /* }}} */ + + void gsl_commit_compilation(void) + { /* {{{ */ + commit_node(rootNode,0); + rootNode = 0; + lastNode = 0; + } /* }}} */ + + void precommit_node(NodeType *node) + { /* {{{ */ + /* do here stuff for expression.. for exemple */ + if (node->type == OPR_NODE) + switch(node->unode.opr.type) { + case OPR_ADD: precommit_add(node); break; + case OPR_SUB: precommit_sub(node); break; + case OPR_MUL: precommit_mul(node); break; + case OPR_DIV: precommit_div(node); break; + case OPR_CALL_EXPR: precommit_call_expr(node); break; + } + } /* }}} */ + + void commit_node(NodeType *node, int releaseIfTmp) + { /* {{{ */ + if (node == 0) return; + + switch(node->type) { + case OPR_NODE: + switch(node->unode.opr.type) { + case OPR_SET: commit_set(node); break; + case OPR_PLUS_EQ: commit_plus_eq(node); break; + case OPR_SUB_EQ: commit_sub_eq(node); break; + case OPR_MUL_EQ: commit_mul_eq(node); break; + case OPR_DIV_EQ: commit_div_eq(node); break; + case OPR_IF: commit_if(node); break; + case OPR_WHILE: commit_while(node); break; + case OPR_BLOCK: commit_block(node); break; + case OPR_FUNC_INTRO: commit_function_intro(node); break; + case OPR_FUNC_OUTRO: commit_function_outro(node); break; + case OPR_CALL: commit_call(node); break; + case OPR_EXT_CALL: commit_ext_call(node); break; + case OPR_EQU: commit_equ(node); break; + case OPR_LOW: commit_low(node); break; + case OPR_NOT: commit_not(node); break; + case OPR_AFFECT_LIST: commit_affect_list(node); break; +#ifdef VERBOSE + case EMPTY_NODE: printf("NOP\n"); break; +#endif + } + + commit_node(node->unode.opr.next,0); /* recursive for the moment, maybe better to do something iterative? */ + break; + + case VAR_NODE: gsl_instr_set_namespace(currentGoomSL->instr, node->vnamespace); + gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_VAR); break; + case CONST_INT_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_INTEGER); break; + case CONST_FLOAT_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_FLOAT); break; + case CONST_PTR_NODE: gsl_instr_add_param(currentGoomSL->instr, node->str, TYPE_PTR); break; + } + if (releaseIfTmp && is_tmp_expr(node)) + releaseTemp(get_tmp_id(node)); + + nodeFree(node); + } /* }}} */ + + NodeType *nodeNew(const char *str, int type, int line_number) { + NodeType *node = (NodeType*)malloc(sizeof(NodeType)); /* {{{ */ + node->type = type; + node->str = (char*)malloc(strlen(str)+1); + node->vnamespace = NULL; + node->line_number = line_number; + strcpy(node->str, str); + return node; + } /* }}} */ + static NodeType *nodeClone(NodeType *node) { + NodeType *ret = nodeNew(node->str, node->type, node->line_number); /* {{{ */ + ret->vnamespace = node->vnamespace; + ret->unode = node->unode; + return ret; + } /* }}} */ + + void nodeFreeInternals(NodeType *node) { + free(node->str); /* {{{ */ + } /* }}} */ + + void nodeFree(NodeType *node) { + nodeFreeInternals(node); /* {{{ */ + free(node); + } /* }}} */ + + NodeType *new_constInt(const char *str, int line_number) { + NodeType *node = nodeNew(str, CONST_INT_NODE, line_number); /* {{{ */ + node->unode.constInt.val = atoi(str); + return node; + } /* }}} */ + + NodeType *new_constPtr(const char *str, int line_number) { + NodeType *node = nodeNew(str, CONST_PTR_NODE, line_number); /* {{{ */ + node->unode.constPtr.id = strtol(str,NULL,0); + return node; + } /* }}} */ + + NodeType *new_constFloat(const char *str, int line_number) { + NodeType *node = nodeNew(str, CONST_FLOAT_NODE, line_number); /* {{{ */ + node->unode.constFloat.val = atof(str); + return node; + } /* }}} */ + + NodeType *new_var(const char *str, int line_number) { + NodeType *node = nodeNew(str, VAR_NODE, line_number); /* {{{ */ + node->vnamespace = gsl_find_namespace(str); + if (node->vnamespace == 0) { + fprintf(stderr, "ERROR: Line %d, Variable not found: '%s'\n", line_number, str); + exit(1); + } + return node; + } /* }}} */ + + NodeType *new_nop(const char *str) { + NodeType *node = new_op(str, EMPTY_NODE, 0); /* {{{ */ + return node; + } /* }}} */ + + NodeType *new_op(const char *str, int type, int nbOp) { + int i; /* {{{ */ + NodeType *node = nodeNew(str, OPR_NODE, currentGoomSL->num_lines); + node->unode.opr.next = 0; + node->unode.opr.type = type; + node->unode.opr.nbOp = nbOp; + for (i=0;i<nbOp;++i) node->unode.opr.op[i] = 0; + return node; + } /* }}} */ + + + static void DECL_VAR(int type, char *name) { + switch(type){ + case FLOAT_TK:gsl_float_decl_global(name);break; + case INT_TK: gsl_int_decl_global(name);break; + case PTR_TK: gsl_ptr_decl_global(name);break; + } + } + + +#line 806 "goomsl_yacc.y" +typedef union { + int intValue; + float floatValue; + char charValue; + char strValue[2048]; + NodeType *nPtr; + } YYSTYPE; +#include <stdio.h> + +#ifndef __cplusplus +#ifndef __STDC__ +#define const +#endif +#endif + + + +#define YYFINAL 149 +#define YYFLAG -32768 +#define YYNTBASE 38 + +#define YYTRANSLATE(x) ((unsigned)(x) <= 274 ? yytranslate[x] : 59) + +static const char yytranslate[] = { 0, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 28, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 31, + 32, 26, 24, 30, 25, 2, 27, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 29, 2, 22, + 21, 23, 33, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 36, 2, 37, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 34, 2, 35, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 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, 3, 4, 5, 6, + 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 17, 18, 19, 20 +}; + +#if YYDEBUG != 0 +static const short yyprhs[] = { 0, + 0, 4, 7, 16, 27, 36, 47, 50, 51, 52, + 55, 58, 61, 63, 66, 67, 71, 76, 83, 84, + 86, 87, 89, 93, 98, 103, 108, 111, 114, 117, + 120, 123, 130, 137, 144, 146, 150, 154, 158, 162, + 164, 165, 169, 175, 178, 180, 184, 185, 187, 189, + 193, 197, 201, 205, 209, 214, 221, 223, 227, 231, + 235, 239, 243, 246, 248, 250 +}; + +static const short yyrhs[] = { 39, + 45, 42, 0, 39, 50, 0, 39, 11, 22, 41, + 23, 40, 28, 47, 0, 39, 11, 22, 41, 29, + 48, 23, 40, 28, 47, 0, 39, 10, 22, 46, + 23, 40, 28, 47, 0, 39, 10, 22, 46, 29, + 48, 23, 40, 28, 47, 0, 39, 28, 0, 0, + 0, 29, 8, 0, 29, 9, 0, 29, 7, 0, + 5, 0, 42, 43, 0, 0, 44, 39, 45, 0, + 22, 46, 23, 28, 0, 22, 46, 29, 48, 23, + 28, 0, 0, 5, 0, 0, 49, 0, 49, 30, + 48, 0, 9, 5, 21, 56, 0, 8, 5, 21, + 56, 0, 7, 5, 21, 56, 0, 9, 5, 0, + 8, 5, 0, 7, 5, 0, 54, 28, 0, 49, + 28, 0, 31, 57, 32, 33, 51, 50, 0, 12, + 57, 51, 13, 51, 50, 0, 34, 28, 55, 39, + 35, 28, 0, 52, 0, 5, 15, 56, 0, 5, + 16, 56, 0, 5, 18, 56, 0, 5, 17, 56, + 0, 28, 0, 0, 46, 28, 47, 0, 46, 29, + 53, 28, 47, 0, 54, 53, 0, 54, 0, 5, + 21, 56, 0, 0, 5, 0, 58, 0, 56, 26, + 56, 0, 56, 27, 56, 0, 56, 24, 56, 0, + 56, 25, 56, 0, 31, 56, 32, 0, 36, 46, + 47, 37, 0, 36, 46, 29, 53, 37, 47, 0, + 56, 0, 56, 21, 56, 0, 56, 22, 56, 0, + 56, 23, 56, 0, 56, 19, 56, 0, 56, 20, + 56, 0, 14, 57, 0, 4, 0, 3, 0, 6, + 0 +}; + +#endif + +#if YYDEBUG != 0 +static const short yyrline[] = { 0, + 835, 837, 838, 839, 840, 841, 842, 843, 846, 847, + 848, 849, 852, 854, 855, 858, 860, 861, 862, 864, + 865, 867, 868, 871, 872, 873, 874, 875, 876, 879, + 880, 881, 882, 883, 884, 885, 886, 887, 888, 891, + 891, 893, 894, 897, 898, 900, 903, 906, 907, 908, + 909, 910, 911, 912, 913, 914, 917, 918, 919, 920, + 921, 922, 923, 926, 927, 928 +}; +#endif + + +#if YYDEBUG != 0 || defined (YYERROR_VERBOSE) + +static const char * const yytname[] = { "$","error","$undefined.","TYPE_INTEGER", +"TYPE_FLOAT","TYPE_VAR","TYPE_PTR","PTR_TK","INT_TK","FLOAT_TK","DECLARE","EXTERNAL", +"WHILE","DO","NOT","PLUS_EQ","SUB_EQ","DIV_EQ","MUL_EQ","SUP_EQ","LOW_EQ","'='", +"'<'","'>'","'+'","'-'","'*'","'/'","'\\n'","':'","','","'('","')'","'?'","'{'", +"'}'","'['","']'","gsl","gsl_code","return_type","ext_task_name","gsl_def_functions", +"function","function_intro","function_outro","task_name","leave_namespace","arglist", +"declaration","instruction","opt_nl","func_call","affectations","affectation", +"start_block","expression","test","constValue", NULL +}; +#endif + +static const short yyr1[] = { 0, + 38, 39, 39, 39, 39, 39, 39, 39, 40, 40, + 40, 40, 41, 42, 42, 43, 44, 44, 45, 46, + 47, 48, 48, 49, 49, 49, 49, 49, 49, 50, + 50, 50, 50, 50, 50, 50, 50, 50, 50, 51, + 51, 52, 52, 53, 53, 54, 55, 56, 56, 56, + 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, + 57, 57, 57, 58, 58, 58 +}; + +static const short yyr2[] = { 0, + 3, 2, 8, 10, 8, 10, 2, 0, 0, 2, + 2, 2, 1, 2, 0, 3, 4, 6, 0, 1, + 0, 1, 3, 4, 4, 4, 2, 2, 2, 2, + 2, 6, 6, 6, 1, 3, 3, 3, 3, 1, + 0, 3, 5, 2, 1, 3, 0, 1, 1, 3, + 3, 3, 3, 3, 4, 6, 1, 3, 3, 3, + 3, 3, 2, 1, 1, 1 +}; + +static const short yydefact[] = { 8, + 19, 20, 0, 0, 0, 0, 0, 0, 7, 0, + 0, 15, 0, 0, 2, 35, 0, 0, 0, 0, + 0, 0, 29, 28, 27, 0, 0, 65, 64, 48, + 66, 0, 0, 0, 57, 41, 49, 0, 47, 1, + 21, 0, 31, 30, 36, 37, 39, 38, 46, 0, + 0, 0, 20, 0, 13, 0, 63, 0, 21, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 40, 0, + 0, 8, 0, 14, 8, 42, 0, 0, 45, 26, + 25, 24, 9, 0, 9, 0, 54, 0, 0, 61, + 62, 58, 59, 60, 52, 53, 50, 51, 41, 41, + 0, 0, 19, 21, 44, 0, 0, 0, 22, 0, + 0, 0, 55, 0, 0, 0, 0, 0, 16, 43, + 12, 10, 11, 21, 9, 0, 21, 9, 21, 33, + 32, 34, 17, 0, 5, 0, 23, 3, 0, 56, + 0, 21, 21, 18, 6, 4, 0, 0, 0 +}; + +static const short yydefgoto[] = { 147, + 1, 107, 56, 40, 74, 75, 12, 13, 76, 108, + 14, 15, 70, 16, 78, 17, 72, 35, 36, 37 +}; + +static const short yypact[] = {-32768, + 111, 131, -3, 8, 10, 3, 5, 26,-32768, 26, + -5,-32768, 47, 6,-32768,-32768, 35, 68, 68, 68, + 68, 68, 46, 48, 56, 77, 92,-32768,-32768,-32768, +-32768, 26, 68, 77, 109, 75,-32768, 85,-32768, 103, +-32768, 121,-32768,-32768, 69, 69, 69, 69, 69, 68, + 68, 68,-32768, -13,-32768, -9,-32768, 54, 108, 68, + 68, 68, 68, 68, 68, 68, 68, 68,-32768, 125, + 107,-32768, 77,-32768,-32768,-32768, 120, 115, 121, 69, + 69, 69, 122, 52, 122, 52,-32768, 121, 113, 69, + 69, 69, 69, 69, 83, 83, 117,-32768, 75, 75, + 80, -1, 111,-32768,-32768, 146, 128, 134, 129, 130, + 137, 124,-32768, 93, 93, 135, 136, 52,-32768,-32768, +-32768,-32768,-32768,-32768, 122, 52,-32768, 122,-32768,-32768, +-32768,-32768,-32768, 139,-32768, 138,-32768,-32768, 140,-32768, + 141,-32768,-32768,-32768,-32768,-32768, 165, 167,-32768 +}; + +static const short yypgoto[] = {-32768, + -33, -84,-32768,-32768,-32768,-32768, 67, -17, -59, -83, + -60, -8, 13,-32768, -67, -24,-32768, -14, 1,-32768 +}; + + +#define YYLAST 170 + + +static const short yytable[] = { 89, + 110, 23, 111, 45, 46, 47, 48, 49, 54, 83, + 38, 105, 24, 85, 25, 84, 59, 79, 58, 86, + 112, 117, 39, 109, 26, 109, 27, 118, 28, 29, + 30, 31, 57, 43, 134, 80, 81, 82, 101, 32, + 136, 103, 137, 139, 120, 90, 91, 92, 93, 94, + 95, 96, 97, 98, 79, 102, 33, 109, 3, 4, + 5, 34, 44, 79, 135, 109, 50, 138, 51, 140, + 28, 29, 30, 31, 41, 42, 52, 65, 66, 67, + 68, 53, 145, 146, 2, 87, 3, 4, 5, 6, + 7, 8, 65, 66, 67, 68, 55, 2, 33, 3, + 4, 5, 69, 34, 8, 130, 131, 9, 67, 68, + 10, 114, 115, 11, 116, 2, 71, 3, 4, 5, + 6, 7, 8, 10, 73, 77, 11, 60, 61, 62, + 63, 64, 65, 66, 67, 68, 88, 99, 9, 100, + 22, 10, 104, 68, 11, 18, 19, 20, 21, 113, + 106, 22, 121, 122, 123, 124, 125, 127, 126, 128, + 129, 141, 132, 133, 148, 142, 149, 143, 144, 119 +}; + +static const short yycheck[] = { 59, + 85, 5, 86, 18, 19, 20, 21, 22, 26, 23, + 10, 79, 5, 23, 5, 29, 34, 42, 33, 29, + 88, 23, 28, 84, 22, 86, 22, 29, 3, 4, + 5, 6, 32, 28, 118, 50, 51, 52, 72, 14, + 125, 75, 126, 128, 104, 60, 61, 62, 63, 64, + 65, 66, 67, 68, 79, 73, 31, 118, 7, 8, + 9, 36, 28, 88, 124, 126, 21, 127, 21, 129, + 3, 4, 5, 6, 28, 29, 21, 24, 25, 26, + 27, 5, 142, 143, 5, 32, 7, 8, 9, 10, + 11, 12, 24, 25, 26, 27, 5, 5, 31, 7, + 8, 9, 28, 36, 12, 114, 115, 28, 26, 27, + 31, 99, 100, 34, 35, 5, 32, 7, 8, 9, + 10, 11, 12, 31, 22, 5, 34, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 29, 13, 28, 33, + 21, 31, 28, 27, 34, 15, 16, 17, 18, 37, + 29, 21, 7, 8, 9, 28, 23, 28, 30, 23, + 37, 23, 28, 28, 0, 28, 0, 28, 28, 103 +}; +/* -*-C-*- Note some compilers choke on comments on `#line' lines. */ +#line 3 "/usr/share/bison.simple" +/* This file comes from bison-1.28. */ + +/* Skeleton output parser for bison, + Copyright (C) 1984, 1989, 1990 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* This is the parser code that is written into each bison parser + when the %semantic_parser declaration is not specified in the grammar. + It was written by Richard Stallman by simplifying the hairy parser + used when %semantic_parser is specified. */ + +#ifndef YYSTACK_USE_ALLOCA +#ifdef alloca +#define YYSTACK_USE_ALLOCA +#else /* alloca not defined */ +#ifdef __GNUC__ +#define YYSTACK_USE_ALLOCA +#define alloca __builtin_alloca +#else /* not GNU C. */ +#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__) || defined (__sparc) || defined (__sgi) || (defined (__sun) && defined (__i386)) +#define YYSTACK_USE_ALLOCA +#include <alloca.h> +#else /* not sparc */ +/* We think this test detects Watcom and Microsoft C. */ +/* This used to test MSDOS, but that is a bad idea + since that symbol is in the user namespace. */ +#if (defined (_MSDOS) || defined (_MSDOS_)) && !defined (__TURBOC__) +#if 0 /* No need for malloc.h, which pollutes the namespace; + instead, just don't use alloca. */ +#include <malloc.h> +#endif +#else /* not MSDOS, or __TURBOC__ */ +#if defined(_AIX) +/* I don't know what this was needed for, but it pollutes the namespace. + So I turned it off. rms, 2 May 1997. */ +/* #include <malloc.h> */ + #pragma alloca +#define YYSTACK_USE_ALLOCA +#else /* not MSDOS, or __TURBOC__, or _AIX */ +#if 0 +#ifdef __hpux /* haible@ilog.fr says this works for HPUX 9.05 and up, + and on HPUX 10. Eventually we can turn this on. */ +#define YYSTACK_USE_ALLOCA +#define alloca __builtin_alloca +#endif /* __hpux */ +#endif +#endif /* not _AIX */ +#endif /* not MSDOS, or __TURBOC__ */ +#endif /* not sparc */ +#endif /* not GNU C */ +#endif /* alloca not defined */ +#endif /* YYSTACK_USE_ALLOCA not defined */ + +#ifdef YYSTACK_USE_ALLOCA +#define YYSTACK_ALLOC alloca +#else +#define YYSTACK_ALLOC malloc +#endif + +/* Note: there must be only one dollar sign in this file. + It is replaced by the list of actions, each action + as one case of the switch. */ + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY -2 +#define YYEOF 0 +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 +/* Like YYERROR except do call yyerror. + This remains here temporarily to ease the + transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ +#define YYFAIL goto yyerrlab +#define YYRECOVERING() (!!yyerrstatus) +#define YYBACKUP(token, value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { yychar = (token), yylval = (value); \ + yychar1 = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { yyerror ("syntax error: cannot back up"); YYERROR; } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +#ifndef YYPURE +#define YYLEX yylex() +#endif + +#ifdef YYPURE +#ifdef YYLSP_NEEDED +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, &yylloc, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval, &yylloc) +#endif +#else /* not YYLSP_NEEDED */ +#ifdef YYLEX_PARAM +#define YYLEX yylex(&yylval, YYLEX_PARAM) +#else +#define YYLEX yylex(&yylval) +#endif +#endif /* not YYLSP_NEEDED */ +#endif + +/* If nonreentrant, generate the variables here */ + +#ifndef YYPURE + +int yychar; /* the lookahead symbol */ +YYSTYPE yylval; /* the semantic value of the */ + /* lookahead symbol */ + +#ifdef YYLSP_NEEDED +YYLTYPE yylloc; /* location data for the lookahead */ + /* symbol */ +#endif + +int yynerrs; /* number of parse errors so far */ +#endif /* not YYPURE */ + +#if YYDEBUG != 0 +int yydebug; /* nonzero means print parse trace */ +/* Since this is uninitialized, it does not stop multiple parsers + from coexisting. */ +#endif + +/* YYINITDEPTH indicates the initial size of the parser's stacks */ + +#ifndef YYINITDEPTH +#define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH is the maximum size the stacks can grow to + (effective only if the built-in stack extension method is used). */ + +#if YYMAXDEPTH == 0 +#undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +#define YYMAXDEPTH 10000 +#endif + +/* Define __yy_memcpy. Note that the size argument + should be passed with type unsigned int, because that is what the non-GCC + definitions require. With GCC, __builtin_memcpy takes an arg + of type size_t, but it can handle unsigned int. */ + +#if __GNUC__ > 1 /* GNU C and GNU C++ define this. */ +#define __yy_memcpy(TO,FROM,COUNT) __builtin_memcpy(TO,FROM,COUNT) +#else /* not GNU C or C++ */ +#ifndef __cplusplus + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (to, from, count) + char *to; + char *from; + unsigned int count; +{ + register char *f = from; + register char *t = to; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#else /* __cplusplus */ + +/* This is the most reliable way to avoid incompatibilities + in available built-in functions on various systems. */ +static void +__yy_memcpy (char *to, char *from, unsigned int count) +{ + register char *t = to; + register char *f = from; + register int i = count; + + while (i-- > 0) + *t++ = *f++; +} + +#endif +#endif + +#line 217 "/usr/share/bison.simple" + +/* The user can define YYPARSE_PARAM as the name of an argument to be passed + into yyparse. The argument should have type void *. + It should actually point to an object. + Grammar actions can access the variable by casting it + to the proper pointer type. */ + +#ifdef YYPARSE_PARAM +#ifdef __cplusplus +#define YYPARSE_PARAM_ARG void *YYPARSE_PARAM +#define YYPARSE_PARAM_DECL +#else /* not __cplusplus */ +#define YYPARSE_PARAM_ARG YYPARSE_PARAM +#define YYPARSE_PARAM_DECL void *YYPARSE_PARAM; +#endif /* not __cplusplus */ +#else /* not YYPARSE_PARAM */ +#define YYPARSE_PARAM_ARG +#define YYPARSE_PARAM_DECL +#endif /* not YYPARSE_PARAM */ + +/* Prevent warning if -Wstrict-prototypes. */ +#ifdef __GNUC__ +#ifdef YYPARSE_PARAM +int yyparse (void *); +#else +int yyparse (void); +#endif +#endif + +int +yyparse(YYPARSE_PARAM_ARG) + YYPARSE_PARAM_DECL +{ + 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 = 0; /* 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 */ + +#ifdef YYLSP_NEEDED + YYLTYPE yylsa[YYINITDEPTH]; /* the location stack */ + YYLTYPE *yyls = yylsa; + YYLTYPE *yylsp; + +#define YYPOPSTACK (yyvsp--, yyssp--, yylsp--) +#else +#define YYPOPSTACK (yyvsp--, yyssp--) +#endif + + int yystacksize = YYINITDEPTH; + int yyfree_stacks = 0; + +#ifdef YYPURE + int yychar; + YYSTYPE yylval; + int yynerrs; +#ifdef YYLSP_NEEDED + YYLTYPE yylloc; +#endif +#endif + + YYSTYPE yyval; /* the variable used to return */ + /* semantic values from the action */ + /* routines */ + + int yylen; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Starting parse\n"); +#endif + + 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. + The wasted elements are never initialized. */ + + yyssp = yyss - 1; + yyvsp = yyvs; +#ifdef YYLSP_NEEDED + yylsp = yyls; +#endif + +/* 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; +#ifdef YYLSP_NEEDED + YYLTYPE *yyls1 = yyls; +#endif + + /* Get the current used size of the three stacks, in elements. */ + int size = yyssp - yyss + 1; + +#ifdef yyoverflow + /* Each stack pointer address is followed by the size of + the data in use in that stack, in bytes. */ +#ifdef YYLSP_NEEDED + /* This used to be a conditional around just the two extra args, + but that might be undefined if yyoverflow is a macro. */ + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yyls1, size * sizeof (*yylsp), + &yystacksize); +#else + yyoverflow("parser stack overflow", + &yyss1, size * sizeof (*yyssp), + &yyvs1, size * sizeof (*yyvsp), + &yystacksize); +#endif + + yyss = yyss1; yyvs = yyvs1; +#ifdef YYLSP_NEEDED + yyls = yyls1; +#endif +#else /* no yyoverflow */ + /* Extend the stack our own way. */ + if (yystacksize >= YYMAXDEPTH) + { + yyerror("parser stack overflow"); + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 2; + } + yystacksize *= 2; + if (yystacksize > YYMAXDEPTH) + yystacksize = YYMAXDEPTH; +#ifndef YYSTACK_USE_ALLOCA + yyfree_stacks = 1; +#endif + yyss = (short *) YYSTACK_ALLOC (yystacksize * sizeof (*yyssp)); + __yy_memcpy ((char *)yyss, (char *)yyss1, + size * (unsigned int) sizeof (*yyssp)); + yyvs = (YYSTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yyvsp)); + __yy_memcpy ((char *)yyvs, (char *)yyvs1, + size * (unsigned int) sizeof (*yyvsp)); +#ifdef YYLSP_NEEDED + yyls = (YYLTYPE *) YYSTACK_ALLOC (yystacksize * sizeof (*yylsp)); + __yy_memcpy ((char *)yyls, (char *)yyls1, + size * (unsigned int) sizeof (*yylsp)); +#endif +#endif /* no yyoverflow */ + + yyssp = yyss + size - 1; + yyvsp = yyvs + size - 1; +#ifdef YYLSP_NEEDED + yylsp = yyls + size - 1; +#endif + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Stack size increased to %d\n", yystacksize); +#endif + + if (yyssp >= yyss + yystacksize - 1) + YYABORT; + } + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Entering state %d\n", yystate); +#endif + + goto yybackup; + 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) + { +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Reading a token: "); +#endif + 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 */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Now at end of input.\n"); +#endif + } + else + { + yychar1 = YYTRANSLATE(yychar); + +#if YYDEBUG != 0 + if (yydebug) + { + fprintf (stderr, "Next token is %d (%s", yychar, yytname[yychar1]); + /* Give the individual parser a way to print the precise meaning + of a token, for further debugging info. */ +#ifdef YYPRINT + YYPRINT (stderr, yychar, yylval); +#endif + fprintf (stderr, ")\n"); + } +#endif + } + + 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. */ + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting token %d (%s), ", yychar, yytname[yychar1]); +#endif + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + /* 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]; + if (yylen > 0) + yyval = yyvsp[1-yylen]; /* implement default value of the action */ + +#if YYDEBUG != 0 + if (yydebug) + { + int i; + + fprintf (stderr, "Reducing via rule %d (line %d), ", + yyn, yyrline[yyn]); + + /* Print the symbols being reduced, and their result. */ + for (i = yyprhs[yyn]; yyrhs[i] > 0; i++) + fprintf (stderr, "%s ", yytname[yyrhs[i]]); + fprintf (stderr, " -> %s\n", yytname[yyr1[yyn]]); + } +#endif + + + switch (yyn) { + +case 2: +#line 837 "goomsl_yacc.y" +{ gsl_append(yyvsp[0].nPtr); ; + break;} +case 3: +#line 838 "goomsl_yacc.y" +{ DECL_VAR(yyvsp[-2].intValue,yyvsp[-4].strValue); ; + break;} +case 4: +#line 839 "goomsl_yacc.y" +{ DECL_VAR(yyvsp[-2].intValue,yyvsp[-6].strValue); ; + break;} +case 5: +#line 840 "goomsl_yacc.y" +{ DECL_VAR(yyvsp[-2].intValue,yyvsp[-4].strValue); ; + break;} +case 6: +#line 841 "goomsl_yacc.y" +{ DECL_VAR(yyvsp[-2].intValue,yyvsp[-6].strValue); ; + break;} +case 9: +#line 846 "goomsl_yacc.y" +{ yyval.intValue=-1; ; + break;} +case 10: +#line 847 "goomsl_yacc.y" +{ yyval.intValue=INT_TK; ; + break;} +case 11: +#line 848 "goomsl_yacc.y" +{ yyval.intValue=FLOAT_TK; ; + break;} +case 12: +#line 849 "goomsl_yacc.y" +{ yyval.intValue=PTR_TK; ; + break;} +case 13: +#line 852 "goomsl_yacc.y" +{ gsl_declare_external_task(yyvsp[0].strValue); gsl_enternamespace(yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); ; + break;} +case 16: +#line 858 "goomsl_yacc.y" +{ gsl_leavenamespace(); ; + break;} +case 17: +#line 860 "goomsl_yacc.y" +{ gsl_append(new_function_intro(yyvsp[-2].strValue)); ; + break;} +case 18: +#line 861 "goomsl_yacc.y" +{ gsl_append(new_function_intro(yyvsp[-4].strValue)); ; + break;} +case 19: +#line 862 "goomsl_yacc.y" +{ gsl_append(new_function_outro()); ; + break;} +case 20: +#line 864 "goomsl_yacc.y" +{ gsl_declare_task(yyvsp[0].strValue); gsl_enternamespace(yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); strcpy(yyval.strValue,yyvsp[0].strValue); ; + break;} +case 21: +#line 865 "goomsl_yacc.y" +{ gsl_leavenamespace(); ; + break;} +case 22: +#line 867 "goomsl_yacc.y" +{ gsl_append(yyvsp[0].nPtr); ; + break;} +case 23: +#line 868 "goomsl_yacc.y" +{ gsl_append(yyvsp[-2].nPtr); ; + break;} +case 24: +#line 871 "goomsl_yacc.y" +{ gsl_float_decl(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); ; + break;} +case 25: +#line 872 "goomsl_yacc.y" +{ gsl_int_decl(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); ; + break;} +case 26: +#line 873 "goomsl_yacc.y" +{ gsl_ptr_decl(yyvsp[-2].strValue); yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines), yyvsp[0].nPtr); ; + break;} +case 27: +#line 874 "goomsl_yacc.y" +{ yyval.nPtr = 0; gsl_float_decl(yyvsp[0].strValue); ; + break;} +case 28: +#line 875 "goomsl_yacc.y" +{ yyval.nPtr = 0; gsl_int_decl(yyvsp[0].strValue); ; + break;} +case 29: +#line 876 "goomsl_yacc.y" +{ yyval.nPtr = 0; gsl_ptr_decl(yyvsp[0].strValue); ; + break;} +case 30: +#line 879 "goomsl_yacc.y" +{ yyval.nPtr = yyvsp[-1].nPtr; ; + break;} +case 31: +#line 880 "goomsl_yacc.y" +{ yyval.nPtr = yyvsp[-1].nPtr; ; + break;} +case 32: +#line 881 "goomsl_yacc.y" +{ yyval.nPtr = new_if(yyvsp[-4].nPtr,yyvsp[0].nPtr); ; + break;} +case 33: +#line 882 "goomsl_yacc.y" +{ yyval.nPtr = new_while(yyvsp[-4].nPtr,yyvsp[0].nPtr); ; + break;} +case 34: +#line 883 "goomsl_yacc.y" +{ lastNode = yyvsp[-3].nPtr->unode.opr.op[1]; yyval.nPtr=yyvsp[-3].nPtr; ; + break;} +case 35: +#line 884 "goomsl_yacc.y" +{ yyval.nPtr = yyvsp[0].nPtr; ; + break;} +case 36: +#line 885 "goomsl_yacc.y" +{ yyval.nPtr = new_plus_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); ; + break;} +case 37: +#line 886 "goomsl_yacc.y" +{ yyval.nPtr = new_sub_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); ; + break;} +case 38: +#line 887 "goomsl_yacc.y" +{ yyval.nPtr = new_mul_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); ; + break;} +case 39: +#line 888 "goomsl_yacc.y" +{ yyval.nPtr = new_div_eq(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); ; + break;} +case 42: +#line 893 "goomsl_yacc.y" +{ yyval.nPtr = new_call(yyvsp[-2].strValue,NULL); ; + break;} +case 43: +#line 894 "goomsl_yacc.y" +{ yyval.nPtr = new_call(yyvsp[-4].strValue,yyvsp[-2].nPtr); ; + break;} +case 44: +#line 897 "goomsl_yacc.y" +{ yyval.nPtr = new_affec_list(yyvsp[-1].nPtr,yyvsp[0].nPtr); ; + break;} +case 45: +#line 898 "goomsl_yacc.y" +{ yyval.nPtr = new_affec_list(yyvsp[0].nPtr,NULL); ; + break;} +case 46: +#line 900 "goomsl_yacc.y" +{ yyval.nPtr = new_set(new_var(yyvsp[-2].strValue,currentGoomSL->num_lines),yyvsp[0].nPtr); ; + break;} +case 47: +#line 903 "goomsl_yacc.y" +{ yyval.nPtr = new_block(lastNode); lastNode = yyval.nPtr->unode.opr.op[0]; ; + break;} +case 48: +#line 906 "goomsl_yacc.y" +{ yyval.nPtr = new_var(yyvsp[0].strValue,currentGoomSL->num_lines); ; + break;} +case 49: +#line 907 "goomsl_yacc.y" +{ yyval.nPtr = yyvsp[0].nPtr; ; + break;} +case 50: +#line 908 "goomsl_yacc.y" +{ yyval.nPtr = new_mul(yyvsp[-2].nPtr,yyvsp[0].nPtr); ; + break;} +case 51: +#line 909 "goomsl_yacc.y" +{ yyval.nPtr = new_div(yyvsp[-2].nPtr,yyvsp[0].nPtr); ; + break;} +case 52: +#line 910 "goomsl_yacc.y" +{ yyval.nPtr = new_add(yyvsp[-2].nPtr,yyvsp[0].nPtr); ; + break;} +case 53: +#line 911 "goomsl_yacc.y" +{ yyval.nPtr = new_sub(yyvsp[-2].nPtr,yyvsp[0].nPtr); ; + break;} +case 54: +#line 912 "goomsl_yacc.y" +{ yyval.nPtr = yyvsp[-1].nPtr; ; + break;} +case 55: +#line 913 "goomsl_yacc.y" +{ yyval.nPtr = new_call_expr(yyvsp[-2].strValue,NULL); ; + break;} +case 56: +#line 914 "goomsl_yacc.y" +{ yyval.nPtr = new_call_expr(yyvsp[-4].strValue,yyvsp[-2].nPtr); ; + break;} +case 57: +#line 917 "goomsl_yacc.y" +{ yyval.nPtr=yyvsp[0].nPtr; ; + break;} +case 58: +#line 918 "goomsl_yacc.y" +{ yyval.nPtr = new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr); ; + break;} +case 59: +#line 919 "goomsl_yacc.y" +{ yyval.nPtr = new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr); ; + break;} +case 60: +#line 920 "goomsl_yacc.y" +{ yyval.nPtr = new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr); ; + break;} +case 61: +#line 921 "goomsl_yacc.y" +{ yyval.nPtr = new_not(new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr)); ; + break;} +case 62: +#line 922 "goomsl_yacc.y" +{ yyval.nPtr = new_not(new_low(yyvsp[0].nPtr,yyvsp[-2].nPtr)); ; + break;} +case 63: +#line 923 "goomsl_yacc.y" +{ yyval.nPtr = new_not(yyvsp[0].nPtr); ; + break;} +case 64: +#line 926 "goomsl_yacc.y" +{ yyval.nPtr = new_constFloat(yyvsp[0].strValue,currentGoomSL->num_lines); ; + break;} +case 65: +#line 927 "goomsl_yacc.y" +{ yyval.nPtr = new_constInt(yyvsp[0].strValue,currentGoomSL->num_lines); ; + break;} +case 66: +#line 928 "goomsl_yacc.y" +{ yyval.nPtr = new_constPtr(yyvsp[0].strValue,currentGoomSL->num_lines); ; + break;} +} + /* the action file gets copied in in place of this dollarsign */ +#line 543 "/usr/share/bison.simple" + + yyvsp -= yylen; + yyssp -= yylen; +#ifdef YYLSP_NEEDED + yylsp -= yylen; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + + *++yyvsp = yyval; + +#ifdef YYLSP_NEEDED + yylsp++; + if (yylen == 0) + { + yylsp->first_line = yylloc.first_line; + yylsp->first_column = yylloc.first_column; + yylsp->last_line = (yylsp-1)->last_line; + yylsp->last_column = (yylsp-1)->last_column; + yylsp->text = 0; + } + else + { + yylsp->last_line = (yylsp+yylen-1)->last_line; + yylsp->last_column = (yylsp+yylen-1)->last_column; + } +#endif + + /* 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; + /* Start X at -yyn if nec to avoid negative indexes in yycheck. */ + for (x = (yyn < 0 ? -yyn : 0); + x < (sizeof(yytname) / sizeof(char *)); x++) + if (yycheck[x + yyn] == x) + size += strlen(yytname[x]) + 15, count++; + msg = (char *) malloc(size + 15); + if (msg != 0) + { + strcpy(msg, "parse error"); + + if (count < 5) + { + count = 0; + for (x = (yyn < 0 ? -yyn : 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 + yyerror ("parse error; also virtual memory exceeded"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror("parse error"); + } + + goto yyerrlab1; +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; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Discarding token %d (%s).\n", yychar, yytname[yychar1]); +#endif + + 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; +#ifdef YYLSP_NEEDED + yylsp--; +#endif + +#if YYDEBUG != 0 + if (yydebug) + { + short *ssp1 = yyss - 1; + fprintf (stderr, "Error: state stack now"); + while (ssp1 != yyssp) + fprintf (stderr, " %d", *++ssp1); + fprintf (stderr, "\n"); + } +#endif + +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; + +#if YYDEBUG != 0 + if (yydebug) + fprintf(stderr, "Shifting error token, "); +#endif + + *++yyvsp = yylval; +#ifdef YYLSP_NEEDED + *++yylsp = yylloc; +#endif + + yystate = yyn; + goto yynewstate; + + yyacceptlab: + /* YYACCEPT comes here. */ + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 0; + + yyabortlab: + /* YYABORT comes here. */ + if (yyfree_stacks) + { + free (yyss); + free (yyvs); +#ifdef YYLSP_NEEDED + free (yyls); +#endif + } + return 1; +} +#line 931 "goomsl_yacc.y" + + + +void yyerror(char *str) +{ /* {{{ */ + fprintf(stderr, "ERROR: Line %d, %s\n", currentGoomSL->num_lines, str); + currentGoomSL->compilationOK = 0; + exit(1); +} /* }}} */ + diff --git a/src/post/goom/goomsl_yacc.h b/src/post/goom/goomsl_yacc.h new file mode 100644 index 000000000..8f3ecf476 --- /dev/null +++ b/src/post/goom/goomsl_yacc.h @@ -0,0 +1,28 @@ +typedef union { + int intValue; + float floatValue; + char charValue; + char strValue[2048]; + NodeType *nPtr; + } YYSTYPE; +#define TYPE_INTEGER 257 +#define TYPE_FLOAT 258 +#define TYPE_VAR 259 +#define TYPE_PTR 260 +#define PTR_TK 261 +#define INT_TK 262 +#define FLOAT_TK 263 +#define DECLARE 264 +#define EXTERNAL 265 +#define WHILE 266 +#define DO 267 +#define NOT 268 +#define PLUS_EQ 269 +#define SUB_EQ 270 +#define DIV_EQ 271 +#define MUL_EQ 272 +#define SUP_EQ 273 +#define LOW_EQ 274 + + +extern YYSTYPE yylval; diff --git a/src/post/goom/plugin_info.c b/src/post/goom/plugin_info.c index c6d57dc5e..856dd8aa5 100644 --- a/src/post/goom/plugin_info.c +++ b/src/post/goom/plugin_info.c @@ -53,11 +53,11 @@ static void setOptimizedMethods(PluginInfo *p) { #ifdef CPU_POWERPC - if (cpuFlavour & CPU_OPTION_64_BITS) { + if ((cpuFlavour & CPU_OPTION_64_BITS) != 0) { p->methods.create_output_with_brightness = ppc_brightness_G5; p->methods.zoom_filter = ppc_zoom_generic; } - else if (cpuFlavour & CPU_OPTION_ALTIVEC) { + else if ((cpuFlavour & CPU_OPTION_ALTIVEC) != 0) { p->methods.create_output_with_brightness = ppc_brightness_G4; p->methods.zoom_filter = ppc_zoom_G4; } @@ -171,8 +171,8 @@ void plugin_info_init(PluginInfo *pp, int nbVisuals) { setOptimizedMethods(pp); - pp->scanner = goom_script_scanner_new(); - pp->main_scanner = goom_script_scanner_new(); + pp->scanner = gsl_new(); + pp->main_scanner = gsl_new(); pp->main_script_str = GOOM_MAIN_SCRIPT; for (i = 0; i < 0xffff; i++) { diff --git a/src/post/goom/ppc_drawings.s b/src/post/goom/ppc_drawings.s index 37d749381..845e5ea16 100644 --- a/src/post/goom/ppc_drawings.s +++ b/src/post/goom/ppc_drawings.s @@ -6,7 +6,7 @@ ; 30 May 2003 : File creation ; Section definition : We use a read only code section for the whole file -.text +.section __TEXT,__text,regular,pure_instructions ; -------------------------------------------------------------------------------------- @@ -150,7 +150,7 @@ _DRAW_LINE_PPC: ; ************************************************************************************** -.const_data +.const .align 4 vectorZERO: .long 0,0,0,0 @@ -160,7 +160,7 @@ vectorZERO: .long 0x1010100C, 0x1010100D, 0x1010100E, 0x1010100F -.text +.section __TEXT,__text,regular,pure_instructions .globl _ppc_brightness_G4 .align 3 @@ -176,8 +176,14 @@ _ppc_brightness_G4: lis r12,0xCFFC mtspr 256,r12 - lis r9,ha16(vectorZERO) - addi r9,r9,lo16(vectorZERO) + mflr r0 + bcl 20,31,"L00000000001$pb" +"L00000000001$pb": + mflr r10 + mtlr r0 + + addis r9,r10,ha16(vectorZERO-"L00000000001$pb") + addi r9,r9,lo16(vectorZERO-"L00000000001$pb") vxor v0,v0,v0 ;; V0 = NULL vector @@ -190,8 +196,8 @@ _ppc_brightness_G4: addi r9,r9,16 lvx v13,0,r9 - lis r9,ha16(vectortmpwork) - addi r9,r9,lo16(vectortmpwork) + addis r9,r10,ha16(vectortmpwork-"L00000000001$pb") + addi r9,r9,lo16(vectortmpwork-"L00000000001$pb") stw r6,0(r9) li r6,8 stw r6,4(r9) @@ -203,14 +209,14 @@ _ppc_brightness_G4: ;; elt counter li r9,0 lis r7,0x0F01 - b L6 + b L7 .align 4 L7: lvx v1,r9,r3 vperm v4,v1,v0,v10 ;********************* - add r10,r9,r3 + add r10,r9,r3 ;********************* vperm v5,v1,v0,v11 vperm v6,v1,v0,v12 @@ -218,7 +224,7 @@ L7: vmulouh v4,v4,v8 ;********************* - dst r10,r7,0 + dst r10,r7,3 ;********************* vmulouh v5,v5,v8 vmulouh v6,v6,v8 @@ -245,7 +251,6 @@ L7: .align 3 _ppc_brightness_G5: - ;; PowerPC Altivec G5 code srwi r5,r5,2 mtctr r5 @@ -255,8 +260,14 @@ _ppc_brightness_G5: lis r12,0xCFFC mtspr 256,r12 - lis r9,ha16(vectorZERO) - addi r9,r9,lo16(vectorZERO) + mflr r0 + bcl 20,31,"L00000000002$pb" +"L00000000002$pb": + mflr r10 + mtlr r0 + + addis r9,r10,ha16(vectorZERO-"L00000000002$pb") + addi r9,r9,lo16(vectorZERO-"L00000000002$pb") vxor v0,v0,v0 ;; V0 = NULL vector @@ -269,8 +280,8 @@ _ppc_brightness_G5: addi r9,r9,16 lvx v13,0,r9 - lis r9,ha16(vectortmpwork) - addi r9,r9,lo16(vectortmpwork) + addis r9,r10,ha16(vectortmpwork-"L00000000002$pb") + addi r9,r9,lo16(vectortmpwork-"L00000000002$pb") stw r6,0(r9) li r6,8 stw r6,4(r9) diff --git a/src/post/goom/xine_goom.c b/src/post/goom/xine_goom.c index ae39e005a..ec993cd51 100644 --- a/src/post/goom/xine_goom.c +++ b/src/post/goom/xine_goom.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_goom.c,v 1.54 2004/06/27 11:58:47 mroi Exp $ + * $Id: xine_goom.c,v 1.55 2004/11/21 15:10:40 mroi Exp $ * * GOOM post plugin. * @@ -27,6 +27,8 @@ */ #include <stdio.h> +#include <stdlib.h> +#include <time.h> #define LOG_MODULE "goom" #define LOG_VERBOSE @@ -271,6 +273,7 @@ static post_plugin_t *goom_open_plugin(post_class_t *class_gen, int inputs, this->width_back = this->width; this->height_back = this->height; + srand((unsigned int)time((time_t *)NULL)); this->goom = goom_init (this->width_back, this->height_back); this->ratio = (double)this->width_back/(double)this->height_back; |