Fixes for bugs shaken out in the recent push: die properly for nil
indexes in slices. Fix string conversion issue with bare "+" and "-". Fix lexing of exponent expressions such that "1e" is not a number.
This commit is contained in:
@@ -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)
|
static void evalSlice(naContext ctx, naRef src, naRef dst, naRef idx)
|
||||||
{
|
{
|
||||||
if(!IS_VEC(src)) ERR(ctx, "cannot slice non-vector");
|
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,
|
||||||
|
|||||||
@@ -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(t->type == TOK_COLON) {
|
||||||
if(LEFT(t)) genExpr(p, LEFT(t)); else emit(p, OP_PUSHNIL);
|
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(RIGHT(t)) genExpr(p, RIGHT(t)); else emit(p, OP_PUSHNIL);
|
||||||
|
|||||||
+5
-3
@@ -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)
|
static int lexNumLiteral(struct Parser* p, int index)
|
||||||
{
|
{
|
||||||
int len = p->len, i = index;
|
int len = p->len, i = index;
|
||||||
unsigned char* buf = (unsigned char*)p->buf;
|
unsigned char* buf = (unsigned char*)p->buf;
|
||||||
double d;
|
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++;
|
while(i<len && buf[i] >= '0' && buf[i] <= '9') i++;
|
||||||
if(i<len && buf[i] == '.') {
|
if(i<len && buf[i] == '.') {
|
||||||
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] == 'e' || buf[i] == 'E')) {
|
if(i+1<len && (buf[i] == 'e' || buf[i] == 'E') && ISNUM(buf[i+1])) {
|
||||||
i++;
|
i++;
|
||||||
if(i<len
|
if(i<len
|
||||||
&& (buf[i] == '-' || buf[i] == '+')
|
&& (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)
|
void naLex(struct Parser* p)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|||||||
@@ -185,9 +185,7 @@ static int tonum(unsigned char* s, int len, double* result)
|
|||||||
int i=0, fraclen=0;
|
int i=0, fraclen=0;
|
||||||
double sgn=1, val, frac=0, exp=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=='.' || *s=='-' || *s=='+')) return 0;
|
||||||
if(len == 1 && s[0] == '.')
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
// Strip off the leading negative sign first, so we can correctly
|
// Strip off the leading negative sign first, so we can correctly
|
||||||
// parse things like -.xxx which would otherwise confuse
|
// parse things like -.xxx which would otherwise confuse
|
||||||
|
|||||||
Reference in New Issue
Block a user