]> git.mxchange.org Git - simgear.git/commitdiff
Fixes for bugs shaken out in the recent push: die properly for nil
authorandy <andy>
Tue, 30 Sep 2008 16:48:36 +0000 (16:48 +0000)
committerandy <andy>
Tue, 30 Sep 2008 16:48:36 +0000 (16:48 +0000)
indexes in slices.  Fix string conversion issue with bare "+" and "-".
Fix lexing of exponent expressions such that "1e" is not a number.

simgear/nasal/code.c
simgear/nasal/codegen.c
simgear/nasal/lex.c
simgear/nasal/string.c

index 11754b2045e56dd61b8a7d2aa3a5baa9511e83f0..cf48dc295770eeb9ad4e886eaecc45af6636c9a3 100644 (file)
@@ -503,7 +503,7 @@ static int vbound(naContext ctx, naRef v, naRef ir, int end)
 static void evalSlice(naContext ctx, naRef src, naRef dst, naRef idx)
 {
     if(!IS_VEC(src)) ERR(ctx, "cannot slice non-vector");
 static void evalSlice(naContext ctx, naRef src, naRef dst, naRef idx)
 {
     if(!IS_VEC(src)) ERR(ctx, "cannot slice non-vector");
-    naVec_append(dst, naVec_get(src, vbound(ctx, src, idx, 0)));
+    naVec_append(dst, naVec_get(src, checkVec(ctx, src, idx)));
 }
  
 static void evalSlice2(naContext ctx, naRef src, naRef dst,
 }
  
 static void evalSlice2(naContext ctx, naRef src, naRef dst,
index 76050031cdc231e89ccf599a526e6d57ea8d5359..d1c05ef6254808bc7abf6c20b9e4d5f7f6d44afd 100644 (file)
@@ -560,7 +560,7 @@ static void genAssign(struct Parser* p, struct Token* t)
 
 static void genSlice(struct Parser* p, struct Token* t)
 {
 
 static void genSlice(struct Parser* p, struct Token* t)
 {
-    if(!t) naParseError(p, "empty slice expression", -1);
+    if(!t || t->type==TOK_EMPTY) naParseError(p, "empty slice expression", -1);
     if(t->type == TOK_COLON) {
         if(LEFT(t))  genExpr(p, LEFT(t));  else emit(p, OP_PUSHNIL);
         if(RIGHT(t)) genExpr(p, RIGHT(t)); else emit(p, OP_PUSHNIL);
     if(t->type == TOK_COLON) {
         if(LEFT(t))  genExpr(p, LEFT(t));  else emit(p, OP_PUSHNIL);
         if(RIGHT(t)) genExpr(p, RIGHT(t)); else emit(p, OP_PUSHNIL);
index 432537467290fe64127ea4fb371896f24b83aecd..d3d525c316c52bfcf095b3a06a91d603871a9ef8 100644 (file)
@@ -256,20 +256,23 @@ static int lexHexLiteral(struct Parser* p, int index)
     return i;
 }
 
     return i;
 }
 
+#define ISNUM(c) ((c) >= '0' && (c) <= '9')
+
 static int lexNumLiteral(struct Parser* p, int index)
 {
     int len = p->len, i = index;
     unsigned char* buf = (unsigned char*)p->buf;
     double d;
 
 static int lexNumLiteral(struct Parser* p, int index)
 {
     int len = p->len, i = index;
     unsigned char* buf = (unsigned char*)p->buf;
     double d;
 
-    if(i+1<len && buf[i+1] == 'x') return lexHexLiteral(p, index+2);
+    if(buf[0] == '0' && i+1<len && buf[i+1] == 'x')
+        return lexHexLiteral(p, index+2);
 
     while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
     if(i<len && buf[i] == '.') {
         i++;
         while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
     }
 
     while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
     if(i<len && buf[i] == '.') {
         i++;
         while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
     }
-    if(i<len && (buf[i] == 'e' || buf[i] == 'E')) {
+    if(i+1<len && (buf[i] == 'e' || buf[i] == 'E') && ISNUM(buf[i+1])) {
         i++;
         if(i<len
            && (buf[i] == '-' || buf[i] == '+')
         i++;
         if(i<len
            && (buf[i] == '-' || buf[i] == '+')
@@ -333,7 +336,6 @@ static int tryLexemes(struct Parser* p, int index, int* lexemeOut)
     return best;
 }
 
     return best;
 }
 
-#define ISNUM(c) ((c) >= '0' && (c) <= '9')
 void naLex(struct Parser* p)
 {
     int i = 0;
 void naLex(struct Parser* p)
 {
     int i = 0;
index 65a29526c97ce0db31a08c87b0d48a08f6edf64c..4855054cddd24cc1983eb0d373056c64c7b66bf3 100644 (file)
@@ -185,9 +185,7 @@ static int tonum(unsigned char* s, int len, double* result)
     int i=0, fraclen=0;
     double sgn=1, val, frac=0, exp=0;
 
     int i=0, fraclen=0;
     double sgn=1, val, frac=0, exp=0;
 
-    // Special case, "." is not a number, even though "1." and ".0" are.
-    if(len == 1 && s[0] == '.')
-        return 0;
+    if(len == 1 && (*s=='.' || *s=='-' || *s=='+')) return 0;
 
     // Strip off the leading negative sign first, so we can correctly
     // parse things like -.xxx which would otherwise confuse
 
     // Strip off the leading negative sign first, so we can correctly
     // parse things like -.xxx which would otherwise confuse