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 {
if(variable.datatype !in ArrayDatatypes
&& variable.type!=VarDeclType.MEMORY
&& variable.struct == null
&& variable.datatype != DataType.STR && variable.datatype!=DataType.STRUCT)
errors.err("invalid pointer-of operand type", addressOf.position)
}

View File

@ -1,21 +1,40 @@
%import textio
%import diskio
%zeropage basicsafe
%option no_sysinit
main {
sub start() {
txt.print("saving...")
diskio.delete(8, "data.bin")
if diskio.save(8, "data.bin", $0400, 40*25) {
txt.clear_screenchars('*')
txt.print("loading...")
uword size = diskio.load(8, "data.bin", $0400)
txt.print_uwhex(size, true)
txt.chrout('\n')
} else txt.print("io error\n")
ubyte[100] cargohold
struct SaveData {
ubyte galaxy
ubyte planet
ubyte cargo0
ubyte cargo1
ubyte cargo2
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()
}

View File

@ -107,7 +107,7 @@ trader {
ship.cash = savedata.cash
ship.Max_cargo = savedata.max_cargo
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)
; TODO CHECK IF GALAXY AND MARKET ARE OKAY AFTER LOAD
@ -120,7 +120,7 @@ trader {
savedata.cash = ship.cash
savedata.max_cargo = ship.Max_cargo
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...")
diskio.delete(8, Savegame)