Added sensible handling for byte iterators
This commit is contained in:
parent
4f51572477
commit
315be292bf
1 changed files with 21 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package commands
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"c65gm/internal/compiler"
|
"c65gm/internal/compiler"
|
||||||
|
|
@ -106,6 +107,26 @@ func (c *ForCommand) Interpret(line preproc.Line, ctx *compiler.CompilerContext)
|
||||||
IsVar: endIsVar,
|
IsVar: endIsVar,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if c.varKind == compiler.KindByte {
|
||||||
|
// Error on literal out of range
|
||||||
|
if !c.startOp.IsVar && c.startOp.Value > 255 {
|
||||||
|
return fmt.Errorf("FOR: BYTE variable cannot start at literal %d (max 255)", c.startOp.Value)
|
||||||
|
}
|
||||||
|
if !c.endOp.IsVar && c.endOp.Value > 255 {
|
||||||
|
return fmt.Errorf("FOR: BYTE variable cannot loop to literal %d (max 255)", c.endOp.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warn on variable type mismatch
|
||||||
|
if c.startOp.IsVar && c.startOp.VarKind == compiler.KindWord {
|
||||||
|
_, _ = fmt.Fprintf(os.Stderr, "%s:%d: warning: BYTE loop variable with WORD start value truncates to low byte\n",
|
||||||
|
line.Filename, line.LineNo)
|
||||||
|
}
|
||||||
|
if c.endOp.IsVar && c.endOp.VarKind == compiler.KindWord {
|
||||||
|
_, _ = fmt.Fprintf(os.Stderr, "%s:%d: warning: BYTE loop variable with WORD end value may cause infinite loop\n",
|
||||||
|
line.Filename, line.LineNo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse optional STEP
|
// Parse optional STEP
|
||||||
if len(params) == 8 {
|
if len(params) == 8 {
|
||||||
if strings.ToUpper(params[6]) != "STEP" {
|
if strings.ToUpper(params[6]) != "STEP" {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue