]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - code.c
block and value codegen protos
[xonotic/gmqcc.git] / code.c
diff --git a/code.c b/code.c
index 66dc9517a68f008abf498748c1f9e0728246bd70..80d6c3b33fb41616d188f35b1bf2eda990e57d45 100644 (file)
--- a/code.c
+++ b/code.c
@@ -28,8 +28,11 @@ typedef struct {
 } prog_section;
 
 typedef struct {
-    uint32_t     version;      /* Program version (6)     */
-    uint32_t     crc16;        /* What is this?           */
+    uint16_t     version;      /* Program version (6)     */
+    uint16_t     flags;        /* see propsal.txt         */
+    uint16_t     crc16;        /* What is this?           */
+    uint16_t     skip;         /* see propsal.txt         */
+    
     prog_section statements;   /* prog_section_statement  */
     prog_section defs;         /* prog_section_def        */
     prog_section fields;       /* prog_section_field      */
@@ -80,16 +83,11 @@ VECTOR_MAKE(prog_section_function,  code_functions );
 VECTOR_MAKE(int,                    code_globals   );
 VECTOR_MAKE(char,                   code_chars     );
 
-int code_strings_add(const char *src) {
-    size_t size = strlen(src);
-    size_t iter = 0;
-    while (iter < size)
-        code_chars_add(src[iter++]);
-    code_chars_add('\0');
-    return code_chars_elements;
-}
-
 void code_init() {
+    /* omit creation of null code */
+    if (opts_omit_nullcode)
+        return;
+        
     /*
      * The way progs.dat is suppose to work is odd, there needs to be
      * some null (empty) statements, functions, and 28 globals
@@ -106,13 +104,13 @@ void code_init() {
 }
 
 void code_test() {    
-    code_strings_add("m_init");
-    code_strings_add("print");
-    code_strings_add("hello world\n");
-    code_strings_add("m_keydown");
-    code_strings_add("m_draw");
-    code_strings_add("m_toggle");
-    code_strings_add("m_shutdown");
+    code_chars_put("m_init",        0x6);
+    code_chars_put("print",         0x5);
+    code_chars_put("hello world\n", 0xC);
+    code_chars_put("m_keydown",     0x9);
+    code_chars_put("m_draw",        0x6);
+    code_chars_put("m_toggle",      0x8);
+    code_chars_put("m_shutdown",    0xA);
     
     code_globals_add(1);  /* m_init */
     code_globals_add(2);  /* print  */
@@ -137,6 +135,13 @@ void code_test() {
 
 void code_write() {
     prog_header code_header={0};
+
+    /* see proposal.txt */
+    if (opts_omit_nullcode) {
+        code_header.skip   = 28;
+        code_header.flags  = 1;
+    }
+    
     code_header.version    = 6;
     code_header.crc16      = 0; /* TODO: */
     code_header.statements = (prog_section){sizeof(prog_header), code_statements_elements };
@@ -150,7 +155,7 @@ void code_write() {
     if (opts_darkplaces_stringtablebug) {
         util_debug("GEN", "Patching stringtable for -fdarkplaces-stringtablebug\n");
 
-        /* >= + padd */
+        /* >= + P */
         code_chars_add('\0'); /* > */
         code_chars_add('\0'); /* = */
         code_chars_add('\0'); /* P */