diff --git a/pcomp/emit.pas b/pcomp/emit.pas index 2ede4f0..3c908c4 100644 --- a/pcomp/emit.pas +++ b/pcomp/emit.pas @@ -1250,7 +1250,7 @@ begin (* nothing to do *) end else - if amount <= MaxTinyOffset then + if (amount > 0) and (amount <= MaxTinyOffset) then emitIns2Int('INC', amount) else begin @@ -1266,7 +1266,7 @@ begin (* nothing to do *) end else - if amount <= MaxTinyOffset then + if (amount > 0) and (amount <= MaxTinyOffset) then emitIns2Int('DEC', amount) else begin diff --git a/pcomp/pcomp.pas b/pcomp/pcomp.pas index c2b8a2f..d7be8a5 100644 --- a/pcomp/pcomp.pas +++ b/pcomp/pcomp.pas @@ -2456,10 +2456,7 @@ begin begin digits := curToken.tokenText; if matchTokenOrNot(MinusToken) then - begin - readNextToken; digits := digits + curToken.tokenText; - end; parseInteger := integerFromString(digits); end; readNextToken; @@ -2812,6 +2809,8 @@ begin if checkToken(CommaToken) then begin + (* TODO: handle comma syntax for indexing a char + from an array of strings *) if elType.baseType <> ArrayType then errorExit2('invalid array subscript for', name) end; @@ -3231,10 +3230,22 @@ begin readNextToken; end; +(* Handle an array range part. Very similar to parseInteger + but additionally handles Boolean, Enum and Char types which + can be used for array indices *) procedure getRangePart(var value:integer; var typeReturn: TypeSpec); var cnst: ConstRef; + negate:boolean; + digits: string[12]; begin setBaseType(typeReturn, NoType); + negate := false; + + if checkToken(MinusToken) then + begin + negate := true; + readNextToken; + end; if checkToken(IdentToken) then begin @@ -3268,7 +3279,11 @@ begin else begin setBaseType(typeReturn, IntegerType); - value := parseInteger; + digits := curToken.tokenText; + if negate then + insert('-', digits, 1); + value := integerFromString(digits); + readNextToken; end; end; @@ -3433,9 +3448,9 @@ begin if savedType.baseType = NoType then savedType := elementType; emitLoadConstantInt(cnst^.intValue); + readNextToken; end; emitAddToSet; - readNextToken; end else if checkToken(NumberToken) then begin @@ -3999,6 +4014,8 @@ begin begin readNextToken; length := parseInteger; + if length < 1 then + errorExit2('invalid string length', ''); matchToken(RBracketToken); end; typSpec.size := getStringMemSize(length);