ir files compile, still a wip
authorjordan@hack_attack <jordanlavatai@gmail.com>
Tue, 30 Aug 2016 19:19:45 +0000 (12:19 -0700)
committerjordan@hack_attack <jordanlavatai@gmail.com>
Tue, 30 Aug 2016 19:19:45 +0000 (12:19 -0700)
src/apc/ir.c
src/apc/ir.h
src/apc/parser.y

index ffc1020..c5c4125 100644 (file)
@@ -1,29 +1,31 @@
 #include <errno.h>
-#include <ir.h> 
+#include <stdio.h>
+#include <string.h>
+#include <apc/ir.h>
 
-//#define CURR_ODAT (OB[obi])
-//#define CURR_VDAT (VB[vbi])
-//#define CURR_CDAT (CB[cbi])
+#define CURR_ODAT (odat_buf[obi])
+#define CURR_VDAT (vdat_buf[vbi])
+#define CURR_CDAT (cdat_buf[cbi]) //more like the base cdat
 
 //TODO: label and vdat_id
 void
 insert_set()
 {
-  cdat_buf[cbi].set_list[set_index].odat_id = obi;
-  cdat_buf[cbi].set_list[set_index].parent_id =//from lexer
+  CURR_CDAT.set_list[CURR_CDAT.set_index].odat_id = obi;
+  CURR_CDAT.set_list[CURR_CDAT.set_index].parent_id = 0;//from lexer
   //TODO: add ele_stack is created in element_list
   //TODO: add set to odat_buf
 
 }
 
-#define CURR_QUAD (odat_buf[obi].ref_list[ref_index])
+#define CURR_QUAD (CURR_ODAT.ref_list[CURR_ODAT.ref_index])
 void
 insert_ref(int x, int y, int z, int ref)
 {
   CURR_QUAD.x = x;
   CURR_QUAD.y = y;
   CURR_QUAD.z = z;
-  CURR_QUAD.ref = ref;
+  CURR_QUAD.objref = ref;
 }
 
 
@@ -33,53 +35,42 @@ insert_ele(char* label, int vdat_id)
 {
 
 
-  odat_buf[obi].label = label;
-  odat_buf[obi].vdat_id = vdat_id;
+  memmove(CURR_ODAT.label,label,32);
+  CURR_ODAT.vdat_id = vdat_id;
   //TODO: check set_obi to see if set_map_data exists
   //comes from e
-  odat_buf[obi].num_ref = odat_buf[set_obi].num_ref;
-  odat_buf[obi].ref_list = odat_buf[set_obi].ref_list;
-  odat_buf[obi].class_id = cbi;
-
-  if(IS_SUBCLASS())
-    {
-      cdat_buf[cbi].subclass_list[subclass_index].set_list[set_index].ele_list[ele_index].odat_id = obi;
-      cdat_buf[cbi].subclass_list[subclass_index].set_list[set_index].ele_list[ele_index].parent_id = cdat_buf[cbi].subclass_list[subclass_index].set_index;
-    }
-  else
-    {
-      cdat_buf[cbi].set_list[set_index].ele_list[ele_index].odat_id = obi;
-      cdat_buf[cbi].set_list[set_index].ele_list[ele_index].parent_id = cdat_buf[cbi].set_index;
-    }
+  //CURR_ODAT.num_ref = //comes from its set
+  //CURR_ODAT.ref_list = //comes from its set
+  //CURR_ODAT.class_id = //comes from lexer?
 
   obi++;
 }
 
 
 /* fd could be a directory entry */
-int
+void
 insert_fdat(char* label, char direction, int fd)
 {
-  vdat_buf[vbi].model_list[vdat_buf[vbi].len].label = label;
-  vdat_buf[vbi].model_list[vdat_buf[vbi].len].fdat_id[(int)direction] = fd;
+  memmove(CURR_VDAT.model_list[CURR_VDAT.num_models].label,label,32);
+  CURR_VDAT.model_list[CURR_VDAT.num_models].fdat_id[(int)direction] = fd;
 }
 
 void
 condense()
 {
-  FILE* vp, op, cp;
+  FILE *vp, *op, *cp;
   int v, m;
   int num_models;
 
-  vp = fopen("vdat_output", w+);
+  vp = fopen("vdat_output", "w+");
   if(!vp)
     perror("vdat_output failed to open\n");
 
-  op = fopen("odat_output", w+);
+  op = fopen("odat_output", "w+");
   if(!op)
     perror("odat_output failed to open\n");
 
-  cp = fopen("cdat_output", w+);
+  cp = fopen("cdat_output", "w+");
   if(!cp)
     perror("cdat_output failed to open\n");
 
@@ -111,26 +102,26 @@ inc_cbi()
 void
 set_class_label(char* label)
 {
-  cdat_buf[cbi].label = $1;
+  memmove(CURR_CDAT.label,label,32);
 }
 
 void
 inc_subclass_idx()
 {
-  cdat_buf[cbi].subclass_index++;
+  CURR_CDAT.subclass_index++;
 }
 
 void
 inc_set_index()
 {
-  odat_buf[cbi].set_index++;
+  cdat_buf[cbi].set_index++;
 }
 
 void
 inc_ref()
 {
-  odat_buf[obi].ref_index++;
-  odat_buf[obi].num_ref++;
+  CURR_ODAT.ref_index++;
+  CURR_ODAT.num_ref++;
 }
 
 //TODO: This needs to be changed to account for
@@ -138,11 +129,12 @@ inc_ref()
 void
 inc_ele()
 {
-  cdat_buf[cbi].set_stack[stack_index].num_ele++;
+  CURR_CDAT.set_list[CURR_CDAT.set_index].num_ele++;
+  vbi++;
 }
 
 void
 inc_models()
 {
-  vdat_buf[vbi].num_models++;
+  CURR_VDAT.num_models++;
 }
index 9b8f4ab..ef54476 100644 (file)
@@ -9,10 +9,6 @@
 #define MAX_MODELS 256
 
 
-//indexes for buffers
-int cbi = 0;
-int vbi = 0;
-int obi = 0;
 
 struct ref {
   int x, y, z, objref;
@@ -23,7 +19,6 @@ struct ele {
   int parent_id;//offset into class set_stack
 };
 
-//TODO: Add jump table
 struct set {
   int odat_id;
   int parent_id;//offset into CB
@@ -40,12 +35,12 @@ struct model {
   int fdat_id[8];
 };
 
-//TODO: Do vdats need labels?
 struct vdat {
+  char label[32];
   int num_models;
   int msi; //model_stack_index
   struct model model_list[MAX_MODELS];
-} vdat_buf[BUF_SIZE];
+};
 
 struct cdat {
   char label[32];
@@ -55,7 +50,7 @@ struct cdat {
   int set_index;
   struct cdat* subclass_list[MAX_SUBCLASSES];
   struct set set_list[MAX_SETS];
-} cdat_buf[BUF_SIZE];
+};
 
 //Element or a set
 struct odat {
@@ -65,8 +60,23 @@ struct odat {
   int num_ref;
   int ref_index;
   struct ref ref_list[MAX_REFS];
-} odat_buf[BUF_SIZE];
+};
+
 
+struct cdat cdat_buf[BUF_SIZE];
+struct odat odat_buf[BUF_SIZE];
+struct vdat vdat_buf[BUF_SIZE];
+
+//indexes for buffers
+int cbi = 0;
+int vbi = 0;
+int obi = 0;
+
+void
+insert_set(void);
+
+void
+insert_ref(int, int, int, int);
 
 void
 inc_cbi(void);
index f42ea7b..e795d31 100644 (file)
@@ -4,7 +4,7 @@
   #include <string.h>
   #include <dirent.h>
   #include <png.h>
-  #include "ir.h"
+  #include <apc/ir.h>
 
   extern int lexer_init();
   extern int lexer();