From 2e73a5e69f0227f15c6049ef805a9b8c20166e2b Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Wed, 21 Jul 2004 14:38:29 +0000 Subject: new goom2k4-dev18 includes almost all of my warning fixes (the goom team is quite fast in applying my patches :) ) some files are still slightly patched from the release version, but I will get this sorted out so we will soon use a completely unmodified version of goom it compiles almost warningless now (the remaining warnings are introduced by lex/yacc and I plan to simply ignore them) the Makefile.am distclean-hack is also obsolete now, since the offending files have been renamed CVS patchset: 6828 CVS date: 2004/07/21 14:38:29 --- CREDITS | 2 +- ChangeLog | 2 +- src/post/goom/Makefile.am | 9 +- src/post/goom/config_param.c | 2 +- src/post/goom/convolve_fx.c | 19 +- src/post/goom/cpu_info.c | 1 + src/post/goom/filters.c | 21 +- src/post/goom/flying_stars_fx.c | 2 +- src/post/goom/gfontlib.c | 2 +- src/post/goom/gfontlib.h | 2 +- src/post/goom/goom_config_param.h | 8 +- src/post/goom/goom_filters.h | 6 +- src/post/goom/goom_fx.h | 7 +- src/post/goom/goom_graphic.h | 6 +- src/post/goom/goom_hash.c | 2 +- src/post/goom/goom_hash.h | 2 +- src/post/goom/goom_plugin_info.h | 4 +- src/post/goom/goom_script.h | 1 + src/post/goom/goom_script_lex.c | 2494 +++++++++++++++++++++++++++++++ src/post/goom/goom_script_scanner.c | 2463 ------------------------------ src/post/goom/goom_script_scanner.h | 22 +- src/post/goom/goom_script_scanner.tab.c | 1642 -------------------- src/post/goom/goom_script_scanner.tab.h | 69 - src/post/goom/goom_script_yacc.c | 1797 ++++++++++++++++++++++ src/post/goom/goom_script_yacc.h | 71 + src/post/goom/goom_tools.h | 4 +- src/post/goom/goom_visual_fx.h | 4 +- src/post/goom/ifs.c | 12 +- src/post/goom/ifs.h | 4 +- src/post/goom/lines.c | 6 +- src/post/goom/mmx.c | 7 +- src/post/goom/mmx.h | 18 +- src/post/goom/plugin_info.c | 16 +- src/post/goom/tentacle3d.c | 20 +- src/post/goom/tentacle3d.h | 2 +- src/post/goom/xmmx.c | 10 +- 36 files changed, 4488 insertions(+), 4271 deletions(-) create mode 100644 src/post/goom/goom_script_lex.c delete mode 100644 src/post/goom/goom_script_scanner.c delete mode 100644 src/post/goom/goom_script_scanner.tab.c delete mode 100644 src/post/goom/goom_script_scanner.tab.h create mode 100644 src/post/goom/goom_script_yacc.c create mode 100644 src/post/goom/goom_script_yacc.h diff --git a/CREDITS b/CREDITS index 1a3e58263..e7a617ed9 100644 --- a/CREDITS +++ b/CREDITS @@ -13,7 +13,7 @@ project version mediator ----------------------------------------------------------------------- ffmpeg build 4715 Mike Melanson -goom 2k4-dev15 +goom 2k4-dev18 gsm610 1.0.10 Mike Melanson liba52 0.7.4 libcdio 0.68 diff --git a/ChangeLog b/ChangeLog index fda62cb06..828cda1e3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ xine-lib (1-rc6) * remove XInitThreads() call from some video out plugins, because it might lead to undefined behaviour; calling XInitThreads() is entirely the frontend's job - * include goom2k4-dev15 + * include goom2k4-dev18 * make sure the streams are played till their very end * support for Annodex files * VobSub-in-Matroska support diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am index 9d0db451a..69891f709 100644 --- a/src/post/goom/Makefile.am +++ b/src/post/goom/Makefile.am @@ -22,17 +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_scanner.c \ - goom_script_scanner.tab.c goom_tools.c graphic.c ifs.c lines.c mathtools.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 \ plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c xineplug_post_goom_la_LIBADD = $(XINE_LIB) 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_scanner.tab.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 \ ppc_drawings.h ppc_zoom_ultimate.h sound_tester.h surf3d.h tentacle3d.h v3d.h - -# automake will delete goom_script_scanner.tab.c without the line below -distclean-compile: diff --git a/src/post/goom/config_param.c b/src/post/goom/config_param.c index a88adec39..2be4bafc9 100644 --- a/src/post/goom/config_param.c +++ b/src/post/goom/config_param.c @@ -11,7 +11,7 @@ #include "goom_config_param.h" #include -void empty_fct() { +static void empty_fct(PluginParam *dummy) { } PluginParam secure_param() { diff --git a/src/post/goom/convolve_fx.c b/src/post/goom/convolve_fx.c index 518875824..c73b541f9 100644 --- a/src/post/goom/convolve_fx.c +++ b/src/post/goom/convolve_fx.c @@ -8,10 +8,19 @@ #include static const char DEF_SCRIPT[] = -"float goom = Sound.Goom_Detection;\n" -"float factor = Bright_Flash.Factor;\n" -"(0.8 < goom)? factor = factor + Sound.Goom_Power * 1.5;\n" -"Bright_Flash.Factor = factor * 0.96;\n"; +"-> config;\n" +"-> main;\n" +"\n" +"\n" +" float INCREASE_RATE = 150%;\n" +" float DECAY_RATE = 96%;\n" +"\n" +"
\n" +" (Sound.Goom_Detection > 0.8) ?\n" +" Bright_Flash.Factor = Bright_Flash.Factor + Sound.Goom_Power * INCREASE_RATE;\n" +"\n" +" Bright_Flash.Factor = Bright_Flash.Factor * DECAY_RATE;\n" +"\n"; #define MAX 2.0f @@ -123,7 +132,7 @@ static void convolve_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo info->methods.create_output_with_brightness(src,dest,info->screen.size,iff); } -VisualFX convolve_create() { +VisualFX convolve_create(void) { VisualFX vfx = { init: convolve_init, free: convolve_free, diff --git a/src/post/goom/cpu_info.c b/src/post/goom/cpu_info.c index d392ee3d3..2ebca754b 100644 --- a/src/post/goom/cpu_info.c +++ b/src/post/goom/cpu_info.c @@ -8,6 +8,7 @@ */ #include "cpu_info.h" +#include "mmx.h" static unsigned int CPU_FLAVOUR = 0; diff --git a/src/post/goom/filters.c b/src/post/goom/filters.c index d4633ed2b..92fb16bc6 100644 --- a/src/post/goom/filters.c +++ b/src/post/goom/filters.c @@ -24,11 +24,12 @@ #include "goom_graphic.h" #include "goom_tools.h" #include "goom_plugin_info.h" +#include "goom_fx.h" #include "v3d.h" /* TODO : MOVE THIS AWAY !!! */ /* jeko: j'ai essayer de le virer, mais si on veut les laisser inline c'est un peu lourdo... */ -inline void setPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Color c) +static inline void setPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Color c) { Pixel i; @@ -38,14 +39,14 @@ inline void setPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Co *(buffer + (x + y * goomInfo->screen.width)) = i; } -inline void setPixelRGB_ (Pixel *buffer, Uint x, Color c) +static inline void setPixelRGB_ (Pixel *buffer, Uint x, Color c) { buffer[x].channels.r = c.r; buffer[x].channels.g = c.v; buffer[x].channels.b = c.b; } -inline void getPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Color * c) +static inline void getPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Color * c) { Pixel i = *(buffer + (x + y * goomInfo->screen.width)); c->b = i.channels.b; @@ -53,7 +54,7 @@ inline void getPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Co c->r = i.channels.r; } -inline void getPixelRGB_ (Pixel *buffer, Uint x, Color * c) +static inline void getPixelRGB_ (Pixel *buffer, Uint x, Color * c) { Pixel i = *(buffer + x); c->b = i.channels.b; @@ -137,7 +138,7 @@ typedef struct _ZOOM_FILTER_FX_WRAPPER_DATA { -inline v2g zoomVector(ZoomFilterFXWrapperData *data, float X, float Y) +static inline v2g zoomVector(ZoomFilterFXWrapperData *data, float X, float Y) { v2g vecteur; float vx, vy; @@ -234,7 +235,7 @@ inline v2g zoomVector(ZoomFilterFXWrapperData *data, float X, float Y) * Translation (-data->middleX, -data->middleY) * Homothetie (Center : 0,0 Coeff : 2/data->prevX) */ -void makeZoomBufferStripe(ZoomFilterFXWrapperData * data, int INTERLACE_INCR) +static void makeZoomBufferStripe(ZoomFilterFXWrapperData * data, int INTERLACE_INCR) { // Position of the pixel to compute in pixmap coordinates Uint x, y; @@ -684,7 +685,7 @@ static void generatePrecalCoef (int precalCoef[16][16]) /* VisualFX Wrapper */ -void zoomFilterVisualFXWrapper_init (struct _VISUAL_FX *_this) +static void zoomFilterVisualFXWrapper_init (struct _VISUAL_FX *_this) { ZoomFilterFXWrapperData *data = (ZoomFilterFXWrapperData*)malloc(sizeof(ZoomFilterFXWrapperData)); @@ -729,16 +730,16 @@ void zoomFilterVisualFXWrapper_init (struct _VISUAL_FX *_this) generatePrecalCoef(data->precalCoef); } -void zoomFilterVisualFXWrapper_free (struct _VISUAL_FX *_this) +static void zoomFilterVisualFXWrapper_free (struct _VISUAL_FX *_this) { free(_this->fx_data); } -void zoomFilterVisualFXWrapper_apply (struct _VISUAL_FX *_this, Pixel *src, Pixel *dest, PluginInfo *info) +static void zoomFilterVisualFXWrapper_apply (struct _VISUAL_FX *_this, Pixel *src, Pixel *dest, PluginInfo *info) { } -VisualFX zoomFilterVisualFXWrapper_create() +VisualFX zoomFilterVisualFXWrapper_create(void) { VisualFX fx; fx.init = zoomFilterVisualFXWrapper_init; diff --git a/src/post/goom/flying_stars_fx.c b/src/post/goom/flying_stars_fx.c index 72231e9c8..ff1d5b9b6 100644 --- a/src/post/goom/flying_stars_fx.c +++ b/src/post/goom/flying_stars_fx.c @@ -269,7 +269,7 @@ static void fs_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *info) } } -VisualFX flying_star_create() { +VisualFX flying_star_create(void) { VisualFX vfx = { init: fs_init, free: fs_free, diff --git a/src/post/goom/gfontlib.c b/src/post/goom/gfontlib.c index 960ca43b9..710c23520 100755 --- a/src/post/goom/gfontlib.c +++ b/src/post/goom/gfontlib.c @@ -11,7 +11,7 @@ static Pixel ***small_font_chars; static int *small_font_width; static int *small_font_height; -void gfont_load () { +void gfont_load (void) { unsigned char *gfont; unsigned int i = 0, j = 0; unsigned int nba = 0; diff --git a/src/post/goom/gfontlib.h b/src/post/goom/gfontlib.h index f5b82917b..0520b7da9 100755 --- a/src/post/goom/gfontlib.h +++ b/src/post/goom/gfontlib.h @@ -3,7 +3,7 @@ #include "goom_graphic.h" -void gfont_load (); +void gfont_load (void); void goom_draw_text (Pixel * buf,int resolx,int resoly, int x, int y, const char *str, float chspace, int center); diff --git a/src/post/goom/goom_config_param.h b/src/post/goom/goom_config_param.h index bd8753e7e..cfa16917b 100644 --- a/src/post/goom/goom_config_param.h +++ b/src/post/goom/goom_config_param.h @@ -1,5 +1,5 @@ -#ifndef _GOOM_CONFIG_PARAM_H -#define _GOOM_CONFIG_PARAM_H +#ifndef _CONFIG_PARAM_H +#define _CONFIG_PARAM_H #include @@ -79,9 +79,7 @@ typedef struct _PARAM { #define IMAX(p) ((p).param.ival.max) #define ISTEP(p) ((p).param.ival.step) -void empty_fct(); - -PluginParam secure_param(); +PluginParam secure_param(void); PluginParam secure_f_param(char *name); PluginParam secure_i_param(char *name); diff --git a/src/post/goom/goom_filters.h b/src/post/goom/goom_filters.h index bf64c166a..f015499a8 100644 --- a/src/post/goom/goom_filters.h +++ b/src/post/goom/goom_filters.h @@ -1,12 +1,12 @@ -#ifndef _GOOM_FILTERS_H -#define _GOOM_FILTERS_H +#ifndef FILTERS_H +#define FILTERS_H #include "goom_config.h" #include "goom_typedefs.h" #include "goom_visual_fx.h" #include "goom_graphic.h" -VisualFX zoomFilterVisualFXWrapper_create(); +VisualFX zoomFilterVisualFXWrapper_create(void); struct _ZOOM_FILTER_DATA { diff --git a/src/post/goom/goom_fx.h b/src/post/goom/goom_fx.h index 0a0e1287b..fec5e2b40 100644 --- a/src/post/goom/goom_fx.h +++ b/src/post/goom/goom_fx.h @@ -4,7 +4,10 @@ #include "goom_visual_fx.h" #include "goom_plugin_info.h" -VisualFX convolve_create (); -VisualFX flying_star_create (); +VisualFX convolve_create (void); +VisualFX flying_star_create (void); + +void zoom_filter_c(int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); +void create_output_with_brightness(Pixel *src, Pixel *dest, int screensize, int iff); #endif diff --git a/src/post/goom/goom_graphic.h b/src/post/goom/goom_graphic.h index 8f0a12c49..1d78f1d4e 100644 --- a/src/post/goom/goom_graphic.h +++ b/src/post/goom/goom_graphic.h @@ -1,5 +1,5 @@ -#ifndef _GOOM_GRAPHIC_H -#define _GOOM_GRAPHIC_H +#ifndef GRAPHIC_H +#define GRAPHIC_H typedef unsigned int Uint; @@ -63,4 +63,4 @@ inline void getPixelRGB (Pixel * buffer, Uint x, Uint y, Color * c); */ -#endif /* _GOOM_GRAPHIC_H */ +#endif /* GRAPHIC_H */ diff --git a/src/post/goom/goom_hash.c b/src/post/goom/goom_hash.c index 09052ed90..f21a6d6c3 100644 --- a/src/post/goom/goom_hash.c +++ b/src/post/goom/goom_hash.c @@ -57,7 +57,7 @@ static HashValue *entry_get(GoomHashEntry *entry, const char *key) { return &(entry->value); } -GoomHash *goom_hash_new() { +GoomHash *goom_hash_new(void) { GoomHash *_this = (GoomHash*)malloc(sizeof(GoomHash)); _this->root = NULL; return _this; diff --git a/src/post/goom/goom_hash.h b/src/post/goom/goom_hash.h index c869e67e4..c8eae37ed 100644 --- a/src/post/goom/goom_hash.h +++ b/src/post/goom/goom_hash.h @@ -21,7 +21,7 @@ struct GOOM_HASH { GoomHashEntry *root; }; -GoomHash *goom_hash_new(); +GoomHash *goom_hash_new(void); void goom_hash_free(GoomHash *gh); void goom_hash_put(GoomHash *gh, const char *key, HashValue value); diff --git a/src/post/goom/goom_plugin_info.h b/src/post/goom/goom_plugin_info.h index c28df65dd..1ec562e39 100644 --- a/src/post/goom/goom_plugin_info.h +++ b/src/post/goom/goom_plugin_info.h @@ -1,5 +1,5 @@ -#ifndef _GOOM_PLUGIN_INFO_H -#define _GOOM_PLUGIN_INFO_H +#ifndef _PLUGIN_INFO_H +#define _PLUGIN_INFO_H #include "goom_typedefs.h" diff --git a/src/post/goom/goom_script.h b/src/post/goom/goom_script.h index 8b5bfb648..ca1cb5665 100644 --- a/src/post/goom/goom_script.h +++ b/src/post/goom/goom_script.h @@ -12,5 +12,6 @@ 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 new file mode 100644 index 000000000..f50882d29 --- /dev/null +++ b/src/post/goom/goom_script_lex.c @@ -0,0 +1,2494 @@ + +#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 +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +#include +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 +#include +#include +#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 +#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.c b/src/post/goom/goom_script_scanner.c deleted file mode 100644 index 5aec843b4..000000000 --- a/src/post/goom/goom_script_scanner.c +++ /dev/null @@ -1,2463 +0,0 @@ -#line 2 "goom_script_scanner.c" - -#line 4 "goom_script_scanner.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 -#include -#include -#include - -/* end standard C headers. */ - -/* flex integer type definitions */ - -#ifndef FLEXINT_H -#define FLEXINT_H - -/* C99 systems have . Non-C99 systems may or may not. */ - -#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L -#include -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 14 -#define YY_END_OF_BUFFER 15 -/* 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[35] = - { 0, - 0, 0, 0, 0, 15, 13, 12, 1, 13, 13, - 9, 8, 8, 8, 3, 3, 12, 9, 4, 11, - 10, 0, 8, 8, 8, 2, 10, 7, 8, 6, - 7, 8, 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, 1, 1, 1, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, - 1, 1, 1, 1, 10, 1, 11, 10, 10, 10, - - 10, 12, 10, 10, 13, 10, 10, 14, 10, 15, - 16, 10, 10, 10, 10, 17, 10, 10, 10, 10, - 10, 10, 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[18] = - { 0, - 1, 1, 1, 1, 1, 1, 2, 1, 3, 4, - 4, 4, 4, 4, 4, 4, 4 - } ; - -static yyconst flex_int16_t yy_base[39] = - { 0, - 0, 0, 15, 16, 57, 58, 54, 58, 46, 49, - 18, 46, 16, 17, 58, 44, 49, 0, 58, 58, - 41, 0, 42, 19, 21, 58, 39, 0, 22, 30, - 0, 19, 17, 58, 38, 41, 27, 43 - } ; - -static yyconst flex_int16_t yy_def[39] = - { 0, - 34, 1, 35, 35, 34, 34, 34, 34, 34, 34, - 34, 36, 36, 36, 34, 34, 34, 11, 34, 34, - 34, 37, 36, 36, 36, 34, 34, 38, 36, 36, - 38, 25, 25, 0, 34, 34, 34, 34 - } ; - -static yyconst flex_int16_t yy_nxt[76] = - { 0, - 6, 7, 8, 6, 6, 9, 6, 10, 11, 12, - 12, 13, 14, 12, 12, 12, 12, 8, 8, 16, - 16, 20, 22, 22, 21, 22, 18, 22, 22, 24, - 28, 25, 32, 23, 29, 33, 22, 30, 15, 15, - 15, 15, 23, 23, 23, 31, 31, 27, 22, 27, - 17, 26, 22, 19, 18, 17, 34, 5, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34 - } ; - -static yyconst flex_int16_t yy_chk[76] = - { 0, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 3, 4, 3, - 4, 11, 13, 14, 11, 24, 11, 25, 29, 13, - 37, 14, 29, 33, 24, 32, 30, 25, 35, 35, - 35, 35, 36, 36, 36, 38, 38, 27, 23, 21, - 17, 16, 12, 10, 9, 7, 5, 34, 34, 34, - 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, - 34, 34, 34, 34, 34 - } ; - -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_scanner.lex" -#line 2 "goom_script_scanner.lex" - -#include -#include -#include -#include "goom_script_scanner.h" -#include "goom_script_scanner.tab.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 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" - - PluginParam *goom_script_get_param(PluginInfo *pluginInfo, const char *name); - - /* ------------- 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(); - 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() { - - 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; - - /* 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); - - default: - return VALIDATE_TODO; - } - return VALIDATE_ERROR; - } - - /** EXECUTE **/ - - void iflow_execute(InstructionFlow *_this, ScriptExecEnv *exec_env) { - int ip = 0; - 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_VAR: - instr->data.v_v.var_dest->f *= instr->data.v_v.var_src->f; - ++ip; break; - - case INSTR_MULF_VAR_FLOAT: - instr->data.v_f.var->f *= instr->data.v_f.value; - ++ip; break; - - /* EQUALS.I * / - case INSTR_EQUALSI_VAR_VAR: - return (instr->data.v_v.var_src->i == instr->data.v_v.var_dest->i)?1:2; - - case INSTR_EQUALSI_VAR_INTEGER: - return (instr->data.v_i.var->i == instr->data.v_i.value)?1:2; - - / * EQUALS.F * / - case INSTR_EQUALSF_VAR_VAR: - return (instr->data.v_v.var_src->f == instr->data.v_v.var_dest->f)?1:2; - case INSTR_EQUALSF_VAR_FLOAT: - return (instr->data.v_f.var->f == instr->data.v_f.value)?1:2; - - / * LOWER.I * / - case INSTR_LOWERI_VAR_VAR: - return (instr->data.v_v.var_src->i > instr->data.v_v.var_dest->i)?1:2; - case INSTR_LOWERI_VAR_INTEGER: - return (instr->data.v_i.var->i < instr->data.v_i.value)?1:2; - - / * LOWER.F * / - case INSTR_LOWERF_VAR_VAR: - return (instr->data.v_v.var_src->f > instr->data.v_v.var_dest->f)?1:2; - case INSTR_LOWERF_VAR_FLOAT: - return (instr->data.v_f.var->f < instr->data.v_f.value)?1:2; - */ - - default: - printf("NOT IMPLEMENTED : %d\n", instr->id); - ++ip; - } - } - } - - GoomScriptScanner *currentScanner; - -#line 1090 "goom_script_scanner.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 -#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 631 "goom_script_scanner.lex" - - -#line 1245 "goom_script_scanner.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 >= 35 ) - 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] != 58 ); - -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 633 "goom_script_scanner.lex" -{ ++currentScanner->num_lines; } - YY_BREAK -case 2: -YY_RULE_SETUP -#line 635 "goom_script_scanner.lex" -{ BEGIN INITIAL; } - YY_BREAK -case 3: -YY_RULE_SETUP -#line 636 "goom_script_scanner.lex" -{ /* eat up comment */ } - YY_BREAK -case 4: -YY_RULE_SETUP -#line 638 "goom_script_scanner.lex" -{ BEGIN COMMENT; } - YY_BREAK -/* - set"."i { currentScanner->instr = instr_init(currentScanner, "set.i", INSTR_SETI, 2); } - set"."f { currentScanner->instr = instr_init(currentScanner, "set.f", INSTR_SETF, 2); } - add"."i { currentScanner->instr = instr_init(currentScanner, "add.i", INSTR_ADDI, 2); } - add"."f { currentScanner->instr = instr_init(currentScanner, "add.f", INSTR_ADDF, 2); } - mul"."i { currentScanner->instr = instr_init(currentScanner, "mul.i", INSTR_MULI, 2); } - mul"."f { currentScanner->instr = instr_init(currentScanner, "mul.f", INSTR_MULF, 2); } - bool { currentScanner->instr = instr_init(currentScanner, "bool", INSTR_INT, 1); } - jump { currentScanner->instr = instr_init(currentScanner, "jump", INSTR_JUMP, 1); } - label { currentScanner->instr = instr_init(currentScanner, "label", INSTR_LABEL, 1); } - equals"."i { currentScanner->instr = instr_init(currentScanner, "equals.i", INSTR_EQUALSI, 2); } - equals"."f { currentScanner->instr = instr_init(currentScanner, "equals.f", INSTR_EQUALSF, 2); } - lower"."i { currentScanner->instr = instr_init(currentScanner, "lower.i", INSTR_LOWERI, 2); } - lower"."f { currentScanner->instr = instr_init(currentScanner, "lower.f", INSTR_LOWERF, 2); } - ":"{ID}":" { instr_add_param(currentScanner->instr, yytext, TYPE_LABEL); } - {ID}"."{ID} { instr_add_param(currentScanner->instr, yytext, TYPE_PARAM); } - */ -case 5: -YY_RULE_SETUP -#line 657 "goom_script_scanner.lex" -{ return FLOAT_TK; } - YY_BREAK -case 6: -YY_RULE_SETUP -#line 658 "goom_script_scanner.lex" -{ return INT_TK; } - YY_BREAK -case 7: -YY_RULE_SETUP -#line 659 "goom_script_scanner.lex" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_PARAM; } - YY_BREAK -case 8: -YY_RULE_SETUP -#line 660 "goom_script_scanner.lex" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_VAR; } - YY_BREAK -case 9: -YY_RULE_SETUP -#line 661 "goom_script_scanner.lex" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_INTEGER; } - YY_BREAK -case 10: -YY_RULE_SETUP -#line 662 "goom_script_scanner.lex" -{ strncpy(yylval.strValue, yytext, 2047); return TYPE_FLOAT; } - YY_BREAK -case 11: -YY_RULE_SETUP -#line 663 "goom_script_scanner.lex" -{ sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return TYPE_FLOAT; } - YY_BREAK -case 12: -YY_RULE_SETUP -#line 664 "goom_script_scanner.lex" -/* eat up whitespace */ - YY_BREAK -case 13: -YY_RULE_SETUP -#line 665 "goom_script_scanner.lex" -{ yylval.charValue = *yytext; return *yytext; } - YY_BREAK -case 14: -YY_RULE_SETUP -#line 667 "goom_script_scanner.lex" -ECHO; - YY_BREAK -#line 1416 "goom_script_scanner.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 >= 35 ) - 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 >= 35 ) - 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 == 34); - - 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 667 "goom_script_scanner.lex" - - - -static void reset_scanner(GoomScriptScanner *gss) { - - gss->num_lines = 0; - gss->instr = NULL; - iflow_clean(gss->iflow); - gss->current_flow = gss->iflow; - 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 - currentScanner = _currentScanner; - reset_scanner(currentScanner); - currentScanner->pluginInfo = pluginInfo; - - yy_scan_string(script); - yyparse(); - gsl_commit_compilation(); - - 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 index fb969ce36..40360dc24 100644 --- a/src/post/goom/goom_script_scanner.h +++ b/src/post/goom/goom_script_scanner.h @@ -7,7 +7,7 @@ void goom_script_scanner_compile(GoomScriptScanner *scanner, PluginInfo *pluginI void goom_script_scanner_execute(GoomScriptScanner *scanner); int goom_script_scanner_is_compiled(GoomScriptScanner *gss); -GoomScriptScanner *goom_script_scanner_new(); +GoomScriptScanner *goom_script_scanner_new(void); void goom_script_scanner_free(GoomScriptScanner *gss); @@ -20,7 +20,8 @@ void goom_script_scanner_free(GoomScriptScanner *gss); #define CONST_FLOAT_NODE 2 #define VAR_NODE 3 #define PARAM_NODE 4 -#define OPR_NODE 5 +#define READ_PARAM_NODE 5 +#define OPR_NODE 6 #define OPR_SET 1 #define OPR_DECLARE_INT 2 @@ -31,6 +32,11 @@ void goom_script_scanner_free(GoomScriptScanner *gss); #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;*/ @@ -64,10 +70,10 @@ typedef struct _NODE_TYPE{ ConstIntNodeType constInt; ConstFloatNodeType constFloat; OprNodeType opr; - } val; + } unode; } NodeType; -void gsl_commit_compilation(); +void gsl_commit_compilation(void); /* ------------- SCRIPT_EXEC_ENV ------------ */ @@ -190,8 +196,12 @@ struct _GoomScriptScanner { #define INSTR_ADDF 10008 #define INSTR_MULI 10009 #define INSTR_MULF 10010 -#define INSTR_ISEQUALI 10011 -#define INSTR_ISEQUALF 10012 +#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_scanner.tab.c b/src/post/goom/goom_script_scanner.tab.c deleted file mode 100644 index be633a9bc..000000000 --- a/src/post/goom/goom_script_scanner.tab.c +++ /dev/null @@ -1,1642 +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 - }; -#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 - - - - -/* Copy the first part of user declarations. */ -#line 6 "goom_script_scanner.y" - - #include - #include - #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_nop(const char *str); - static NodeType *new_op(const char *str, int type, int nbOp); - - static int allocateLabel(); - #define allocateTemp allocateLabel - - /* SETTER */ - static NodeType *new_set(NodeType *lvalue, NodeType *expression) { - NodeType *set = new_op("set", OPR_SET, 2); - set->val.opr.op[0] = lvalue; - set->val.opr.op[1] = expression; - return set; - } - static void commit_set(NodeType *set) { - precommit_node(set->val.opr.op[1]); -#ifdef VERBOSE - printf("set.f %s %s\n", set->val.opr.op[0]->str, set->val.opr.op[1]->str); -#endif - currentScanner->instr = instr_init(currentScanner, "set.f", INSTR_SETF, 2); - commit_node(set->val.opr.op[0]); - commit_node(set->val.opr.op[1]); - } - - /* FLOAT */ - static NodeType *new_float_decl(NodeType *name) { - NodeType *fld = new_op("float", OPR_DECLARE_FLOAT, 1); - fld->val.opr.op[0] = name; - return fld; - } - static void commit_float(NodeType *var) { -#ifdef VERBOSE - printf("float %s\n", var->val.opr.op[0]->str); -#endif - currentScanner->instr = instr_init(currentScanner, "float", INSTR_INT, 1); - commit_node(var->val.opr.op[0]); - } - - /* INT */ - static NodeType *new_int_decl(NodeType *name) { - NodeType *intd = new_op("int", OPR_DECLARE_INT, 1); - intd->val.opr.op[0] = name; - return intd; - } - static void commit_int(NodeType *var) { -#ifdef VERBOSE - printf("int %s\n", var->val.opr.op[0]->str); -#endif - currentScanner->instr = instr_init(currentScanner, "int", INSTR_INT, 1); - commit_node(var->val.opr.op[0]); - } - - /* 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->val.opr.op[0]); - precommit_node(expr->val.opr.op[1]); - - if (is_tmp_expr(expr->val.opr.op[0])) { - strcpy(stmp, expr->val.opr.op[0]->str); - toAdd = 1; - } - else if (is_tmp_expr(expr->val.opr.op[1])) { - strcpy(stmp,expr->val.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->val.opr.op[0])); - toAdd = 1; - } - - /* add op2 to tmp */ -#ifdef VERBOSE - printf("%s %s %s\n", type, stmp, expr->val.opr.op[toAdd]->str); -#endif - currentScanner->instr = instr_init(currentScanner, type, instr_id, 2); - commit_node(new_var(stmp)); - commit_node(expr->val.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->val.opr.op[0] = expr1; - add->val.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); - } - - /* 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); - } - - /* 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->val.opr.op[0] = expression; - node->val.opr.op[1] = instr; - return node; - } - static void commit_if(NodeType *node) { - - char slab[1024]; - precommit_node(node->val.opr.op[0]); - - /* jzero.i */ - sprintf(slab, "|eif%d|", allocateLabel()); -#ifdef VERBOSE - printf("jzero.i %s %s\n", node->val.opr.op[0]->str, slab); -#endif - currentScanner->instr = instr_init(currentScanner, "jzero.i", INSTR_JZERO, 2); - commit_node(node->val.opr.op[0]); - instr_add_param(currentScanner->instr, slab, TYPE_LABEL); - - /* [... instrs of the if ...] */ - commit_node(node->val.opr.op[1]); - /* label */ -#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->val.opr.op[0] = new_nop("start_of_block"); - blk->val.opr.op[1] = lastNode; - return blk; - } - static void commit_block(NodeType *node) { - commit_node(node->val.opr.op[0]->val.opr.next); - } - - /** **/ - - static NodeType *rootNode = 0; // TODO: reinitialiser a chaque compilation. - static NodeType *lastNode = 0; - static NodeType *gsl_append(NodeType *curNode) { - if (lastNode) - lastNode->val.opr.next = curNode; - lastNode = curNode; - while(lastNode->val.opr.next) lastNode = lastNode->val.opr.next; - if (rootNode == 0) - rootNode = curNode; - return curNode; - } - - static int lastLabel = 0; - int allocateLabel() { - return ++lastLabel; - } - void releaseLabel(int n) { - if (n == lastLabel) - lastLabel--; - } - - void gsl_commit_compilation() { - 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->val.opr.type) { - case OPR_ADD: precommit_add(node); break; - case OPR_MUL: precommit_mul(node); break; - case OPR_EQU: precommit_equ(node); break; - case OPR_LOW: precommit_low(node); break; - } - } - } - - void commit_node(NodeType *node) { - - if (node == 0) return; - - switch(node->type) { - case OPR_NODE: - switch(node->val.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; -#ifdef VERBOSE - case EMPTY_NODE: printf("NOP\n"); break; -#endif - } - - commit_node(node->val.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 263 "goom_script_scanner.y" -typedef union YYSTYPE { - int intValue; - float floatValue; - char charValue; - char strValue[2048]; - NodeType *nPtr; - } YYSTYPE; -/* Line 191 of yacc.c. */ -#line 357 "goom_script_scanner.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 369 "goom_script_scanner.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 /* 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 2 -/* YYLAST -- Last index in YYTABLE. */ -#define YYLAST 79 - -/* YYNTOKENS -- Number of terminals. */ -#define YYNTOKENS 19 -/* YYNNTS -- Number of nonterminals. */ -#define YYNNTS 7 -/* YYNRULES -- Number of rules. */ -#define YYNRULES 22 -/* YYNRULES -- Number of states. */ -#define YYNSTATES 44 - -/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ -#define YYUNDEFTOK 2 -#define YYMAXUTOK 263 - -#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, - 14, 15, 10, 9, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, - 8, 7, 2, 16, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 17, 2, 18, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 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, 11, 12 -}; - -#if YYDEBUG -/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in - YYRHS. */ -static const unsigned char yyprhs[] = -{ - 0, 0, 3, 6, 7, 12, 18, 22, 26, 32, - 37, 39, 40, 42, 44, 48, 52, 56, 60, 64, - 66, 68, 70 -}; - -/* YYRHS -- A `-1'-separated list of the rules' RHS. */ -static const yysigned_char yyrhs[] = -{ - 20, 0, -1, 20, 21, -1, -1, 24, 7, 23, - 13, -1, 12, 5, 7, 23, 13, -1, 12, 5, - 13, -1, 11, 5, 13, -1, 14, 23, 15, 16, - 21, -1, 17, 22, 20, 18, -1, 13, -1, -1, - 24, -1, 25, -1, 23, 10, 23, -1, 23, 9, - 23, -1, 23, 7, 23, -1, 23, 8, 23, -1, - 14, 23, 15, -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, 284, 284, 285, 288, 289, 291, 292, 293, 294, - 295, 298, 301, 302, 303, 304, 305, 306, 307, 310, - 311, 314, 315 -}; -#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", "';'", - "'('", "')'", "'?'", "'{'", "'}'", "$accept", "gsl", "instruction", - "start_block", "expression", "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, 61, 60, 43, - 42, 262, 263, 59, 40, 41, 63, 123, 125 -}; -# endif - -/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ -static const unsigned char yyr1[] = -{ - 0, 19, 20, 20, 21, 21, 21, 21, 21, 21, - 21, 22, 23, 23, 23, 23, 23, 23, 23, 24, - 24, 25, 25 -}; - -/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ -static const unsigned char yyr2[] = -{ - 0, 2, 2, 0, 4, 5, 3, 3, 5, 4, - 1, 0, 1, 1, 3, 3, 3, 3, 3, 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[] = -{ - 3, 0, 1, 19, 20, 0, 0, 10, 0, 11, - 2, 0, 0, 0, 22, 21, 0, 0, 12, 13, - 3, 0, 7, 0, 6, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 18, 16, 17, 15, 14, 0, - 9, 4, 5, 8 -}; - -/* YYDEFGOTO[NTERM-NUM]. */ -static const yysigned_char yydefgoto[] = -{ - -1, 1, 10, 20, 17, 18, 19 -}; - -/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing - STATE-NUM. */ -#define YYPACT_NINF -8 -static const yysigned_char yypact[] = -{ - -8, 1, -8, -8, -8, 0, 22, -8, 5, -8, - -8, -3, 8, 13, -8, -8, 5, 46, -8, -8, - -8, 5, -8, 5, -8, 50, 5, 5, 5, 5, - 15, 11, 59, 66, -8, -7, -7, 23, -8, 35, - -8, -8, -8, -8 -}; - -/* YYPGOTO[NTERM-NUM]. */ -static const yysigned_char yypgoto[] = -{ - -8, 14, -4, -8, 16, -1, -8 -}; - -/* 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[] = -{ - 11, 2, 28, 29, 21, 12, 3, 4, 14, 15, - 3, 4, 5, 6, 7, 8, 3, 4, 9, 16, - 23, 22, 5, 6, 7, 8, 24, 13, 9, 40, - 11, 39, 25, 29, 31, 43, 0, 32, 11, 33, - 3, 4, 35, 36, 37, 38, 5, 6, 7, 8, - 0, 0, 9, 26, 27, 28, 29, 26, 27, 28, - 29, 30, 0, 0, 0, 34, 26, 27, 28, 29, - 0, 0, 41, 26, 27, 28, 29, 0, 0, 42 -}; - -static const yysigned_char yycheck[] = -{ - 1, 0, 9, 10, 7, 5, 5, 6, 3, 4, - 5, 6, 11, 12, 13, 14, 5, 6, 17, 14, - 7, 13, 11, 12, 13, 14, 13, 5, 17, 18, - 31, 16, 16, 10, 20, 39, -1, 21, 39, 23, - 5, 6, 26, 27, 28, 29, 11, 12, 13, 14, - -1, -1, 17, 7, 8, 9, 10, 7, 8, 9, - 10, 15, -1, -1, -1, 15, 7, 8, 9, 10, - -1, -1, 13, 7, 8, 9, 10, -1, -1, 13 -}; - -/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing - symbol of state STATE-NUM. */ -static const unsigned char yystos[] = -{ - 0, 20, 0, 5, 6, 11, 12, 13, 14, 17, - 21, 24, 5, 5, 3, 4, 14, 23, 24, 25, - 22, 7, 13, 7, 13, 23, 7, 8, 9, 10, - 15, 20, 23, 23, 15, 23, 23, 23, 23, 16, - 18, 13, 13, 21 -}; - -#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 /* 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 /* 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 2: -#line 284 "goom_script_scanner.y" - { gsl_append(yyvsp[0].nPtr); } - break; - - case 4: -#line 288 "goom_script_scanner.y" - { yyval.nPtr = new_set(yyvsp[-3].nPtr,yyvsp[-1].nPtr); } - break; - - case 5: -#line 289 "goom_script_scanner.y" - { yyval.nPtr = new_float_decl(new_var(yyvsp[-3].strValue)); - yyval.nPtr->val.opr.next = new_set(new_var(yyvsp[-3].strValue), yyvsp[-1].nPtr); } - break; - - case 6: -#line 291 "goom_script_scanner.y" - { yyval.nPtr = new_float_decl(new_var(yyvsp[-1].strValue)); } - break; - - case 7: -#line 292 "goom_script_scanner.y" - { yyval.nPtr = new_int_decl(new_var(yyvsp[-1].strValue)); } - break; - - case 8: -#line 293 "goom_script_scanner.y" - { yyval.nPtr = new_if(yyvsp[-3].nPtr,yyvsp[0].nPtr); } - break; - - case 9: -#line 294 "goom_script_scanner.y" - { lastNode = yyvsp[-2].nPtr->val.opr.op[1]; yyval.nPtr=yyvsp[-2].nPtr; } - break; - - case 10: -#line 295 "goom_script_scanner.y" - { yyval.nPtr = new_nop("nop"); } - break; - - case 11: -#line 298 "goom_script_scanner.y" - { yyval.nPtr = new_block(lastNode); lastNode = yyval.nPtr->val.opr.op[0]; } - break; - - case 12: -#line 301 "goom_script_scanner.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 13: -#line 302 "goom_script_scanner.y" - { yyval.nPtr = yyvsp[0].nPtr; } - break; - - case 14: -#line 303 "goom_script_scanner.y" - { yyval.nPtr = new_mul(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 15: -#line 304 "goom_script_scanner.y" - { yyval.nPtr = new_add(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 16: -#line 305 "goom_script_scanner.y" - { yyval.nPtr = new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 17: -#line 306 "goom_script_scanner.y" - { yyval.nPtr = new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr); } - break; - - case 18: -#line 307 "goom_script_scanner.y" - { yyval.nPtr = yyvsp[-1].nPtr; } - break; - - case 19: -#line 310 "goom_script_scanner.y" - { yyval.nPtr = new_var(yyvsp[0].strValue); } - break; - - case 20: -#line 311 "goom_script_scanner.y" - { yyval.nPtr = new_param(yyvsp[0].strValue); } - break; - - case 21: -#line 314 "goom_script_scanner.y" - { yyval.nPtr = new_constFloat(yyvsp[0].strValue); } - break; - - case 22: -#line 315 "goom_script_scanner.y" - { yyval.nPtr = new_constInt(yyvsp[0].strValue); } - break; - - - } - -/* Line 999 of yacc.c. */ -#line 1376 "goom_script_scanner.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 318 "goom_script_scanner.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->val.constInt.val = atoi(str); - return node; - } - - NodeType *new_constFloat(const char *str) { - NodeType *node = nodeNew(str, CONST_FLOAT_NODE); - node->val.constFloat.val = atof(str); - return node; - } - - NodeType *new_var(const char *str) { - NodeType *node = nodeNew(str, VAR_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->val.opr.next = 0; - node->val.opr.type = type; - node->val.opr.nbOp = nbOp; - for (i=0;ival.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_scanner.tab.h b/src/post/goom/goom_script_scanner.tab.h deleted file mode 100644 index 6b9a2e04a..000000000 --- a/src/post/goom/goom_script_scanner.tab.h +++ /dev/null @@ -1,69 +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 - }; -#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 - - - - -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -#line 263 "goom_script_scanner.y" -typedef union YYSTYPE { - int intValue; - float floatValue; - char charValue; - char strValue[2048]; - NodeType *nPtr; - } YYSTYPE; -/* Line 1240 of yacc.c. */ -#line 61 "goom_script_scanner.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_script_yacc.c b/src/post/goom/goom_script_yacc.c new file mode 100644 index 000000000..50a1ec90f --- /dev/null +++ b/src/post/goom/goom_script_yacc.c @@ -0,0 +1,1797 @@ +/* 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 + #include + #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 */ + 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 */ +#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 /* 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 /* 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 /* 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;iunode.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 new file mode 100644 index 000000000..e35d93f82 --- /dev/null +++ b/src/post/goom/goom_script_yacc.h @@ -0,0 +1,71 @@ +/* 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.h b/src/post/goom/goom_tools.h index 9ee0e8082..31d044e4a 100644 --- a/src/post/goom/goom_tools.h +++ b/src/post/goom/goom_tools.h @@ -1,5 +1,5 @@ -#ifndef _GOOM_TOOLS_H -#define _GOOM_TOOLS_H +#ifndef _GOOMTOOLS_H +#define _GOOMTOOLS_H /** * Random number generator wrapper for faster random number. diff --git a/src/post/goom/goom_visual_fx.h b/src/post/goom/goom_visual_fx.h index 6cc798350..bb5c8f164 100644 --- a/src/post/goom/goom_visual_fx.h +++ b/src/post/goom/goom_visual_fx.h @@ -1,5 +1,5 @@ -#ifndef _GOOM_VISUAL_FX_H -#define _GOOM_VISUAL_FX_H +#ifndef _VISUAL_FX_H +#define _VISUAL_FX_H /** * File created on 2003-05-21 by Jeko. diff --git a/src/post/goom/ifs.c b/src/post/goom/ifs.c index a955b95d2..901bf7348 100644 --- a/src/post/goom/ifs.c +++ b/src/post/goom/ifs.c @@ -201,7 +201,7 @@ free_ifs (FRACTAL * Fractal) /***************************************************************/ -void +static void init_ifs (PluginInfo *goomInfo, IfsData *data) { int i; @@ -376,7 +376,7 @@ Draw_Fractal (IfsData *data) } -IFSPoint * +static IFSPoint * draw_ifs (PluginInfo *goomInfo, int *nbpt, IfsData *data) { int i; @@ -724,7 +724,7 @@ static void ifs_update (PluginInfo *goomInfo, Pixel * data, Pixel * back, int in /** VISUAL_FX WRAPPER FOR IFS */ -void ifs_vfx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInfo) { +static void ifs_vfx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInfo) { IfsData *data = (IfsData*)_this->fx_data; if (!data->initalized) { @@ -735,7 +735,7 @@ void ifs_vfx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInf /*TODO: trouver meilleur soluce pour increment (mettre le code de gestion de l'ifs dans ce fichier: ifs_vfx_apply) */ } -void ifs_vfx_init(VisualFX *_this) { +static void ifs_vfx_init(VisualFX *_this) { IfsData *data = (IfsData*)malloc(sizeof(IfsData)); data->Root = (FRACTAL*)NULL; @@ -743,13 +743,13 @@ void ifs_vfx_init(VisualFX *_this) { _this->fx_data = data; } -void ifs_vfx_free(VisualFX *_this) { +static void ifs_vfx_free(VisualFX *_this) { IfsData *data = (IfsData*)_this->fx_data; release_ifs(data); free(data); } -VisualFX ifs_visualfx_create() { +VisualFX ifs_visualfx_create(void) { VisualFX vfx; vfx.init = ifs_vfx_init; vfx.free = ifs_vfx_free; diff --git a/src/post/goom/ifs.h b/src/post/goom/ifs.h index 909838bd3..fab042668 100644 --- a/src/post/goom/ifs.h +++ b/src/post/goom/ifs.h @@ -10,7 +10,7 @@ #include "goom_plugin_info.h" #include "goom_visual_fx.h" -VisualFX ifs_visualfx_create(); +VisualFX ifs_visualfx_create(void); /* init ifs for a (width)x(height) output. * / void init_ifs (PluginInfo *goomInfo, int width, int height); @@ -20,7 +20,7 @@ void init_ifs (PluginInfo *goomInfo, int width, int height); void ifs_update (PluginInfo *goomInfo, Pixel * buffer, Pixel * back, int width, int height, int increment); / * free all ifs's data. * / -void release_ifs (); +void release_ifs (void); */ diff --git a/src/post/goom/lines.c b/src/post/goom/lines.c index a6a268337..877f1894c 100644 --- a/src/post/goom/lines.c +++ b/src/post/goom/lines.c @@ -44,7 +44,7 @@ static void lightencolor (guint32 *col, float power) -void +static void genline (int id, float param, GMUnitPointer * l, int rx, int ry) { int i; @@ -78,7 +78,7 @@ genline (int id, float param, GMUnitPointer * l, int rx, int ry) } } -guint32 getcouleur (int mode) +static guint32 getcouleur (int mode) { switch (mode) { case GML_RED: @@ -111,7 +111,7 @@ goom_lines_set_res (GMLine * gml, int rx, int ry) } -void +static void goom_lines_move (GMLine * l) { int i; diff --git a/src/post/goom/mmx.c b/src/post/goom/mmx.c index 3188d9bed..fdf06492a 100644 --- a/src/post/goom/mmx.c +++ b/src/post/goom/mmx.c @@ -1,3 +1,5 @@ +#ifdef HAVE_MMX + #define BUFFPOINTNB 16 #define BUFFPOINTMASK 0xffff #define BUFFINCR 0xff @@ -11,12 +13,12 @@ // faire : a / sqrtperte <=> a >> PERTEDEC #define PERTEDEC 4 -int mmx_supported () { +int mmx_supported (void) { return (mm_support()&0x1); } void zoom_filter_mmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, + Pixel *expix1, Pixel *expix2, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]) { @@ -270,3 +272,4 @@ end_of_line: /* __asm__ __volatile__ ("emms"); */ } +#endif diff --git a/src/post/goom/mmx.h b/src/post/goom/mmx.h index fe095de12..53c1cc5d9 100755 --- a/src/post/goom/mmx.h +++ b/src/post/goom/mmx.h @@ -27,6 +27,8 @@ #ifndef _MMX_H #define _MMX_H +#include "goom_graphic.h" + /* Warning: at this writing, the version of GAS packaged with most Linux distributions does not handle the parallel AND operation mnemonic correctly. If the @@ -58,7 +60,7 @@ typedef union { /* Function to test if multimedia instructions are supported... */ -inline extern int +static int mm_support(void) { /* Returns 1 if MMX instructions are supported, @@ -223,13 +225,25 @@ mm_support(void) /* Function to test if mmx instructions are supported... */ -inline extern int +static inline int mmx_ok(void) { /* Returns 1 if MMX instructions are supported, 0 otherwise */ return ( mm_support() & 0x1 ); } +int mmx_supported (void); +int xmmx_supported (void); + + +/* MMX optimized implementations */ +void draw_line_mmx (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny); +void draw_line_xmmx (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny); +void zoom_filter_mmx (int prevX, int prevY, Pixel *expix1, Pixel *expix2, + int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); +void zoom_filter_xmmx (int prevX, int prevY, Pixel *expix1, Pixel *expix2, + int *lbruS, int *lbruD, int buffratio, int precalCoef[16][16]); + /* Helper functions for the instruction macros that follow... (note that memory-to-register, m2r, instructions are nearly diff --git a/src/post/goom/plugin_info.c b/src/post/goom/plugin_info.c index 31627f96f..c6d57dc5e 100644 --- a/src/post/goom/plugin_info.c +++ b/src/post/goom/plugin_info.c @@ -1,4 +1,5 @@ #include "goom_plugin_info.h" +#include "goom_fx.h" #include "cpu_info.h" #include "default_scripts.h" #include "drawmethods.h" @@ -15,24 +16,11 @@ #ifdef CPU_X86 -/* TODO: PUT THIS IN SEPARATE HEADERS */ -extern int xmmx_supported (); -extern int mmx_supported (); -extern void draw_line_mmx (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny); -extern void zoom_filter_mmx (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); -extern void zoom_filter_xmmx (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); -/* END TODO */ +#include "mmx.h" #endif /* CPU_X86 */ - -/* prototypes of methods */ - -void zoom_filter_c (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); -void create_output_with_brightness(Pixel *src, Pixel *output_buffer, int screensize, int iff); - - static void setOptimizedMethods(PluginInfo *p) { unsigned int cpuFlavour = cpu_flavour(); diff --git a/src/post/goom/tentacle3d.c b/src/post/goom/tentacle3d.c index 600511327..b42e80525 100755 --- a/src/post/goom/tentacle3d.c +++ b/src/post/goom/tentacle3d.c @@ -38,16 +38,16 @@ typedef struct _TENTACLE_FX_DATA { int lock; } TentacleFXData; -void tentacle_new (TentacleFXData *data); -void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, +static void tentacle_new (TentacleFXData *data); +static void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, short[2][512], float, int drawit, TentacleFXData *data); -void tentacle_free (TentacleFXData *data); +static void tentacle_free (TentacleFXData *data); /* * VisualFX wrapper for the tentacles */ -void tentacle_fx_init(VisualFX *_this) { +static void tentacle_fx_init(VisualFX *_this) { TentacleFXData *data = (TentacleFXData*)malloc(sizeof(TentacleFXData)); @@ -77,18 +77,18 @@ void tentacle_fx_init(VisualFX *_this) { _this->fx_data = (void*)data; } -void tentacle_fx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInfo) { +static void tentacle_fx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInfo) { tentacle_update(goomInfo, dest, src, goomInfo->screen.width, goomInfo->screen.height, goomInfo->sound.samples, (float)goomInfo->sound.accelvar, goomInfo->curGState->drawTentacle, (TentacleFXData*)_this->fx_data); } -void tentacle_fx_free(VisualFX *_this) { +static void tentacle_fx_free(VisualFX *_this) { tentacle_free((TentacleFXData*)_this->fx_data); free(_this->fx_data); } -VisualFX tentacle_fx_create() { +VisualFX tentacle_fx_create(void) { VisualFX fx; fx.init = tentacle_fx_init; fx.apply = tentacle_fx_apply; @@ -98,12 +98,12 @@ VisualFX tentacle_fx_create() { /* ----- */ -void tentacle_free (TentacleFXData *data) { +static void tentacle_free (TentacleFXData *data) { /* TODO : un vrai FREE GRID!! */ free (data->vals); } -void tentacle_new (TentacleFXData *data) { +static void tentacle_new (TentacleFXData *data) { int tmp; v3d center = {0,-17.0,0}; @@ -221,7 +221,7 @@ static void pretty_move (PluginInfo *goomInfo, float cycle, float *dist, float * *rotangle = fx_data->rot = (tmp + 15.0f*fx_data->rot) / 16.0f; } -void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, +static void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, short data[2][512], float rapport, int drawit, TentacleFXData *fx_data) { int tmp; diff --git a/src/post/goom/tentacle3d.h b/src/post/goom/tentacle3d.h index adc5f7721..ad0858fad 100755 --- a/src/post/goom/tentacle3d.h +++ b/src/post/goom/tentacle3d.h @@ -3,6 +3,6 @@ #include "goom_visual_fx.h" -VisualFX tentacle_fx_create(); +VisualFX tentacle_fx_create(void); #endif diff --git a/src/post/goom/xmmx.c b/src/post/goom/xmmx.c index 87589e863..a5d57b395 100644 --- a/src/post/goom/xmmx.c +++ b/src/post/goom/xmmx.c @@ -1,6 +1,9 @@ /* a definir pour avoir exactement le meme resultat que la fonction C * (un chouillat plus lent) */ + +#ifdef HAVE_MMX + #define STRICT_COMPAT //#define HAVE_ATHLON @@ -21,12 +24,12 @@ /*#include "xmmx.h"*/ #include "goom_graphic.h" -int xmmx_supported () { +int xmmx_supported (void) { return (mm_support()&0x8)>>3; } void zoom_filter_xmmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, + Pixel *expix1, Pixel *expix2, int *lbruS, int *lbruD, int buffratio, int precalCoef[16][16]) { @@ -40,7 +43,7 @@ void zoom_filter_xmmx (int prevX, int prevY, volatile mmx_t ratiox; /* volatile mmx_t interpix; */ - expix1[0]=expix1[prevX-1]=expix1[prevX*prevY-1]=expix1[prevX*prevY-prevX]=0; + expix1[0].val=expix1[prevX-1].val=expix1[prevX*prevY-1].val=expix1[prevX*prevY-prevX].val=0; prevXY.ud[0] = (prevX-1)<