-/*!@file
- \brief IR Memory Implementation
- \details Intermediary memory management
- \author Jordan Lavatai
- \date Aug 2016
- ----------------------------------------------------------------------------*/
-#include <errno.h>
-#include <stdio.h>
-#include <stdint.h> //uint64_t
-#include <string.h> //memmove
-#include <stdlib.h> //malloc
-#include <apc/ir.h>
-
-
-
-/* functions needed from irmem.c */
-extern
-void
-ir_init(void);
-
-extern
-struct cdat*
-alloc_cdat(void);
-
-extern
-struct odat*
-alloc_odat(void);
-
-extern
-void
-alloc_vdat(void);
-
-extern
-struct link*
-alloc_link(void);
-
-extern
-struct ref*
-alloc_ref(void);
-
-extern
-struct cdat*
-curr_cdat(void);
-
-extern
-struct odat*
-curr_odat(void);
-
-extern
-struct vdat*
-curr_vdat(void);
-
-extern
-struct set*
-curr_set(void);
-
-extern
-struct ref*
-curr_ref(void);
-
-extern
-struct quad*
-curr_quad(void);
-
-extern
-struct model*
-curr_model(void);
-
-/* struct definitions needed from irmem.c */
-extern int num_cdats;
-extern struct cdat** cdat_stackp;
-extern struct odat* curr_set_odatp;
-extern uint64_t ss_ref_id;
-
-extern int num_vdats;
-/* Dynamically allocate memory for a class data structure,
- or cdat, after a class has been identified in a grammar.
- We also create a stack of class pointers so that
- we can access the cdat during processing of that
- cdats sets and elements, a requirement because the
- nature of recursive classes prevents us from accessing
- the cdat based on the previous index into cdat_buf,
- which is a list of all allocated cdats*/
-void
-push_cdat
-( char* name
-)
-{
- struct cdat* curr_cdatp;
-
- curr_cdatp = alloc_cdat();
-
- memmove(curr_cdatp->name, name, 32);
- curr_cdatp->idx = num_cdats;
-
- /* Set the cdat as a subclass of the previous cdat */
- (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes] = curr_cdatp;
- /* Push the cdat onto the cdat_stack */
- *++cdat_stackp = curr_cdatp;
-
-}
-
-void
-pop_cdat
-()
-{
- cdat_stackp--;
-}
-
-/* Called in the reduction of a set. While both odats (eles and sets)
- have identical label terminals, we are unable to give a single grammatical rule
- for both due to how we allocate odats in the odat buf. Due to the
- nature of bottom up parsing, the set label is recognized first, and then the
- sets elements are recognized. This means that after we have processed the sets elemenets,
- the curr_odat is going to be the last element and NOT the set that was first allocated.
- To get around this, we create a global variable set_odatp that will store the pointer
- to the odat when it is first allocated (in insert_set_label()) so that insert_set() can
- have access to it. Curr set points the sets representation in the cdat, curr_set_odatp
- points to the sets representation as an odat*/
-
-void
-insert_set_label
-( char* name,
- uint64_t ref_id
-)
-{
-
- struct set* curr_setp;
-
- curr_setp = curr_set();
- curr_set_odatp = alloc_odat();
-
- memmove(curr_set_odatp->name, name, 32);
- memmove(curr_setp->name, name, 32);
-
- if(ref_id != -1)
- { curr_set_odatp->ref_id = ref_id;
- curr_setp->ref_id = ref_id;
- }
- else
- { curr_setp->ref_id = ss_ref_id;
- curr_set_odatp->ref_id = ss_ref_id++;
- }
-
-}
-
-/* Inserting a olink instead of a set. Set is really just a placeholder
- for another set. Allocate the memory for the set so taht it can be populated*/
-void
-insert_set_olink
-( uint64_t ref_id
-)
-{
- struct set* curr_setp;
-
- curr_setp = curr_set();
-
- curr_setp->ref_id = ref_id;
-
-}
-
-void
-insert_set_vlink
-( uint64_t ref_id,
- char* anim_name
-)
-{
- struct cdat* curr_cdatp;
- struct odat* curr_odatp;
- struct link* curr_linkp;
-
-
- curr_cdatp = curr_cdat();
- curr_odatp = curr_odat();
- curr_linkp = alloc_link();
-
- /* Insert vlink into link_stack so that it gets processed at
- output time */
- curr_linkp->type = 2;
- /* Store the target odat information*/
- curr_linkp->link_t.vlink.ref_id = ref_id;
- memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
- /* Store the linking odat/cdat information */
- curr_linkp->classp = curr_cdatp;
- curr_linkp->odatp = curr_odatp;
- curr_linkp->set_idx = curr_cdatp->num_sets;
- curr_linkp->ele_idx = -1;
-
-}
-
-/* Svlinks dont have animation names */
-void
-insert_set_svlink
-( uint64_t ref_id
-)
-{
- struct cdat* curr_cdatp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_linkp = alloc_link();
-
- /* Insert svlink into link_stack so that it gets processed at
- output time */
- curr_linkp->type = 3;
- curr_linkp->classp = curr_cdatp;
- curr_linkp->set_idx = curr_cdatp->num_sets;
- curr_linkp->ele_idx = -1;
- curr_linkp->link_t.svlink.ref_id = ref_id;
-
-}
-
-/* At the point of reducing to a set, most of the
- sets odat information has already been populated
- during the reduction of its right hand side
- non terminals (hitbox, root, quad_list). */
-void
-insert_set
-()
-{ uint64_t ref_id;
- struct odat* curr_odatp;
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct ref* prev_refp;
- struct ref* curr_refp;
- struct vdat* curr_vdatp;
-
- curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space
- curr_cdatp = curr_cdat();
- curr_setp = curr_set();
- prev_refp = curr_ref();
- curr_refp = alloc_ref();
- curr_vdatp = curr_vdat();
-
- curr_vdatp->creator = curr_set_odatp;
-
- curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?
- memmove(curr_setp->name, curr_odatp->name, 32);
- curr_cdatp->num_sets++;
-
- curr_odatp->cdat_idx = curr_cdatp->idx;
- curr_odatp->refp = curr_refp;
-
- ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id)
-
- curr_refp->ref_id = ref_id;
- curr_refp->lastref = prev_refp;
- curr_refp->odatp = curr_odatp;
- prev_refp->nextref = curr_refp;
-
-
-
-}
-/* Created as a seperate function, instead of setting the ODATS vdat_id and
- calling inc_vdat() inside of insert_set(), to account for the set reduction
- where a vdat is not created (o/v/svlinks). */
-void
-insert_set_vdatid
-()
-{
- struct vdat* curr_vdatp;
-
- curr_vdatp = curr_vdat();
-
- curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks
- curr_set_odatp->vdatp = curr_vdatp;
- curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info
-}
-
-/* Populates the odat name and ref_id for odat, allocate the odat here for the rest of
- the functions to use via curr_odat(). */
-void
-insert_ele_label
-( char* name,
- uint64_t ref_id
-)
-{
- struct odat* curr_odatp;
-
- curr_odatp = alloc_odat();
-
- memmove(curr_odatp->name, name, 32);
-
- if(ref_id != -1)
- curr_odatp->ref_id = ref_id;
- else
- curr_odatp->ref_id = ss_ref_id++;
-
-}
-
-/* We don't make an odat here, at output time we will resolve
- the ref_id to the corresponding odat. */
-void
-insert_ele_olink
-( uint64_t ref_id
-)
-{
- /* Do nothing because we already know the ref_id that
- the odat needs for this element (in the quad_file) */
-}
-
-void
-insert_ele_vlink
-( uint64_t ref_id,
- char* anim_name
-)
-{
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_setp = curr_set();
- curr_linkp = alloc_link();
-
- /* Insert vlink into link_stack so that it gets processed at
- output time */
- curr_linkp->classp = curr_cdatp;
- curr_linkp->type = 2;
- curr_linkp->set_idx = curr_cdatp->num_sets;
- //curr_linkp->ele_idx = curr_setp->num_ele;
- curr_linkp->link_t.vlink.ref_id = ref_id;
- memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
-
-}
-
-void
-insert_ele_svlink
-( uint64_t ref_id
-)
-{
- struct cdat* curr_cdatp;
- struct set* curr_setp;
- struct link* curr_linkp;
-
- curr_cdatp = curr_cdat();
- curr_setp = curr_set();
- curr_linkp = alloc_link();
-
- curr_linkp->classp = curr_cdatp;
- curr_linkp->type = 3;
-
- //curr_linkp->ele_idx = curr_setp->num_ele;
- curr_linkp->link_t.svlink.ref_id = ref_id;
-
-
-}
-
-//Insert element into odat_buf and cdatpages
-void
-insert_ele()
-{
- uint64_t ref_id;
- struct cdat* curr_cdatp;
- struct odat* curr_odatp;
- struct vdat* curr_vdatp;
- struct set* curr_setp;
- struct ele* curr_elep;
- struct ref* curr_refp;
- struct ref* prev_refp;
-
-
- curr_odatp = curr_odat(); //malloced @ insert_ele_label
- curr_vdatp = curr_vdat();
- curr_setp = curr_set();
- prev_refp = curr_ref();
- curr_refp = alloc_ref();
-
- curr_vdatp->creator = curr_odatp;
-
- /* Populate odat for ele */
- curr_odatp->cdat_idx = curr_cdatp->idx;
- curr_odatp->refp = curr_refp;
-
- ref_id = curr_odatp->ref_id;
-
- curr_refp->ref_id = ref_id;
- curr_refp->lastref = prev_refp;
- curr_refp->odatp = curr_odatp;
- prev_refp->nextref = curr_refp;
-
-}
-
-void
-insert_ele_vdatid
-()
-{ struct odat* curr_odatp;
- curr_odatp = curr_odat();
- curr_odatp->vdat_id = num_vdats;
-}
-
-void
-insert_quad
-( void* quad_filep
-)
-{
- struct odat* curr_odatp;
-
- curr_odatp->quad_filep = quad_filep;
-}
-
-/* Inserting the hitbox into the set
- odat. Elements that don't have
- a hitbox will use the sets root. */
-void
-insert_hitbox
-( int hitbox
-)
-{ struct odat* curr_odatp;
-
- curr_odatp = curr_odat();
- curr_odatp->hitbox = hitbox;
-}
-
-/* Inserting the root into the set
- odat. Elements that don't have
- a root will use the sets root. */
-void
-insert_root
-( int x,
- int y,
- int z
-)
-{ struct odat* curr_odatp;
-
- curr_odatp = curr_odat();
- curr_odatp->root.x = x;
- curr_odatp->root.y = y;
- curr_odatp->root.z = z;
-}
-
-
-void
-insert_framesheet
-( char direction,
- char* name,
- uint64_t ref_id,
- int height ,
- int width,
- int num_frames
-)
-{ struct vdat* curr_vdatp;
- struct model* curr_modelp;
-
- curr_vdatp = curr_vdat();
- curr_modelp = curr_model();
-
- curr_modelp->spritesheet[(int)direction].height = height;
- curr_modelp->spritesheet[(int)direction].width = width;
- curr_modelp->spritesheet[(int)direction].num_frames = num_frames;
- curr_vdatp->num_models++;
-}
-
-void
-insert_frame_pointer
-( char direction,
- void* frame
-)
-{ struct model* curr_modelp;
-
- curr_modelp = curr_model();
-
- curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;
-}
-
+/*!@file\r
+ \brief IR Memory Implementation\r
+ \details Intermediary memory management\r
+ \author Jordan Lavatai\r
+ \date Aug 2016\r
+ ----------------------------------------------------------------------------*/\r
+#include <errno.h>\r
+#include <stdio.h>\r
+#include <stdint.h> //uint64_t\r
+#include <string.h> //memmove\r
+#include <stdlib.h> //malloc\r
+#include <apc/ir.h>\r
+\r
+\r
+\r
+/* functions needed from irmem.c */\r
+extern\r
+void\r
+ir_init(void);\r
+\r
+extern\r
+struct cdat*\r
+alloc_cdat(void);\r
+\r
+extern\r
+struct odat*\r
+alloc_odat(void);\r
+\r
+extern\r
+void\r
+alloc_vdat(void);\r
+\r
+extern\r
+struct link*\r
+alloc_link(void);\r
+\r
+extern\r
+struct ref*\r
+alloc_ref(void);\r
+\r
+extern\r
+struct cdat*\r
+curr_cdat(void);\r
+\r
+extern\r
+struct odat*\r
+curr_odat(void);\r
+\r
+extern\r
+struct vdat*\r
+curr_vdat(void);\r
+\r
+extern\r
+struct set*\r
+curr_set(void);\r
+\r
+extern\r
+struct ref*\r
+curr_ref(void);\r
+\r
+extern\r
+struct quad*\r
+curr_quad(void);\r
+\r
+extern\r
+struct model*\r
+curr_model(void);\r
+\r
+/* struct definitions needed from irmem.c */\r
+extern int num_cdats;\r
+extern struct cdat** cdat_stackp;\r
+extern struct odat* curr_set_odatp;\r
+extern uint64_t ss_ref_id;\r
+\r
+extern int num_vdats;\r
+/* Dynamically allocate memory for a class data structure,\r
+ or cdat, after a class has been identified in a grammar.\r
+ We also create a stack of class pointers so that\r
+ we can access the cdat during processing of that\r
+ cdats sets and elements, a requirement because the\r
+ nature of recursive classes prevents us from accessing\r
+ the cdat based on the previous index into cdat_buf,\r
+ which is a list of all allocated cdats*/\r
+void\r
+push_cdat\r
+( char* name\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+\r
+ curr_cdatp = alloc_cdat();\r
+\r
+ memmove(curr_cdatp->name, name, 32);\r
+ curr_cdatp->idx = num_cdats;\r
+\r
+ /* Set the cdat as a subclass of the previous cdat */\r
+ (*cdat_stackp)->class_list[(*cdat_stackp)->num_classes] = curr_cdatp;\r
+ /* Push the cdat onto the cdat_stack */\r
+ *++cdat_stackp = curr_cdatp;\r
+\r
+}\r
+\r
+void\r
+pop_cdat\r
+()\r
+{\r
+ cdat_stackp--;\r
+}\r
+\r
+/* Called in the reduction of a set. While both odats (eles and sets)\r
+ have identical label terminals, we are unable to give a single grammatical rule\r
+ for both due to how we allocate odats in the odat buf. Due to the\r
+ nature of bottom up parsing, the set label is recognized first, and then the\r
+ sets elements are recognized. This means that after we have processed the sets elemenets,\r
+ the curr_odat is going to be the last element and NOT the set that was first allocated.\r
+ To get around this, we create a global variable set_odatp that will store the pointer\r
+ to the odat when it is first allocated (in insert_set_label()) so that insert_set() can\r
+ have access to it. Curr set points the sets representation in the cdat, curr_set_odatp\r
+ points to the sets representation as an odat*/\r
+\r
+void\r
+insert_set_label\r
+( char* name,\r
+ uint64_t ref_id\r
+)\r
+{\r
+\r
+ struct set* curr_setp;\r
+\r
+ curr_setp = curr_set();\r
+ curr_set_odatp = alloc_odat();\r
+\r
+ memmove(curr_set_odatp->name, name, 32);\r
+ memmove(curr_setp->name, name, 32);\r
+\r
+ if(ref_id != -1)\r
+ { curr_set_odatp->ref_id = ref_id;\r
+ curr_setp->ref_id = ref_id;\r
+ }\r
+ else\r
+ { curr_setp->ref_id = ss_ref_id;\r
+ curr_set_odatp->ref_id = ss_ref_id++;\r
+ }\r
+\r
+}\r
+\r
+/* Inserting a olink instead of a set. Set is really just a placeholder\r
+ for another set. Allocate the memory for the set so taht it can be populated*/\r
+void\r
+insert_set_olink\r
+( uint64_t ref_id\r
+)\r
+{\r
+ struct set* curr_setp;\r
+\r
+ curr_setp = curr_set();\r
+\r
+ curr_setp->ref_id = ref_id;\r
+\r
+}\r
+\r
+void\r
+insert_set_vlink\r
+( uint64_t ref_id,\r
+ char* anim_name\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct odat* curr_odatp;\r
+ struct link* curr_linkp;\r
+\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_odatp = curr_odat();\r
+ curr_linkp = alloc_link();\r
+\r
+ /* Insert vlink into link_stack so that it gets processed at\r
+ output time */\r
+ curr_linkp->type = 2;\r
+ /* Store the target odat information*/\r
+ curr_linkp->link_t.vlink.ref_id = ref_id;\r
+ memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+ /* Store the linking odat/cdat information */\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->odatp = curr_odatp;\r
+ curr_linkp->set_idx = curr_cdatp->num_sets;\r
+ curr_linkp->ele_idx = -1;\r
+\r
+}\r
+\r
+/* Svlinks dont have animation names */\r
+void\r
+insert_set_svlink\r
+( uint64_t ref_id \r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct link* curr_linkp;\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_linkp = alloc_link();\r
+\r
+ /* Insert svlink into link_stack so that it gets processed at\r
+ output time */\r
+ curr_linkp->type = 3;\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->set_idx = curr_cdatp->num_sets;\r
+ curr_linkp->ele_idx = -1;\r
+ curr_linkp->link_t.svlink.ref_id = ref_id;\r
+\r
+}\r
+\r
+/* At the point of reducing to a set, most of the\r
+ sets odat information has already been populated\r
+ during the reduction of its right hand side\r
+ non terminals (hitbox, root, quad_list). */\r
+void\r
+insert_set\r
+()\r
+{ uint64_t ref_id;\r
+ struct odat* curr_odatp;\r
+ struct cdat* curr_cdatp;\r
+ struct set* curr_setp;\r
+ struct ref* prev_refp;\r
+ struct ref* curr_refp;\r
+ struct vdat* curr_vdatp;\r
+\r
+ curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space\r
+ curr_cdatp = curr_cdat();\r
+ curr_setp = curr_set();\r
+ prev_refp = curr_ref();\r
+ curr_refp = alloc_ref();\r
+ curr_vdatp = curr_vdat();\r
+\r
+ curr_vdatp->creator = curr_set_odatp;\r
+\r
+ curr_setp->cdat_idx = curr_cdatp->idx; //does a set need its class idx?\r
+ memmove(curr_setp->name, curr_odatp->name, 32);\r
+ curr_cdatp->num_sets++;\r
+\r
+ curr_odatp->cdat_idx = curr_cdatp->idx;\r
+ curr_odatp->refp = curr_refp;\r
+\r
+ ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id)\r
+\r
+ curr_refp->ref_id = ref_id;\r
+ curr_refp->lastref = prev_refp;\r
+ curr_refp->odatp = curr_odatp;\r
+ prev_refp->nextref = curr_refp;\r
+\r
+\r
+\r
+}\r
+/* Created as a seperate function, instead of setting the ODATS vdat_id and\r
+ calling inc_vdat() inside of insert_set(), to account for the set reduction\r
+ where a vdat is not created (o/v/svlinks). */\r
+void\r
+insert_set_vdatid\r
+()\r
+{\r
+ struct vdat* curr_vdatp;\r
+\r
+ curr_vdatp = curr_vdat();\r
+\r
+ curr_set_odatp->vdat_id = num_vdats; //no vdat_id for odats that have vlinks/svlinks\r
+ curr_set_odatp->vdatp = curr_vdatp;\r
+ curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info\r
+}\r
+\r
+/* Populates the odat name and ref_id for odat, allocate the odat here for the rest of\r
+ the functions to use via curr_odat(). */\r
+void\r
+insert_ele_label\r
+( char* name,\r
+ uint64_t ref_id\r
+)\r
+{\r
+ struct odat* curr_odatp;\r
+\r
+ curr_odatp = alloc_odat();\r
+\r
+ memmove(curr_odatp->name, name, 32);\r
+\r
+ if(ref_id != -1)\r
+ curr_odatp->ref_id = ref_id;\r
+ else\r
+ curr_odatp->ref_id = ss_ref_id++;\r
+\r
+}\r
+\r
+/* We don't make an odat here, at output time we will resolve\r
+ the ref_id to the corresponding odat. */\r
+void\r
+insert_ele_olink\r
+( uint64_t ref_id\r
+)\r
+{\r
+ /* Do nothing because we already know the ref_id that\r
+ the odat needs for this element (in the quad_file) */\r
+}\r
+\r
+void\r
+insert_ele_vlink\r
+( uint64_t ref_id,\r
+ char* anim_name\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct set* curr_setp;\r
+ struct link* curr_linkp;\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_setp = curr_set();\r
+ curr_linkp = alloc_link();\r
+\r
+ /* Insert vlink into link_stack so that it gets processed at\r
+ output time */\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->type = 2;\r
+ curr_linkp->set_idx = curr_cdatp->num_sets;\r
+ //curr_linkp->ele_idx = curr_setp->num_ele;\r
+ curr_linkp->link_t.vlink.ref_id = ref_id;\r
+ memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);\r
+\r
+}\r
+\r
+void\r
+insert_ele_svlink\r
+( uint64_t ref_id\r
+)\r
+{\r
+ struct cdat* curr_cdatp;\r
+ struct set* curr_setp;\r
+ struct link* curr_linkp;\r
+\r
+ curr_cdatp = curr_cdat();\r
+ curr_setp = curr_set();\r
+ curr_linkp = alloc_link();\r
+\r
+ curr_linkp->classp = curr_cdatp;\r
+ curr_linkp->type = 3;\r
+\r
+ //curr_linkp->ele_idx = curr_setp->num_ele;\r
+ curr_linkp->link_t.svlink.ref_id = ref_id;\r
+\r
+\r
+}\r
+\r
+//Insert element into odat_buf and cdatpages\r
+void\r
+insert_ele()\r
+{\r
+ uint64_t ref_id;\r
+ struct cdat* curr_cdatp;\r
+ struct odat* curr_odatp;\r
+ struct vdat* curr_vdatp;\r
+ struct set* curr_setp;\r
+ struct ele* curr_elep;\r
+ struct ref* curr_refp;\r
+ struct ref* prev_refp;\r
+\r
+\r
+ curr_odatp = curr_odat(); //malloced @ insert_ele_label\r
+ curr_vdatp = curr_vdat();\r
+ curr_setp = curr_set();\r
+ prev_refp = curr_ref();\r
+ curr_refp = alloc_ref();\r
+\r
+ curr_vdatp->creator = curr_odatp;\r
+\r
+ /* Populate odat for ele */\r
+ curr_odatp->cdat_idx = curr_cdatp->idx;\r
+ curr_odatp->refp = curr_refp;\r
+\r
+ ref_id = curr_odatp->ref_id;\r
+\r
+ curr_refp->ref_id = ref_id;\r
+ curr_refp->lastref = prev_refp;\r
+ curr_refp->odatp = curr_odatp;\r
+ prev_refp->nextref = curr_refp;\r
+\r
+}\r
+\r
+void\r
+insert_ele_vdatid\r
+()\r
+{ struct odat* curr_odatp;\r
+ curr_odatp = curr_odat();\r
+ curr_odatp->vdat_id = num_vdats;\r
+}\r
+\r
+void\r
+insert_quad\r
+( void* quad_filep\r
+)\r
+{\r
+ struct odat* curr_odatp;\r
+\r
+ curr_odatp->quad_filep = quad_filep;\r
+}\r
+\r
+/* Inserting the hitbox into the set\r
+ odat. Elements that don't have\r
+ a hitbox will use the sets root. */\r
+void\r
+insert_hitbox\r
+( int hitbox\r
+)\r
+{ struct odat* curr_odatp;\r
+\r
+ curr_odatp = curr_odat();\r
+ curr_odatp->hitbox = hitbox;\r
+}\r
+\r
+/* Inserting the root into the set\r
+ odat. Elements that don't have\r
+ a root will use the sets root. */\r
+void\r
+insert_root\r
+( int x,\r
+ int y,\r
+ int z\r
+)\r
+{ struct odat* curr_odatp;\r
+\r
+ curr_odatp = curr_odat();\r
+ curr_odatp->root.x = x;\r
+ curr_odatp->root.y = y;\r
+ curr_odatp->root.z = z;\r
+}\r
+\r
+\r
+void\r
+insert_framesheet\r
+( char direction,\r
+ char* name,\r
+ uint64_t ref_id,\r
+ int height ,\r
+ int width,\r
+ int num_frames\r
+)\r
+{ struct vdat* curr_vdatp;\r
+ struct model* curr_modelp;\r
+\r
+ curr_vdatp = curr_vdat();\r
+ curr_modelp = curr_model();\r
+\r
+ curr_modelp->spritesheet[(int)direction].height = height;\r
+ curr_modelp->spritesheet[(int)direction].width = width;\r
+ curr_modelp->spritesheet[(int)direction].num_frames = num_frames;\r
+ curr_vdatp->num_models++;\r
+}\r
+\r
+void\r
+insert_frame_pointer\r
+( char direction,\r
+ void* frame\r
+)\r
+{ struct model* curr_modelp;\r
+\r
+ curr_modelp = curr_model();\r
+\r
+ curr_modelp->spritesheet[(int)direction].frames[curr_modelp->spritesheet[(int)direction].num_frames++] = frame;\r
+}\r
+\r
-/*!@file
- \brief Intermediate Representation (IR) between Directory Structure and Engine Grammar
- \details The IR serves as a storage structure that is populated during the
- parsing of the input directory structure. After parsing is complete,
- the IR will be condensed (removed of excess allocated space) and then
- output as the Engine Grammar. In this file we describe the semantic actions
- that are called at each step, and the memory buffers that they populate.
- See parser.y for the description on how the input grammar is constructed,
- and where/when semantic actions are called.
- TODO: or just write it here.
- \author Jordan Lavatai
- \date Aug 2016
- ----------------------------------------------------------------------------*/
-
-
-#include <stdint.h>
-
-#define BUF_SIZE 256
-#define MAX_SETS 256
-#define MAX_ELES 256
-#define MAX_QUADS 256
-#define MAX_MODELS 256
-#define MAX_POSTS 256
-#define MAX_CLASS_DEPTH 256
-#define MAX_CLASSES 256
-#define MAX_FRAMES 256
-#define PTRS_IN_PAGE 1024
-#define MAX_CHUNKS 256
-#define PAGES_PER_CHUNK 16
-
-/* Sets: elements. The set is populated at parse time AFTER the
- elements are populated, due to the nature of bottom up parsing. */
-
-struct set {
- char name[32];
- uint64_t ref_id;
- int cdat_idx;
-};
-
-/* Cdats: A cdat is a class data structure. Cdats serve as the central */
-/* data types of the IR. For each cdat, sets and element */
-/* ref_ids must be dereferenced to determine the odat information. Cdats */
-/* contain pointers to their subclasses so that the relationship between */
-/* classes can be determined, but the subclasses are not represented inside */
-/* of the cdat itself but rather in subsequent cdats in cdat_buf. We */
-/* can determine the number of subclasses (the last index into cdat_buf */
-/* that represents a subclass of some arbitrary cdat) each cdat has by */
-/* incrementing num_classes during parse time. */
-/* TODO: Should classes point to their parent class? */
-
-struct cdat {
- char name[32];
- int idx;
- int num_classes;
- int num_sets;
- struct cdat* class_list[MAX_CLASSES];
- struct set set_list[MAX_SETS];
-};
-
-/* The cdat_stack is a stack pointers to cdat pointers, the top of which is
- the cdat that is currently being parsed. Whenever a new cdat is recognized
- by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer
- to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have
- access to the current cdat so that the elements and sets can populate themselves
- in the cdat accordingly. */
-
-
-/* Refs: Each set/ele has a reference to its object data (odat) through a ref_id.
- Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During
- the construction of the directory structure, users can choose a RGBA value for
- each object that any other object can refer to via links (see link). If a user
- does not choose an RGBA value, then the object is given one from the system space.
- We maintain a doubly linked list of refs in the ref_buf at parse time so that
- links can be resolved after the parsing of the directory structure is complete.
- For every 16th ref, we create a post so that we can reduce on the search time for
- a random access. */
-
-struct ref {
- int type;
- struct ref* nextref;
- struct ref* lastref;
- struct odat* odatp;
- uint64_t ref_id; //0xFFFFFF->digit
-};
-
-
-/* Links: At parse time, a set/ele can include a link in their
- grammar representation instead of the actual data and this signifies
- to the APC that that set/ele wishes to use the data of another
- set/ele, either its video data (vdat) or object data (odat). The link
- itself contains the type of link it is, the ref_id OR name, and
- which set/ele created the link. During parse time, links can be made
- to o/vdats that have yet to be parsed. In order to accomodate for this,
- we resolve all links AFTER parse time by iterating through the link_buf,
- finding the ref_id that was stored for some object (if the ref_id exists),
- and creating a relative pointer from the original object to the data that
- was linked */
-
-/* Svlinks stand for short vlink, which is a link to a vdat. svlinks
- differ from vlinks because they do not have a name */
-
-struct svlink {
- uint64_t ref_id;
-};
-
-/* A vlink is what it sounds like, a link to a vdat */
-struct vlink {
- uint64_t ref_id;
- char anim_name[32];
-};
-
-union link_t {
- struct vlink vlink;
- struct svlink svlink;
-};
-
-/* From: src odat ()To: dest odat (ref_id)*/
-struct link {
- int type; //1 = olink, 2 = vlink, 3 = svlink
- union link_t link_t;
- struct cdat* classp;
- struct odat* odatp;
- int set_idx;
- int ele_idx;
-};
-
-
-/* Odats: Odats consist of the object data necessary for
- each object. Odats are sometimes referred to as archetypes
- at compile-time, in order to distinguish the difference from
- a runtime object and a compile-time object.
- TODO: Need more info about objects at runtime, to described
- the reasoning behind odat structure at compile-time*/
-
-struct root {
- int x, y, z;
-};
-
-struct odat {
- char name[32];
- struct vdat* vdatp;
- int vdat_id; //
- int cdat_idx;
- int hitbox;
- uint64_t ref_id;
- struct root root;
- struct ref* refp; /* pointer to it's ref on ref_list */
- void* quad_filep;
-};
-
-struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer
- //refer to its odat via curr_odat, so save the set odat.
-
-/* A framesheet is a grouping of animation frames in
- a single direction (N,W,S,E) */
-struct framesheet {
- int width;
- int height;
- int num_frames;
- void* frames[MAX_FRAMES];
-};
-
-/* A model is a collection of framesheets for every
- direction (N,W,S,E,NW,NE,SW,SE)*/
-/* NAMED spritesheet */
-struct model {
- char name[32];
- struct framesheet spritesheet[8]; //one for each
-};
-
-/* Vdat: Vdats are the video data of each object. They can not be
- created as a stand alone object (because they consist solely
- of animation information and not the skeleton on which the
- animation manipulates). Vdats have a list of models for every
- animation that the vdats odat can do for that vdat*/
-struct vdat {
- struct odat* creator; //pointer to odat that made this vdat
- int num_models;
- struct model model_list[MAX_MODELS];
-};
-
-/* Called after the cdat open operator has been recognized in grammar. Allocates
- the space for a cdat on the cdat_buf, pushes that pointer onto
- the cdat_stack */
-void
-push_cdat(char*);
-
-/* Called after a cdat end operator has been recognized in grammar. Sets
- top stack cdat ** to null and decrements stack pointer */
-void
-pop_cdat(void);
-
-/* Called after an odat has been populated. Allocates memory for
- the next odat. */
-
-void
-insert_set_label(char*, uint64_t);
-
-/* Populate the sets representation in CURR_CDAT with a ref_id and insert a link
- into the link_buf that will resolve the ref_id to an actual odat after parse time. */
-void
-insert_set_olink(uint64_t);
-
-/* Put the vlink in the link_buf to be processed after parsetime */
-void
-insert_set_vlink(uint64_t, char*);
-
-/* Put svlink in the link_buf to be processed after parsetime */
-void
-insert_set_svlink(uint64_t);
-
-/* Called for every set reduction except for sets with olinks. Populates the
- set data structures in the CDAT and in the ODAT. Uses the name and ref_id
- from insert_set_label. Also inserts a ref into the ref_buf with the CURR_ODAT
- pointer so that we can also resolve the odat from its ref_id. */
-void
-insert_set(void);
-
-/* Insertion of eles is practically equivalent to how sets are inserted because both
- share the same data type (ODAT). Like sets, eles have links, labels
- and odats. Eles have the added notion of a parent set, and so must be inserted
- into said parent set, but this is the only place they truly differ from sets. */
-
-void
-insert_set_vdatid(void);
-
-void
-insert_ele_label(char*, uint64_t);
-
-/* Insert an ele olink into the CURR_ODAT */
-void
-insert_ele_olink(uint64_t);
-
-/* Insert a ele vlink into CURR_ODAT*/
-void
-insert_ele_vlink(uint64_t, char*);
-
-/* Inserts an ele short vlink into CURR_ODAT*/
-void
-insert_ele_svlink(uint64_t);
-
-/* inserts ele into CURR_CLASS and CURR_ODAT */
-void
-insert_ele(void);
-
-void
-insert_ele_vdatid(void);
-
-/* Inserts the hitbox into the CURR_ODAT */
-void
-insert_hitbox(int);
-
-/* Inserts the root into the CURR_ODAT */
-void
-insert_root(int, int, int);
-
-/* Inserts a quad into the CURR_ODAT */
-void
-insert_quad(void*);
-
-void
-insert_model(void);
-
-void
-insert_framesheet(char, char*, uint64_t, int, int, int);
-
-void
-insert_frame_pointer(char, void*);
-
-void
-alloc_vdat(void);
+/*!@file\r
+ \brief Intermediate Representation (IR) between Directory Structure and Engine Grammar\r
+ \details The IR serves as a storage structure that is populated during the\r
+ parsing of the input directory structure. After parsing is complete,\r
+ the IR will be condensed (removed of excess allocated space) and then\r
+ output as the Engine Grammar. In this file we describe the semantic actions\r
+ that are called at each step, and the memory buffers that they populate.\r
+ See parser.y for the description on how the input grammar is constructed,\r
+ and where/when semantic actions are called.\r
+ TODO: or just write it here.\r
+ \author Jordan Lavatai\r
+ \date Aug 2016\r
+ ----------------------------------------------------------------------------*/\r
+\r
+\r
+#include <stdint.h>\r
+\r
+#define BUF_SIZE 256\r
+#define MAX_SETS 256\r
+#define MAX_ELES 256\r
+#define MAX_QUADS 256\r
+#define MAX_MODELS 256\r
+#define MAX_POSTS 256\r
+#define MAX_CLASS_DEPTH 256\r
+#define MAX_CLASSES 256\r
+#define MAX_FRAMES 256\r
+#define PTRS_IN_PAGE 1024\r
+#define MAX_CHUNKS 256\r
+#define PAGES_PER_CHUNK 16\r
+\r
+/* Sets: elements. The set is populated at parse time AFTER the\r
+ elements are populated, due to the nature of bottom up parsing. */\r
+\r
+struct set {\r
+ char name[32];\r
+ uint64_t ref_id;\r
+ int cdat_idx;\r
+};\r
+\r
+/* Cdats: A cdat is a class data structure. Cdats serve as the central */\r
+/* data types of the IR. For each cdat, sets and element */\r
+/* ref_ids must be dereferenced to determine the odat information. Cdats */\r
+/* contain pointers to their subclasses so that the relationship between */\r
+/* classes can be determined, but the subclasses are not represented inside */\r
+/* of the cdat itself but rather in subsequent cdats in cdat_buf. We */\r
+/* can determine the number of subclasses (the last index into cdat_buf */\r
+/* that represents a subclass of some arbitrary cdat) each cdat has by */\r
+/* incrementing num_classes during parse time. */\r
+/* TODO: Should classes point to their parent class? */\r
+\r
+struct cdat {\r
+ char name[32];\r
+ int idx;\r
+ int num_classes;\r
+ int num_sets;\r
+ struct cdat* class_list[MAX_CLASSES];\r
+ struct set set_list[MAX_SETS];\r
+};\r
+\r
+/* The cdat_stack is a stack pointers to cdat pointers, the top of which is\r
+ the cdat that is currently being parsed. Whenever a new cdat is recognized\r
+ by the grammar (CLOPEN), a cdat is pushed onto the cdat_stack, and we refer\r
+ to this cdat through the macro CURR_CDAT. By keeping a cdat_stack, we have\r
+ access to the current cdat so that the elements and sets can populate themselves\r
+ in the cdat accordingly. */\r
+\r
+\r
+/* Refs: Each set/ele has a reference to its object data (odat) through a ref_id.\r
+ Ref_ids are unsigned 64 byte integers that map to the hex values RGBA. During\r
+ the construction of the directory structure, users can choose a RGBA value for\r
+ each object that any other object can refer to via links (see link). If a user\r
+ does not choose an RGBA value, then the object is given one from the system space.\r
+ We maintain a doubly linked list of refs in the ref_buf at parse time so that\r
+ links can be resolved after the parsing of the directory structure is complete.\r
+ For every 16th ref, we create a post so that we can reduce on the search time for\r
+ a random access. */\r
+\r
+struct ref {\r
+ int type;\r
+ struct ref* nextref;\r
+ struct ref* lastref;\r
+ struct odat* odatp;\r
+ uint64_t ref_id; //0xFFFFFF->digit\r
+};\r
+\r
+\r
+/* Links: At parse time, a set/ele can include a link in their\r
+ grammar representation instead of the actual data and this signifies\r
+ to the APC that that set/ele wishes to use the data of another\r
+ set/ele, either its video data (vdat) or object data (odat). The link\r
+ itself contains the type of link it is, the ref_id OR name, and\r
+ which set/ele created the link. During parse time, links can be made\r
+ to o/vdats that have yet to be parsed. In order to accomodate for this,\r
+ we resolve all links AFTER parse time by iterating through the link_buf,\r
+ finding the ref_id that was stored for some object (if the ref_id exists),\r
+ and creating a relative pointer from the original object to the data that\r
+ was linked */\r
+\r
+/* Svlinks stand for short vlink, which is a link to a vdat. svlinks\r
+ differ from vlinks because they do not have a name */\r
+\r
+struct svlink {\r
+ uint64_t ref_id;\r
+};\r
+\r
+/* A vlink is what it sounds like, a link to a vdat */\r
+struct vlink {\r
+ uint64_t ref_id;\r
+ char anim_name[32];\r
+};\r
+\r
+union link_t {\r
+ struct vlink vlink;\r
+ struct svlink svlink;\r
+};\r
+\r
+/* From: src odat ()To: dest odat (ref_id)*/\r
+struct link {\r
+ int type; //1 = olink, 2 = vlink, 3 = svlink\r
+ union link_t link_t;\r
+ struct cdat* classp;\r
+ struct odat* odatp;\r
+ int set_idx;\r
+ int ele_idx;\r
+};\r
+\r
+\r
+/* Odats: Odats consist of the object data necessary for\r
+ each object. Odats are sometimes referred to as archetypes\r
+ at compile-time, in order to distinguish the difference from\r
+ a runtime object and a compile-time object.\r
+ TODO: Need more info about objects at runtime, to described\r
+ the reasoning behind odat structure at compile-time*/\r
+\r
+struct root {\r
+ int x, y, z;\r
+};\r
+\r
+struct odat {\r
+ char name[32];\r
+ struct vdat* vdatp;\r
+ int vdat_id; //\r
+ int cdat_idx;\r
+ int hitbox;\r
+ uint64_t ref_id;\r
+ struct root root;\r
+ struct ref* refp; /* pointer to it's ref on ref_list */\r
+ void* quad_filep;\r
+};\r
+\r
+struct odat* curr_set_odatp; //when a set has elements, insert_set() can no longer\r
+ //refer to its odat via curr_odat, so save the set odat. \r
+\r
+/* A framesheet is a grouping of animation frames in\r
+ a single direction (N,W,S,E) */\r
+struct framesheet {\r
+ int width;\r
+ int height;\r
+ int num_frames;\r
+ void* frames[MAX_FRAMES];\r
+};\r
+\r
+/* A model is a collection of framesheets for every\r
+ direction (N,W,S,E,NW,NE,SW,SE)*/\r
+/* NAMED spritesheet */\r
+struct model {\r
+ char name[32];\r
+ struct framesheet spritesheet[8]; //one for each\r
+};\r
+\r
+/* Vdat: Vdats are the video data of each object. They can not be\r
+ created as a stand alone object (because they consist solely\r
+ of animation information and not the skeleton on which the\r
+ animation manipulates). Vdats have a list of models for every\r
+ animation that the vdats odat can do for that vdat*/\r
+struct vdat {\r
+ struct odat* creator; //pointer to odat that made this vdat\r
+ int num_models;\r
+ struct model model_list[MAX_MODELS];\r
+};\r
+\r
+/* Called after the cdat open operator has been recognized in grammar. Allocates\r
+ the space for a cdat on the cdat_buf, pushes that pointer onto\r
+ the cdat_stack */\r
+void\r
+push_cdat(char*);\r
+\r
+/* Called after a cdat end operator has been recognized in grammar. Sets\r
+ top stack cdat ** to null and decrements stack pointer */\r
+void\r
+pop_cdat(void);\r
+\r
+/* Called after an odat has been populated. Allocates memory for\r
+ the next odat. */\r
+\r
+void\r
+insert_set_label(char*, uint64_t);\r
+\r
+/* Populate the sets representation in CURR_CDAT with a ref_id and insert a link\r
+ into the link_buf that will resolve the ref_id to an actual odat after parse time. */\r
+void\r
+insert_set_olink(uint64_t);\r
+\r
+/* Put the vlink in the link_buf to be processed after parsetime */\r
+void\r
+insert_set_vlink(uint64_t, char*);\r
+\r
+/* Put svlink in the link_buf to be processed after parsetime */\r
+void\r
+insert_set_svlink(uint64_t);\r
+\r
+/* Called for every set reduction except for sets with olinks. Populates the\r
+ set data structures in the CDAT and in the ODAT. Uses the name and ref_id\r
+ from insert_set_label. Also inserts a ref into the ref_buf with the CURR_ODAT\r
+ pointer so that we can also resolve the odat from its ref_id. */\r
+void\r
+insert_set(void);\r
+\r
+/* Insertion of eles is practically equivalent to how sets are inserted because both\r
+ share the same data type (ODAT). Like sets, eles have links, labels\r
+ and odats. Eles have the added notion of a parent set, and so must be inserted\r
+ into said parent set, but this is the only place they truly differ from sets. */\r
+\r
+void\r
+insert_set_vdatid(void);\r
+\r
+void\r
+insert_ele_label(char*, uint64_t);\r
+\r
+/* Insert an ele olink into the CURR_ODAT */\r
+void\r
+insert_ele_olink(uint64_t);\r
+\r
+/* Insert a ele vlink into CURR_ODAT*/\r
+void\r
+insert_ele_vlink(uint64_t, char*);\r
+\r
+/* Inserts an ele short vlink into CURR_ODAT*/\r
+void\r
+insert_ele_svlink(uint64_t);\r
+\r
+/* inserts ele into CURR_CLASS and CURR_ODAT */\r
+void\r
+insert_ele(void);\r
+\r
+void\r
+insert_ele_vdatid(void);\r
+\r
+/* Inserts the hitbox into the CURR_ODAT */\r
+void\r
+insert_hitbox(int);\r
+\r
+/* Inserts the root into the CURR_ODAT */\r
+void\r
+insert_root(int, int, int);\r
+\r
+/* Inserts a quad into the CURR_ODAT */\r
+void\r
+insert_quad(void*);\r
+\r
+void\r
+insert_model(void);\r
+\r
+void\r
+insert_framesheet(char, char*, uint64_t, int, int, int);\r
+\r
+void\r
+insert_frame_pointer(char, void*);\r
+\r
+void\r
+alloc_vdat(void);\r
-/* Ragel State Machine for tokenizing text */
-#include <stdio.h>
-#include <string.h>
-#include <apc/parser.tab.h>
-
-extern void lexer_pushtok(int, YYSTYPE);
-
-int lexer_lex(const char*);
-int ipow(int, int);
-int ttov(const char* str, int);
-uint64_t ttor(const char* str, int);
-char* ttos(const char* str, int);
-
-
-#define MAX_TOK_LEN 64
-#define MAX_TOKENS 16
-#define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS)
-#define $($)#$
-#define PUSHTOK(TOK,LFUNC,UTYPE) \
- do { \
- printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \
- tok_t = TOK; \
- yylval.UTYPE = LFUNC(ts, p-ts); \
- lexer_pushtok(tok_t, yylval); \
- ++ntok; \
- } while (0)
-
-%%{
- machine token_matcher;
-
- # set up yylval and tok_t to be pushed to stack
- action set_ref { PUSHTOK(REF, ttor, ref); }
- action set_val { PUSHTOK(NUM, ttov, val); }
- action set_name { PUSHTOK(NAME, ttos, str); }
- action set_ts { ts = p; }
- action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);}
-
- # instantiate machines for each possible token
- ref = '0x' xdigit+ %set_ref;
- val = digit+ %set_val;
- name = alpha+ %set_name;
- tok = ref | val | name;
- segment = (tok . '_') %set_ts;
-
- main := segment* . tok $lerr(lex_error);
-}%%
-
-
-%%write data;
-
-/* Scan filename and push the its tokens
- onto the stack */
-int lexer_lex (const char* str)
-{
- const char *p, *pe, *ts, *eof;
- int cs, tok_t, ntok = 0;
- printf ("Lexing: %s\n",str);
- p = ts = str;
- pe = p + strlen(str);
- %%write init;
- %%write exec;
- printf ("Lexed %i tokens\n",ntok);
- return ntok;
-}
-
-int ipow(int base, int exp)
-{
- int result = 1;
- while (exp)
- {
- if (exp & 1)
- result = result * base;
- exp = exp >> 1;
- base *= base;
- }
-
- return result;
-}
-
-/* Token to Value */
-int ttov(const char* str, int len)
-{
- int i, val = 0;
-
- for (i = 0; i < len; i++)
- {
- val += ((str[len - (i + 1)] - '0') * ipow(10,i));
- }
-
- return val;
-}
-
-uint64_t ttor(const char* str, int len)
-{
- int i;
- uint64_t num = 0;
-
- for (i = 0; i < len; i++)
- {
- num += ((str[len - (i + 1)] - '0') * ipow(10,i));
- }
-
- return num;
-}
-
-char* ttos(const char* str, int len)
-{
- int i;
- char token_buf[MAX_TOK_LEN];
-
- memmove(token_buf, str, len);
- token_buf[len+1] = '\0';
-
- return strdup(token_buf);
-}
+/* Ragel State Machine for tokenizing text */\r
+#include <stdio.h>\r
+#include <string.h>\r
+#include <apc/parser.tab.h>\r
+\r
+extern void lexer_pushtok(int, YYSTYPE);\r
+\r
+int lexer_lex(const char*);\r
+int ipow(int, int);\r
+int ttov(const char* str, int);\r
+uint64_t ttor(const char* str, int);\r
+char* ttos(const char* str, int);\r
+\r
+\r
+#define MAX_TOK_LEN 64\r
+#define MAX_TOKENS 16\r
+#define MAX_STR_SIZE (MAX_TOK_LEN * MAX_TOKENS)\r
+#define $($)#$\r
+#define PUSHTOK(TOK,LFUNC,UTYPE) \\r
+ do { \\r
+ printf("PUSHTOK(" $(TOK) $(LFUNC) $(UTYPE) ")\n"); \\r
+ tok_t = TOK; \\r
+ yylval.UTYPE = LFUNC(ts, ts-p-1); \\r
+ lexer_pushtok(tok_t, yylval); \\r
+ ++ntok; \\r
+ } while (0)\r
+\r
+%%{\r
+ machine token_matcher;\r
+\r
+ # set up yylval and tok_t to be pushed to stack\r
+ action set_ref { PUSHTOK(REF, ttor, ref); }\r
+ action set_val { PUSHTOK(NUM, ttov, val); }\r
+ action set_name { PUSHTOK(NAME, ttos, str); }\r
+ action set_ts { ts = p; }\r
+ action lex_error {printf("input error: character %c in filename %s is invalid\n", fc, str);}\r
+\r
+ # instantiate machines for each possible token\r
+ ref = '0x'. xdigit+ . '_' %set_ref;\r
+ val = digit+ . '_' %set_val;\r
+ name = alpha+ . '_' %set_name;\r
+ tok = (ref | val | name) %set_ts;\r
+\r
+ main := alpha+ @set_name;\r
+}%%\r
+\r
+\r
+%%write data;\r
+/* Scan filename and push the its tokens\r
+ onto the stack */\r
+int lexer_lex (const char* str)\r
+{\r
+ const char *p, *pe, *ts, *eof;\r
+ int cs, tok_t, ntok = 0;\r
+ printf ("Lexing: %s\n",str);\r
+ p = ts = str;\r
+ pe = p + strlen(str);\r
+ printf("p = %s \n", p);\r
+ %%write init;\r
+ %%write exec;\r
+ printf ("Lexed %i tokens\n",ntok);\r
+ return ntok;\r
+}\r
+\r
+int ipow(int base, int exp)\r
+{\r
+ int result = 1;\r
+ while (exp)\r
+ {\r
+ if (exp & 1)\r
+ result = result * base;\r
+ exp = exp >> 1;\r
+ base *= base;\r
+ }\r
+\r
+ return result;\r
+}\r
+\r
+/* Token to Value */\r
+int ttov(const char* str, int len)\r
+{\r
+ int i, val = 0;\r
+\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ val += ((str[len - (i + 1)] - '0') * ipow(10,i));\r
+ }\r
+\r
+ return val;\r
+}\r
+\r
+uint64_t ttor(const char* str, int len)\r
+{\r
+ int i;\r
+ uint64_t num = 0;\r
+\r
+ for (i = 0; i < len; i++)\r
+ {\r
+ num += ((str[len - (i + 1)] - '0') * ipow(10,i));\r
+ }\r
+\r
+ return num;\r
+}\r
+\r
+char* ttos(const char* str, int len)\r
+{\r
+ int i;\r
+ char token_buf[MAX_TOK_LEN];\r
+\r
+ memmove(token_buf, str, len);\r
+ token_buf[len+1] = '\0';\r
+\r
+ return strdup(token_buf);\r
+}\r
;
class:
- NAME CLOPEN {push_cdat($1);} class_block CLCLOSE {pop_cdat();};
+ CLOPEN NAME {push_cdat($2);} class_block CLCLOSE {pop_cdat();};
;
class_block:
;
root:
-RT NUM NUM NUM {insert_root($2, $3, $4);};
+RT NUM NUM NUM {insert_root($2, $3, $4);};
;
quad_file:
QOPEN QPTR QCLOSE {insert_quad($2);};
hitbox:
-HB NUM {insert_hitbox($2);}
+HB NUM {insert_hitbox($2);}
;
set_map_data:
;
set:
-SOPEN set_label set_map_data element_list {alloc_vdat();} vdat SCLOSE {insert_set(); insert_set_vdatid();};
+SOPEN set_label set_map_data element_list {alloc_vdat();} vdat SCLOSE {insert_set(); insert_set_vdatid();};
| SOPEN set_label set_map_data element_list set_vlink SCLOSE {insert_set();};
| SOPEN set_label set_map_data element_list set_svlink SCLOSE {insert_set_svlink($5); insert_set(); };
| SOPEN set_label element_list {alloc_vdat();} vdat SCLOSE {insert_set(); insert_set_vdatid();};
set_label:
-HP NAME REF {insert_set_label($2,$3);};
-| LP NAME {insert_set_label($2, -1);};
+HP NAME REF {insert_set_label($2,$3);};
+| LP NAME {insert_set_label($2, -1);};
;
set_svlink:
;
set_vlink:
-REF NAME {insert_set_vlink($1, $2);};
+REF NAME {insert_set_vlink($1, $2);};
;
olink:
;
ele_label:
-HP NAME REF {insert_ele_label($2, $3);};
-| LP NAME {insert_ele_label($2, -1);};
+HP NAME REF {insert_ele_label($2, $3);};
+| LP NAME {insert_ele_label($2, -1);};
;
ele_vlink:
-REF NAME {insert_ele_vlink($1, $2);};
+REF NAME {insert_ele_vlink($1, $2);};
;
ele_svlink:
| EOPEN ele_label hitbox root ele_svlink ECLOSE {insert_ele_svlink($5);insert_ele(); };
| EOPEN ele_label root {alloc_vdat();} vdat ECLOSE {insert_ele(); insert_ele_vdatid();};
| EOPEN ele_label root ele_vlink ECLOSE {insert_ele(); };
-| EOPEN ele_label root ele_svlink ECLOSE {insert_ele_svlink($4); insert_ele(); };
+| EOPEN ele_label root ele_svlink ECLOSE {insert_ele_svlink($4); insert_ele(); };
| EOPEN olink ECLOSE {insert_ele_olink($2);};
;
;
frame_pointers:
-frame_pointers SSD HP FPTR {insert_frame_pointer($2, $4);};
-| SSD FPTR {insert_frame_pointer($1, $2);};
+frame_pointers SSD HP FPTR {insert_frame_pointer($2, $4);};
+| SSD FPTR {insert_frame_pointer($1, $2);};
;
%%