removed olinks, updated lexer_lex to handle errors
authorjordan@hack_attack <jordanlavatai@gmail.com>
Sun, 9 Oct 2016 03:44:50 +0000 (20:44 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Sun, 9 Oct 2016 03:44:50 +0000 (20:44 -0700)
src/apc/ir.c
src/apc/ir.h
src/apc/lexer_lex.rl

index 5af236d..f47e25a 100644 (file)
@@ -151,22 +151,11 @@ insert_set_olink
 ( uint64_t ref_id
 )
 {
-  struct cdat* curr_cdatp;
-  struct link* curr_linkp;
-  struct odat* curr_setp;
+  struct set* curr_setp;
 
-  curr_cdatp = curr_cdat();
-  curr_setp = alloc_odat();
-  curr_linkp = alloc_link();
+  curr_setp = curr_set();
 
-  curr_setp->cdat_idx = curr_cdatp->idx;
-  curr_setp->ref_id = ref_id; /* Will be resolved to offset
-                                          when link is processed */
-  curr_linkp->type = 1;
-  curr_linkp->link_t.olink.ref_id = ref_id;
-  curr_linkp->classp = curr_cdatp;
-  curr_linkp->set_idx = curr_cdatp->num_sets++;
-  curr_linkp->ele_idx = -1;
+  curr_setp->ref_id = ref_id;
 
 }
 
@@ -177,26 +166,32 @@ insert_set_vlink
 )
 {
   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;
-  memmove(curr_linkp->link_t.vlink.anim_name, anim_name, 32);
 
 }
 
 /* Svlinks dont have animation names */
 void
 insert_set_svlink
-( uint64_t ref_id
+( uint64_t ref_id 
 )
 {
   struct cdat* curr_cdatp;
@@ -300,24 +295,8 @@ insert_ele_olink
 ( uint64_t ref_id
 )
 {
-  struct cdat* curr_cdatp;
-  struct set* curr_setp;
-  struct ele* curr_elep;
-  struct link* curr_linkp;
-
-  curr_cdatp = curr_cdat();
-  //curr_elep = curr_ele();
-  curr_linkp = alloc_link();
-
-  //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->classp = curr_cdatp;
-  curr_linkp->set_idx = curr_cdatp->num_sets++;
-  //curr_linkp->ele_idx = curr_setp->num_ele++;
-
+  /* Do nothing because we already know the ref_id that
+     the odat needs for this element (in the quad_file) */
 }
 
 void
index 53b1d65..7983284 100644 (file)
@@ -109,22 +109,17 @@ struct vlink {
   char anim_name[32];
 };
 
-/* Olinks are links to odats */
-struct olink {
-  uint64_t ref_id;
-};
-
 union link_t {
-  struct olink olink;
   struct vlink vlink;
   struct svlink svlink;
 };
 
-/* From: Some odat ()To: Another odat (ref_id)*/
+/* 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;
 };
index 4c9aeea..234e941 100644 (file)
@@ -33,6 +33,7 @@ char* ttos(const char* str, int);
   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;
@@ -41,7 +42,7 @@ char* ttos(const char* str, int);
   tok = ref | val | name;
   segment = (tok . '_') %set_ts;
 
 main := segment* . tok;
main := segment* . tok $lerr(lex_error);
 }%%
 
 
@@ -55,7 +56,7 @@ int lexer_lex (const char* str)
   int  cs, tok_t, ntok = 0;
   printf ("Lexing: %s\n",str);
   p = ts = str;
-  pe = p + strlen(str) + 1;
+  pe = p + strlen(str);
   %%write init;
   %%write exec;
   printf ("Lexed %i tokens\n",ntok);