relaxed symbol shadowing

This commit is contained in:
Irmen de Jong 2019-08-04 18:40:50 +02:00
parent cc1fc869cf
commit f29ec3b4e1
4 changed files with 36 additions and 17 deletions

View File

@ -1063,7 +1063,7 @@ _mod lda $ffff ; modified
sub setcc (ubyte column, ubyte row, ubyte char, ubyte color) {
; ---- set char+color at the given position on the screen
%asm {{
lda setcc_row
lda row
asl a
tay
lda setchr._screenrows+1,y
@ -1072,15 +1072,15 @@ sub setcc (ubyte column, ubyte row, ubyte char, ubyte color) {
sta _colormod+2
lda setchr._screenrows,y
clc
adc setcc_column
adc column
sta _charmod+1
sta _colormod+1
bcc +
inc _charmod+2
inc _colormod+2
+ lda setcc_char
+ lda char
_charmod sta $ffff ; modified
lda setcc_color
lda color
_colormod sta $ffff ; modified
rts
}}

View File

@ -67,8 +67,6 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
// the builtin functions can't be redefined
checkResult.add(NameError("builtin function cannot be redefined", decl.position))
if(decl.name in AssemblyProgram.reservedNames)
checkResult.add(NameError("can't use a symbol name reserved by the assembler program", decl.position))
if(decl.name in AssemblyProgram.opcodeNames)
checkResult.add(NameError("can't use a cpu opcode name as a symbol", decl.position))
@ -106,7 +104,9 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
}
override fun visit(subroutine: Subroutine): Statement {
if(subroutine.name in BuiltinFunctions) {
if(subroutine.name in AssemblyProgram.opcodeNames) {
checkResult.add(NameError("can't use a cpu opcode name as a symbol", subroutine.position))
} else if(subroutine.name in BuiltinFunctions) {
// the builtin functions can't be redefined
checkResult.add(NameError("builtin function cannot be redefined", subroutine.position))
} else {
@ -162,6 +162,9 @@ internal class AstIdentifiersChecker(private val program: Program) : IAstModifyi
}
override fun visit(label: Label): Statement {
if(label.name in AssemblyProgram.opcodeNames)
checkResult.add(NameError("can't use a cpu opcode name as a symbol", label.position))
if(label.name in BuiltinFunctions) {
// the builtin functions can't be redefined
checkResult.add(NameError("builtin function cannot be redefined", label.position))

View File

@ -10,12 +10,7 @@ class AssemblyProgram(val name: String) {
private val viceMonListFile = "$name.vice-mon-list"
companion object {
// reserved by the 64tass assembler (on top of prog8"s own reserved names)
val reservedNames = setOf("bits", "bool", "bytes", "code", "dict", "gap", "int", "list", "tuple", "type",
"trunc", " frac", "cbrt", "log10", "log", "exp", "pow", "asin", "sinh", "acos", "cosh", "tanh", "hypot",
"atan2", "sign", "binary", "format", "random", "range", "repr", "size", "sort")
// 6502 opcodes (including aliases and illegal opcodes), these cannot be used as variable names either
// 6502 opcodes (including aliases and illegal opcodes), these cannot be used as variable or label names
val opcodeNames = setOf("adc", "ahx", "alr", "anc", "and", "ane", "arr", "asl", "asr", "axs", "bcc", "bcs",
"beq", "bge", "bit", "blt", "bmi", "bne", "bpl", "brk", "bvc", "bvs", "clc",
"cld", "cli", "clv", "cmp", "cpx", "cpy", "dcm", "dcp", "dec", "dex", "dey",
@ -30,8 +25,9 @@ class AssemblyProgram(val name: String) {
fun assemble(options: CompilationOptions) {
// add "-Wlong-branch" to see warnings about conversion of branch instructions to jumps
val command = mutableListOf("64tass", "--ascii", "--case-sensitive", "--long-branch", "-Wall", "-Wno-strict-bool",
"-Werror", "-Wno-error=long-branch", "--dump-labels", "--vice-labels", "-l", viceMonListFile, "--no-monitor")
val command = mutableListOf("64tass", "--ascii", "--case-sensitive", "--long-branch",
"-Wall", "-Wno-strict-bool", "-Wno-shadow", "-Werror", "-Wno-error=long-branch",
"--dump-labels", "--vice-labels", "-l", viceMonListFile, "--no-monitor")
val outFile = when(options.output) {
OutputType.PRG -> {

View File

@ -6,7 +6,27 @@
main {
sub start() {
memset(c64.Screen, 40, 1)
memset(c64.Screen+40, 80, 2)
ubyte x=3
ubyte y=2
ubyte a=1
ubyte s=0
float repr=4.4
;memset(c64.Screen, 40, 1)
;memset(c64.Screen+40, 80, 2)
A=x
A=y
Y=a
A=s
}
sub foo() {
x:
s:
y:
a:
A=3
}
}