fixed compiling errors for ir and parser
authorjordan@hack_attack <jordanlavatai@gmail.com>
Thu, 22 Sep 2016 19:29:40 +0000 (12:29 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Thu, 22 Sep 2016 19:29:40 +0000 (12:29 -0700)
src/apc/ir-mem.c [moved from src/apc/ir.c with 89% similarity]
src/apc/ir.h
src/apc/parser.y

similarity index 89%
rename from src/apc/ir.c
rename to src/apc/ir-mem.c
index 4a8486f..8b64101 100644 (file)
@@ -3,7 +3,7 @@
 #include <stdint.h> //uint64_t
 #include <string.h> //memmove
 #include <stdlib.h> //malloc
-#include "ir.h"
+#include <apc/ir.h>
 
 #define CURR_CDAT (*cdat_stackp)
 #define CURR_SET set_list[CURR_CDAT->num_sets]
 #define PREV_VDAT (vdat_buf[num_vdats-1])
 #define CURR_MODEL model_list[CURR_VDAT->num_models]
 #define CURR_LINK (link_buf[num_links])
+#define CURR_POST (post_buf[num_posts])
 
+int num_cdats = 0;
+int curr_max_cdats = PTRS_IN_PAGE;
+
+int num_odats = 0;
+int curr_max_odats = PTRS_IN_PAGE;
+
+
+int num_vdats = 0;
+int curr_max_vdats = PTRS_IN_PAGE;
+
+int num_refs = 0;
+int curr_max_refs = PTRS_IN_PAGE;
+uint64_t ss_ref_id = 0x00FFFFFF; /* system space for ref_ids */
+
+int num_links = 0;
+int curr_max_links = PTRS_IN_PAGE;
+
+int num_posts = 0;
+int curr_max_posts = PTRS_IN_PAGE;
 
 void
 ir_init()
@@ -46,6 +66,10 @@ ir_init()
   /* Init first link */
   if( (CURR_LINK = (struct link*) malloc(sizeof(struct link))) == NULL)
     perror("malloc first link failed");
+
+  /* Init first post */
+  if( (CURR_POST = (struct ref*) malloc(sizeof(struct ref))) == NULL)
+    perror("malloc first post failed");
 }
 
 //TODO: FREE MEMORY!
@@ -99,6 +123,22 @@ pop_cdat()
   cdat_stackp--;
 }
 
+void
+inc_posts()
+{
+  num_posts++;
+  if(num_posts >= curr_max_posts)
+    {
+      if( (realloc((void*) post_buf, PTRS_IN_PAGE * 4)) == NULL)
+        perror("realloc post_buf failed");
+      curr_max_posts += PTRS_IN_PAGE;
+    }
+  if( (CURR_POST = (struct ref*) malloc(sizeof (struct ref))) == NULL)
+    {
+      perror("malloc post failed");
+    }
+
+}
 void
 inc_odat()
 {
@@ -155,7 +195,8 @@ inc_ref()
 
   if(num_refs % 16 == 0)
     {
-      posts[num_posts++] = *CURR_REF;
+      CURR_POST = CURR_REF;
+      inc_posts();
     }
 
   num_refs++;
@@ -344,7 +385,7 @@ insert_ele()
 }
 
 void
-insert_framesheets(char direction, char* name, uint64_t ref_id, int height , int width, int num_frames)
+insert_framesheet(char direction, char* name, uint64_t ref_id, int height , int width, int num_frames)
 {
   CURR_VDAT->CURR_MODEL.spritesheet[(int)direction].height = height;
   CURR_VDAT->CURR_MODEL.spritesheet[(int)direction].width = width;
index d8a7ec3..25e5788 100644 (file)
@@ -104,8 +104,6 @@ struct cdat {
 /* 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.           */
 struct cdat* cdat_buf[PTRS_IN_PAGE];
-int num_cdats = 0;
-int curr_max_cdats = PTRS_IN_PAGE;
 
 /* 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
@@ -138,14 +136,9 @@ struct ref {
 /* Like the cdat_buf, ref_buf stores pointers to refs and can
    increase in size */
 struct ref* ref_buf[PTRS_IN_PAGE];
-int num_refs = 0;
-int curr_max_refs = PTRS_IN_PAGE;
-uint64_t ss_ref_id = 0x00FFFFFF; /* system space for ref_ids */
-
 
 /* posts for ref_buf */
-struct ref posts[MAX_POSTS];
-int num_posts;
+struct ref* post_buf[PTRS_IN_PAGE];
 
 /* Links: At parse time, a set/ele can include a link in their
    grammar representation instead of the actual data and this signifies
@@ -197,8 +190,6 @@ struct link {
    This does not include quad refs, because
    those are already known to need to be resolved */
 struct link* link_buf[PTRS_IN_PAGE];
-int num_links = 0;
-int curr_max_links = PTRS_IN_PAGE;
 
 
 /* Odats: Odats consist of the object data necessary for
@@ -232,8 +223,6 @@ struct odat {
 
 /* Populated and allocated same way as other bufs */
 struct odat* odat_buf[PTRS_IN_PAGE];
-int curr_max_odats = PTRS_IN_PAGE;
-int num_odats = 0;
 
 /* A framesheet is a grouping of animation frames in
    a single direction (N,W,S,E) */
@@ -265,8 +254,6 @@ struct vdat {
 
 
 struct vdat* vdat_buf[PTRS_IN_PAGE];
-int curr_max_vdats = PTRS_IN_PAGE;
-int num_vdats = 0;
 
 /* The initalization function of the IR. Mallocs the
    first c/v/odat and the first links and refs and
index e4b1bb5..07bc28b 100644 (file)
 %}
 %define parse.error verbose
 %define lr.type ielr
-%define api.value.type union
-//operators
+
+%union {
+  uint64_t ref;
+  int NUM;
+  char *str;
+  void *voidp;
+
+}
+
+ //operators
 %token         CLOPEN   // /
 %token         CLCLOSE  // \
 %token         SOPEN
 %token         FS
 %token         ELE
 //nonterminal types
-%type <uint64_t> olink
-%type <uint64_t> ele_svlink
-%type <uint64_t> set_svlink
+%type <ref> olink
+%type <ref> ele_svlink
+%type <ref> set_svlink
 //terminals
-%token <int> NUM
-%token <char*> STR
-%token <int> SS
-%token <char*> NAME
-%token <uint64_t> REF
-%token <int> SSD
-%token <void*> FPTR
-%token <int> WIDTH
-%token <int> HEIGHT
-%token <int> NUM_PTRS
+%token <NUM> NUM
+%token <str> STR
+%token <NUM> SS
+%token <str> NAME
+%token <ref> REF
+%token <NUM> SSD
+%token <voidp> FPTR
+%token <NUM> WIDTH
+%token <NUM> HEIGHT
+%token <NUM> NUM_PTRS
 //precedence
 %precedence LP
 %precedence MP