fix invalid address-of error when taking address of struct variable

This commit is contained in:
Irmen de Jong 2020-10-15 20:14:17 +02:00
parent 095c8b2309
commit cd825e386d
3 changed files with 32 additions and 12 deletions

View File

@ -464,6 +464,7 @@ internal class AstChecker(private val program: Program,
else { else {
if(variable.datatype !in ArrayDatatypes if(variable.datatype !in ArrayDatatypes
&& variable.type!=VarDeclType.MEMORY && variable.type!=VarDeclType.MEMORY
&& variable.struct == null
&& variable.datatype != DataType.STR && variable.datatype!=DataType.STRUCT) && variable.datatype != DataType.STR && variable.datatype!=DataType.STRUCT)
errors.err("invalid pointer-of operand type", addressOf.position) errors.err("invalid pointer-of operand type", addressOf.position)
} }

View File

@ -1,21 +1,40 @@
%import textio %import textio
%import diskio %import diskio
%zeropage basicsafe %zeropage basicsafe
%option no_sysinit
main { main {
sub start() { sub start() {
txt.print("saving...") ubyte[100] cargohold
diskio.delete(8, "data.bin")
if diskio.save(8, "data.bin", $0400, 40*25) { struct SaveData {
txt.clear_screenchars('*') ubyte galaxy
txt.print("loading...") ubyte planet
uword size = diskio.load(8, "data.bin", $0400) ubyte cargo0
txt.print_uwhex(size, true) ubyte cargo1
txt.chrout('\n') ubyte cargo2
} else txt.print("io error\n") ubyte cargo3
ubyte cargo4
ubyte cargo5
ubyte cargo6
ubyte cargo7
ubyte cargo8
ubyte cargo9
ubyte cargo10
ubyte cargo11
ubyte cargo12
ubyte cargo13
ubyte cargo14
ubyte cargo15
ubyte cargo16
uword cash
ubyte max_cargo
ubyte fuel
}
SaveData savedata
memcopy(&savedata.cargo0, cargohold, len(cargohold)) ; TODO fix compiler error about pointer
testX() testX()
} }

View File

@ -107,7 +107,7 @@ trader {
ship.cash = savedata.cash ship.cash = savedata.cash
ship.Max_cargo = savedata.max_cargo ship.Max_cargo = savedata.max_cargo
ship.fuel = savedata.fuel ship.fuel = savedata.fuel
;memcopy(&savedata.cargo0, ship.cargohold, len(ship.cargohold)) ; TODO fix compiler error about pointer memcopy(&savedata.cargo0, ship.cargohold, len(ship.cargohold))
galaxy.travel_to(savedata.galaxy, savedata.planet) galaxy.travel_to(savedata.galaxy, savedata.planet)
; TODO CHECK IF GALAXY AND MARKET ARE OKAY AFTER LOAD ; TODO CHECK IF GALAXY AND MARKET ARE OKAY AFTER LOAD
@ -120,7 +120,7 @@ trader {
savedata.cash = ship.cash savedata.cash = ship.cash
savedata.max_cargo = ship.Max_cargo savedata.max_cargo = ship.Max_cargo
savedata.fuel = ship.fuel savedata.fuel = ship.fuel
;memcopy(ship.cargohold, &savedata.cargo0, len(ship.cargohold)) ; TODO fix compiler error about pointer memcopy(ship.cargohold, &savedata.cargo0, len(ship.cargohold))
txt.print("\nSaving universe...") txt.print("\nSaving universe...")
diskio.delete(8, Savegame) diskio.delete(8, Savegame)