updated lexer_lex and ir
authorjordan@hack_attack <jordanlavatai@gmail.com>
Thu, 6 Oct 2016 21:31:40 +0000 (14:31 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Thu, 6 Oct 2016 21:31:40 +0000 (14:31 -0700)
src/apc/ir.c
src/apc/ir.h
src/apc/irmem.c
src/apc/lexer_lex.rl

index 8030755..5af236d 100644 (file)
@@ -56,7 +56,7 @@ curr_set(void);
 
 extern
 struct ref*
-prev_ref(void);
+curr_ref(void);
 
 extern
 struct quad*
@@ -104,7 +104,6 @@ void
 pop_cdat
 ()
 {
-  *cdat_stackp = NULL;
   cdat_stackp--;
 }
 
@@ -116,7 +115,8 @@ pop_cdat
    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. */
+   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
@@ -124,6 +124,7 @@ insert_set_label
   uint64_t ref_id
 )
 {
+
   struct set* curr_setp;
 
   curr_setp = curr_set();
@@ -131,20 +132,31 @@ insert_set_label
 
   memmove(curr_set_odatp->name, name, 32);
   memmove(curr_setp->name, name, 32);
-  curr_setp->ref_id = ref_id;
+
+  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;
   struct cdat* curr_cdatp;
   struct link* curr_linkp;
+  struct odat* curr_setp;
 
-  curr_setp = curr_set();
   curr_cdatp = curr_cdat();
+  curr_setp = alloc_odat();
   curr_linkp = alloc_link();
 
   curr_setp->cdat_idx = curr_cdatp->idx;
@@ -152,7 +164,7 @@ insert_set_olink
                                           when link is processed */
   curr_linkp->type = 1;
   curr_linkp->link_t.olink.ref_id = ref_id;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets++;
   curr_linkp->ele_idx = -1;
 
@@ -174,7 +186,7 @@ insert_set_vlink
      output time */
   curr_linkp->type = 2;
   curr_linkp->link_t.vlink.ref_id = ref_id;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets;
   curr_linkp->ele_idx = -1;
   memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
@@ -196,7 +208,7 @@ insert_set_svlink
   /* Insert svlink into link_stack so that it gets processed at
      output time */
   curr_linkp->type = 3;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  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;
@@ -221,7 +233,7 @@ insert_set
   curr_odatp = curr_set_odatp; //allocated at insert_set_label, preserved in global space
   curr_cdatp = curr_cdat();
   curr_setp = curr_set();
-  prev_refp = prev_ref();
+  prev_refp = curr_ref();
   curr_refp = alloc_ref();
   curr_vdatp = curr_vdat();
 
@@ -236,11 +248,6 @@ insert_set
 
   ref_id = curr_setp->ref_id; // ref_id set by insert_set_label(name, ref_id)
 
-  if(ref_id == -1) /* user did not define a ref_id  */
-    { ref_id = ss_ref_id;
-      ss_ref_id++;
-    }
-
   curr_refp->ref_id = ref_id;
   curr_refp->lastref = prev_refp;
   curr_refp->odatp = curr_odatp;
@@ -256,12 +263,17 @@ 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 = NULL; //So this sets odat cant be modified after (which would be a bug)
+  curr_set_odatp->vdatp = curr_vdatp;
+  curr_set_odatp = NULL; //This sets odat shouldnt be modified after populating odats vdat info
 }
 
-/* Populates both the odat name and ref_id
  for odat and ele */
+/* 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,
@@ -273,7 +285,11 @@ insert_ele_label
   curr_odatp = alloc_odat();
 
   memmove(curr_odatp->name, name, 32);
-  curr_odatp->ref_id = ref_id;
+
+  if(ref_id != -1)
+    curr_odatp->ref_id = ref_id;
+  else
+    curr_odatp->ref_id = ss_ref_id++;
 
 }
 
@@ -293,12 +309,12 @@ insert_ele_olink
   //curr_elep = curr_ele();
   curr_linkp = alloc_link();
 
-  //curr_elep->cdat_idx = curr_cdatp->idx;
+  //curr_elep->cdat_idx = curr_cdatp;
   //curr_elep->ref_id = ref_id;
 
   curr_linkp->type = 1;
   curr_linkp->link_t.olink.ref_id = ref_id;
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->set_idx = curr_cdatp->num_sets++;
   //curr_linkp->ele_idx = curr_setp->num_ele++;
 
@@ -320,7 +336,7 @@ insert_ele_vlink
 
   /* Insert vlink into link_stack so that it gets processed at
      output time */
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  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;
@@ -342,7 +358,7 @@ insert_ele_svlink
   curr_setp = curr_set();
   curr_linkp = alloc_link();
 
-  curr_linkp->cdat_idx = curr_cdatp->idx;
+  curr_linkp->classp = curr_cdatp;
   curr_linkp->type = 3;
 
   //curr_linkp->ele_idx = curr_setp->num_ele;
@@ -368,8 +384,8 @@ insert_ele()
   curr_odatp = curr_odat(); //malloced @ insert_ele_label
   curr_vdatp = curr_vdat();
   curr_setp = curr_set();
+  prev_refp = curr_ref();
   curr_refp = alloc_ref();
-  prev_refp = prev_ref();
 
   curr_vdatp->creator = curr_odatp;
 
@@ -379,12 +395,6 @@ insert_ele()
 
   ref_id = curr_odatp->ref_id;
 
-
-  if(ref_id == -1) /* user did not define a ref_id so */
-    { ref_id = ss_ref_id;
-      ss_ref_id++;
-    }
-
   curr_refp->ref_id = ref_id;
   curr_refp->lastref = prev_refp;
   curr_refp->odatp = curr_odatp;
@@ -405,18 +415,6 @@ insert_quad
 ( void* quad_filep
 )
 {
-
-  /* struct quad* curr_quadp; */
-  /* struct odat* curr_odatp; */
-
-  /* curr_quadp = curr_quad(); */
-  /* curr_odatp = curr_odat(); */
-
-  /* curr_quadp->x = x; */
-  /* curr_quadp->y = y; */
-  /* curr_quadp->z = z; */
-  /* curr_quadp->ref_id = ref_id; */
-  /* curr_odatp->num_quads++; */
   struct odat* curr_odatp;
 
   curr_odatp->quad_filep = quad_filep;
index 0292e01..53b1d65 100644 (file)
 #define MAX_CHUNKS 256
 #define PAGES_PER_CHUNK 16
 
-/*  General: All information from the directory structure is stored in        */
-/*  five buffers that comprise the IR: cdat_buf, odat_buf, vdat_buf, ref_buf  */
-/*  and link_buf. Each buf corresponds to the data structure that it stores.  */
-/*  The storage techique for all bufs (except cdat) is the same. Each bufs member first */
-/*  populates its struct and then allocates the space for the next member     */
-/*  and increments the buf index. This means that we have to allocate the     */
-/*  very first member of each buf at ir_init(), so that we don't segfault     */
-/*  as the first member attempts to access memory that its previous member    */
-/*  didn't allocate (because it doesnt exist). We access the buf members      */
-/*  through standard array indexing but conceal the tediousness of array      */
-/*  indexing with macros. E.g. without macros, acessing an elements name      */
-/*  member would look like (split up to not go over line char limit):         */
-/*  (*cdat_stackp)->set_list[(*cdat_stackp)->num_sets] */
-/*     .ele_list[(*cdat_stackp)->set_list[(*cdat_stackp->num_sets)].num_ele].name */
-
-/* For cdats in cdat_buf, we allocate the memory for a cdat once a cdat
-   is recognized in the grammar. Cdat_buf is different from the other bufs
-   because cdats have a root cdat that all cdats are a subclass of. This root
-   cdat can have a set_list like other cdats.                                */
-
-/*  All bufs are of pointers to their respective structs. When a buf is full */
-/*  (number of data structs pointers >= max number of data struct pointers),        */
-/*  we need to allocate a more pointers for that buf. Allocate these       */
-/*  pointers a page at a time (1024 = Page bytes (4096)/bytes per pointer(4))   */
-
-/*  Sets: The set is similar to the ele, but it contains a list of its    */
-/*  elements. The set is populated at parse time AFTER the elements are   */
-/*  populated, due to the nature of bottom up parsing.                    */
+/*  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];
@@ -64,12 +38,11 @@ struct set {
 };
 
 /*  Cdats: A cdat is a class data structure. Cdats serve as the central       */
-/*  data types of the IR. At output, the cdat_buf is iterated through and     */
-/*  each is written to the output file. For each cdat, sets and element       */
+/*  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 the subsequent cdats in cdat_buf. We     */
+/*  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.                               */
@@ -84,9 +57,6 @@ struct cdat {
   struct set set_list[MAX_SETS];
 };
 
-/* There are an unknown amount of cdats at compile time, so we maintain    */
-/*   a cdat_buf of cdat pointers that can be expanded as needed.           */
-
 /* 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
@@ -114,11 +84,6 @@ struct ref {
 };
 
 
-/* Like the cdat_buf, ref_buf stores pointers to refs and can
-   increase in size */
-
-/* posts for ref_buf */
-
 /* 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
@@ -131,15 +96,14 @@ struct ref {
    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
-   TODO: diff btwn vlink*/
+/* 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
- TODO: model link? */
+/* A vlink is what it sounds like, a link to a vdat */
 struct vlink {
   uint64_t ref_id;
   char anim_name[32];
@@ -156,20 +120,15 @@ union link_t {
   struct svlink svlink;
 };
 
+/* From: Some odat ()To: Another odat (ref_id)*/
 struct link {
   int type; //1 = olink, 2 = vlink, 3 = svlink
   union link_t link_t;
-  int cdat_idx;
+  struct cdat* classp;
   int set_idx;
   int ele_idx;
 };
 
-/* link_buf contains all the links that
-   we encountered during parse time that need
-   to be resolved to an offset at output time.
-   This does not include quad refs, because
-   those are already known to need to be resolved */
-
 
 /* Odats: Odats consist of the object data necessary for
    each object. Odats are sometimes referred to as archetypes
@@ -178,14 +137,14 @@ struct link {
    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];
-  int vdat_id;
+  struct vdat* vdatp;
+  int vdat_id; //
   int cdat_idx;
   int hitbox;
   uint64_t ref_id;
index 67068d9..3716d59 100644 (file)
@@ -26,7 +26,7 @@ curr_vdat(void);
 struct set*
 curr_set(void);
 struct ref*
-prev_ref(void);
+curr_ref(void);
 struct model*
 curr_model(void);
 void
@@ -34,7 +34,6 @@ inc_posts(void);
 
 #define PAGES_PER_CHUNK 16
 
-#define CURR_CDAT  (*cdat_stackp)
 //"type free" chunk stacking
 struct chunk_stack
 { void* chunks[MAX_CHUNKS];
@@ -47,6 +46,8 @@ struct chunk_stack
 //type safety handled by macro expansion (do not call these directly from code, make dependent macros for access to these)
 #define CHUNKS_LEN(STACK)         ((STACK).csp - (STACK).chunks)
 #define CURRENT_CHUNK(STACK)      ((STACK).chunks[CHUNKS_LEN(STACK) - 1])
+#define CHUNKS_FULL(STACK)        ( (STACK).csp >= \
+                                    (STACK).chunks + MAX_CHUNKS * (STACK).chunk_size)
 #define CURRENT_DSP(STACK,TYPE)   ((TYPE*) ((STACK).dsp[CHUNKS_LEN(STACK) - 1]))
 #define DATA_FULL(STACK,TYPE)     ((void*) CURRENT_DSP(STACK,TYPE) >=  \
                                   (CURRENT_CHUNK(STACK) + (STACK).chunk_size))
@@ -54,32 +55,47 @@ struct chunk_stack
 #define CURRENT_DATP(STACK,TYPE)  (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 1])
 #define PREVIOUS_DATP(STACK,TYPE) (((TYPE**)(STACK).dsp)[CHUNKS_LEN(STACK) - 2])
 #define ALLOC_DAT(STACK,TYPE)     (++CURRENT_DATP(STACK,TYPE))
-#define INIT_STACK(STACK,TYPE)                                 \
-  do {                                                         \
-    (STACK).chunk_size = PAGES_PER_CHUNK;                      \
+#define INIT_STACK(STACK,TYPE) \
+  { int i; \
+    (STACK).chunk_size = PAGES_PER_CHUNK * pagesize;            \
     (STACK).max_dats = (STACK).chunk_size / sizeof (TYPE);     \
-    CSP_PUSH(STACK);                                           \
-  } while (0)
+    CSP_PUSH(STACK); \
+    for( i = 0; i < MAX_CHUNKS; i++){ \
+      (STACK).dsp[i] += pagesize; \
+    } \
+  }
 //Stack-specific macros (called directly from code (safety enforcement)
+#define INIT_ODAT()     (INIT_STACK(ocs, struct odat))
 #define CURRENT_ODAT()  (CURRENT_DATP(ocs,struct odat))
 #define ODAT_FULL()     (DATA_FULL(ocs,struct odat))
 #define ODAT_ALLOC()    (ALLOC_DAT(ocs,struct odat))
+#define OCS_FULL()      (CHUNKS_FULL(ocs))
+#define INIT_VDAT()     (INIT_STACK(vcs, struct vdat))
 #define CURRENT_VDAT()  (CURRENT_DATP(vcs,struct vdat))
 #define VDAT_FULL()     (DATA_FULL(vcs,struct vdat))
 #define VDAT_ALLOC()    (ALLOC_DAT(vcs,struct vdat))
+#define VCS_FULL()      (CHUNKS_FULL(vcs))
+#define INIT_CDAT()     (INIT_STACK(ccs, struct cdat))
 #define CURRENT_CDAT()  (CURRENT_DATP(ccs,struct cdat))
 #define CDAT_FULL()     (DATA_FULL(ccs, struct cdat))
 #define CDAT_ALLOC()    (ALLOC_DAT(ccs, struct cdat))
+#define CCS_FULL()      (CHUNKS_FULL(ccs))
+#define INIT_LINK()     (INIT_STACK(lcs, struct link))
 #define CURRENT_LINK()  (CURRENT_DATP(lcs,struct link))
 #define LDAT_FULL()     (DATA_FULL(lcs, struct link))
 #define LDAT_ALLOC()    (ALLOC_DAT(lcs, struct link))
+#define LCS_FULL()      (CHUNKS_FULL(lcs))
+#define INIT_POST()     (INIT_STACK(rcs, struct ref))
 #define CURRENT_POST()  (CURRENT_DATP(pcs,struct ref))
 #define POST_FULL()     (DATA_FULL(pcs,struct ref))
 #define POST_ALLOC()    (ALLOC_DAT(pcs,struct ref))
+#define PCS_FULL()      (CHUNKS_FULL(pcs))
+#define INIT_REF()      (INIT_STACK(rcs, struct ref))
 #define CURRENT_REF()   (CURRENT_DATP(rcs,struct ref))
 #define PREVIOUS_REF()  (PREVIOUS_DATP(rcs, struct ref))
 #define REF_FULL()      (DATA_FULL(rcs,struct ref))
 #define REF_ALLOC()     (ALLOC_DAT(rcs,struct ref))
+#define RCS_FULL()      (CHUNKS_FULL(rcs))
 //Metadata
 #define CURRENT_SET()   (CURRENT_CDAT()->set_list[CURRENT_CDAT()->num_sets])
 #define CURRENT_MODEL() (CURRENT_VDAT()->model_list[CURRENT_VDAT()->num_models])
@@ -89,13 +105,9 @@ struct chunk_stack
 
 long pagesize;
 
-int pages_per_chunk = 10;
-
 int num_cdats = 0;
-int curr_max_cdats = PTRS_IN_PAGE;
 
-struct cdat* cdat_buf[PTRS_IN_PAGE];
-struct cdat* cdat_stack[PTRS_IN_PAGE];
+struct cdat* cdat_stack[MAX_CLASSES];
 struct cdat** cdat_stackp;
 
 int num_odats = 0;
@@ -105,14 +117,9 @@ int num_vdats = 0;
 int num_refs = 0;
 uint64_t ss_ref_id = 0x00FFFFFF; /* system space for ref_ids */
 
-int num_posts = -1;
-int curr_max_posts = PTRS_IN_PAGE;
-struct ref* post_buf[PTRS_IN_PAGE];
-
+int num_posts = 0;
 
-int num_links = -1;
-int curr_max_links = PTRS_IN_PAGE;
-struct link* link_buf[PTRS_IN_PAGE];
+int num_links = 0;
 
 
 /* The initalization function of the IR. */
@@ -120,21 +127,20 @@ int
 ir_init()
 {
 
-  /* Init root cdat and stack */
   char root[4] = "root";
 
-  if( (cdat_buf[num_cdats] = (struct cdat*) malloc(sizeof(struct cdat))) == NULL)
-    {
-      perror("malloc root class failed\n");
-      return -1;
-    }
-  cdat_buf[num_cdats]->idx = num_cdats;
-  memmove(cdat_buf[num_cdats]->name, root, 4);
+  pagesize = sysconf(_SC_PAGESIZE);
 
-  cdat_stackp = cdat_stack;
-  *cdat_stackp++ = cdat_buf[num_cdats++];
+  INIT_CDAT();
+  *cdat_stackp = CURRENT_CDAT();
+  memmove((*cdat_stackp)->name, root, 32);
+
+  INIT_ODAT();
+  INIT_VDAT();
+  INIT_LINK();
+  INIT_REF();
+  INIT_POST();
 
-  pagesize = sysconf(_SC_PAGESIZE);
 
   return 0;
 
@@ -145,54 +151,68 @@ ir_quit()
 {
   int i;
 
-  for(i = 0; i <= num_odats ; i++)
+  for(i = 0; i < CHUNKS_LEN(ccs) ; i++)
     {
+      free(ccs.chunks[i]);
     }
-  for(i = 0; i <= num_cdats; i++)
+  for(i = 0; i < CHUNKS_LEN(ocs); i++)
     {
+      free(ocs.chunks[i]);
     }
-  for(i = 0; i <= num_vdats; i++)
+  for(i = 0; i < CHUNKS_LEN(vcs) ; i++)
     {
+      free(vcs.chunks[i]);
     }
-  for(i = 0; i <= num_refs; i++)
+  for(i = 0; i < CHUNKS_LEN(rcs); i++)
     {
+      free(rcs.chunks[i]);
     }
-  for(i = 0; i<= num_links; i++)
+  for(i = 0; i < CHUNKS_LEN(lcs); i++)
     {
+      free(lcs.chunks[i]);
     }
-  for(i = 0; i<= num_posts; i++)
+  for(i = 0; i < CHUNKS_LEN(pcs); i++)
     {
+      free(pcs.chunks[i]);
     }
 
 }
 
-//TODO: FREE MEMORY!
 struct cdat*
 alloc_cdat()
 {
   num_cdats++;
-  if(curr_max_cdats <= num_cdats)
-    { if( (realloc((void*) cdat_buf, PTRS_IN_PAGE * 4)) == NULL)
-        perror("realloc cdat_buf failed");
-      curr_max_cdats += PTRS_IN_PAGE;
-      if( (realloc( (void*) cdat_stack, PTRS_IN_PAGE * 4)) == NULL) //increase cdat_stack also
-        perror("realloc cdat_stack failed");
+  if(CDAT_FULL())
+    { if(CCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) cdats ", num_cdats);
+          exit(EXIT_FAILURE);
+        }
+      else
+        CSP_PUSH(ccs);
     }
-  if( (CURR_CDAT = (struct cdat*) malloc(sizeof (struct cdat)) ) == NULL )
-    perror("malloc cdat failed");
-
-  return CURR_CDAT;
+  else
+    CDAT_ALLOC();
 
+  return CURRENT_CDAT();
 }
 
 //these should probably be inline
 struct odat*
 alloc_odat
 ()
-{ if(ODAT_FULL())
-      CSP_PUSH(ocs);
+{
+  num_odats++;
+  if(ODAT_FULL())
+    { if(!OCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) odats ", num_odats);
+          exit(EXIT_FAILURE);
+        }
+      else
+        CSP_PUSH(ocs);
+    }
   else
     ODAT_ALLOC();
+
   return CURRENT_ODAT();
 }
 
@@ -201,7 +221,13 @@ alloc_vdat
 ()
 { num_vdats++;
   if(VDAT_FULL())
-    CSP_PUSH(vcs);
+    { if(!VCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) vdats ", num_vdats);
+          exit(EXIT_FAILURE);
+        }
+      else
+        CSP_PUSH(vcs);
+    }
   else
     VDAT_ALLOC();
 }
@@ -211,10 +237,18 @@ alloc_link
 ()
 { num_links++;
   if(LDAT_FULL())
-    CSP_PUSH(lcs);
+    { if(!LCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) links ", num_links);
+          exit(EXIT_FAILURE);
+        }
+      else
+        CSP_PUSH(lcs);
+    }
   else
     LDAT_ALLOC();
+
   return CURRENT_LINK();
+
 }
 
 struct ref*
@@ -222,10 +256,17 @@ alloc_ref
 ()
 { num_refs++;
   if(REF_FULL())
-    CSP_PUSH(rcs);
+    { if(!RCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) refs ", num_refs);
+          exit(EXIT_FAILURE);
+        }
+      else
+        CSP_PUSH(rcs);
+    }
   else
     REF_ALLOC();
 
+
   if(num_refs % 16 == 0)
     { CURRENT_POST() = CURRENT_REF();
       inc_posts();
@@ -238,16 +279,23 @@ void
 inc_posts()
 { num_posts++;
   if(POST_FULL())
-    CSP_PUSH(pcs);
+    { if(!PCS_FULL())
+        { fprintf(stderr, "You have allocated to many (%d) refs ", num_posts);
+          exit(EXIT_FAILURE);
+        }
+      else
+        CSP_PUSH(pcs);
+    }
   else
     POST_ALLOC();
+
 }
 
 struct cdat*
 curr_cdat
 ()
 {
-  return CURR_CDAT;
+  return (*cdat_stackp);
 }
 
 struct odat*
@@ -269,10 +317,10 @@ curr_set
   return &CURRENT_SET();
 }
 struct ref*
-prev_ref
+curr_ref
 ()
 {
-  return PREVIOUS_REF();
+  return CURRENT_REF();
 }
 struct model*
 curr_model
index cb068d6..e1f9669 100644 (file)
@@ -24,26 +24,26 @@ char* ttos(const char* str, int);
   action set_ref {
                    tok_t = REF;                      \
                    yylval.ref = ttor(ts, p-ts);      \
-                   lexer_pushtok(tok_t, yylval);     \
-                   ts = p;   }
+                   lexer_pushtok(tok_t, yylval); }
 
   action set_val { tok_t = NUM;                      \
                    yylval.val = ttov(ts, p-ts);      \
-                   lexer_pushtok(tok_t, yylval);     \
-                   ts = p;   }
+                   lexer_pushtok(tok_t, yylval); }
 
   action set_name { tok_t = NAME;                    \
                     yylval.str = ttos(ts, p-ts);     \
-                    lexer_pushtok(tok_t, yylval);    \
-                    ts = p;   }
+                    lexer_pushtok(tok_t, yylval); }
+
+  action set_ts   { ts = p; }
 
   # 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 := (tok . '_')* . tok;
+  main := segment* . tok;
 }%%