]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
vector parsing for assembly
authorDale Weiler <killfieldengine@gmail.com>
Sat, 28 Apr 2012 11:27:03 +0000 (07:27 -0400)
committerDale Weiler <killfieldengine@gmail.com>
Sat, 28 Apr 2012 11:27:03 +0000 (07:27 -0400)
asm.c
data/test.qs

diff --git a/asm.c b/asm.c
index 0b48ca92a144e230e7dc8f1f7ef1c51e1dbbd017..a40ed94af5b66ca041e06824529005d7a92f7397 100644 (file)
--- a/asm.c
+++ b/asm.c
@@ -87,9 +87,36 @@ static inline bool asm_parse_type(const char *skip, size_t line, asm_state *stat
     /* TODO: determine if constant, global, or local */
     switch (*skip) {
         /* VECTOR */ case 'V': {
+            float val1;
+            float val2;
+            float val3;
+            
             const char *find = skip + 7;
             while (*find == ' ' || *find == '\t') find++;
-            printf("found VECTOR %s\n", find);
+
+            /*
+             * Parse all three elements of the vector.  This will only
+             * pass the first try if we hit a constant, otherwise it's
+             * a global.
+             */
+            #define PARSE_ELEMENT(X,Y,Z)                    \
+                if (isdigit(*X)  || *X == '-'||*X == '+') { \
+                    bool negated = (*X == '-');             \
+                    if  (negated || *X == '+')   { X++; }   \
+                    Y = (negated)?-atof(X):atof(X);         \
+                    X = strchr(X, ',');                     \
+                    Z                                       \
+                }
+
+            PARSE_ELEMENT(find, val1, { if(find) { find+=3; }});
+            PARSE_ELEMENT(find, val2, { if(find) { find+=2; }});
+            PARSE_ELEMENT(find, val3, { if(find) { find+=1; }});
+            #undef PARSE_ELEMENT
+
+            printf("X:[0] = %f\n", val1);
+            printf("Y:[1] = %f\n", val2);
+            printf("Z:[2] = %f\n", val3);
+            
             break;
         }
         /* ENTITY */ case 'E': {
index 14d3e26247731443229af5d7b30f0fe708fecf2e..b087e4f8449734e7bd637ac690de6206e4138333 100644 (file)
@@ -83,6 +83,6 @@ FUNCTION: findfloat,      $98
 FUNCTION: checkextension, $99
 
 ; constants test
-VECTOR: 1, 2, 3
+VECTOR: -1,  +2, 38865.444
 FLOAT:  1
 STRING: "hello world"