tweak address-of types

This commit is contained in:
Irmen de Jong
2025-05-16 16:49:23 +02:00
parent 4f0839f27e
commit 0e64a22910
4 changed files with 24 additions and 12 deletions

View File

@@ -171,20 +171,22 @@ class DataType private constructor(val base: BaseDataType, val sub: BaseDataType
if (isUndefined)
return if(msb) pointer(BaseDataType.UBYTE) else UWORD
else {
// if(isBasic)
// return pointer(base) // TODO breaks 6502 codegen atm
// if(isString) // TODO pointer to string == ptr to ubyte? breaks 6502 codegen atm.
if(isBasic)
return pointer(base)
// if(isString) // TODO return this typed pointer instead, but that breaks 6502 codegen now:
// return pointer(BaseDataType.UBYTE)
// if(isArray) // TODO pointer to array == ptr to element type? breaks 6502 codegen atm.
// return pointer(elementType().base)
if (subType != null)
return pointerToType(subType!!)
else if (isArray) {
if (isArray) {
if (msb || isSplitWordArray)
return pointer(BaseDataType.UBYTE)
return UWORD
} else
return UWORD // TODO("address-of type for $this")
// TODO return this typed pointer instead, but that breaks 6502 codegen now:
// val elementDt = elementType()
// require(elementDt.isBasic)
// return pointer(elementDt.base)
}
return UWORD
}
}

View File

@@ -99,6 +99,10 @@ internal class VerifyFunctionArgTypes(val program: Program, val options: Compila
TODO("array vs element pointer check")
}
// if expected is UWORD and actual is any pointer, we allow it (uword is untyped pointer, for backwards compatibility)
if(paramDt.isUnsignedWord && argDt.isPointer)
return true
return false
}

View File

@@ -48,12 +48,12 @@ STRUCTS and TYPED POINTERS
- DONE: pointer[0] should be replaced with @(pointer) if pointer is ^^ubyte, so these are now all identical: ptr[0], ptr^^, @(ptr) if ptr is ^^ubyte
- DONE: STR should be asssignment compatible with UBYTE^^ but local scoped STR should still be accessed directly using LDA str,Y instead of through the pointer, like arrays.
- fix actual _msb/_lsb storage of the split-words pointer-arrays
- rather than str or uword parameter types for routines with a string argument, use ^^str (or ^^ubyte maybe? these are more or less identical..?)
- allow memory-mapped structs? Something like &Sprite sprite0 = $9000 basically behaves identical to a typed pointer, but the address is immutable as usual
- make typeForAddressOf() be even more specific about the typed pointers it returns for the address-of operator. + unit test. Needs fixes in 6502 codegen too though... (also recheck passing STR and ARRAY types to subroutines)
- fixing the pointer dereferencing issues (cursed hybrid beween IdentifierReference, PtrDereferece and PtrIndexedDereference) may require getting rid of scoped identifiers altogether and treat '.' as a "scope or pointer following operator"
- (later, nasty parser problem:) support chaining pointer dereference on function calls that return a pointer. (type checking now fails on stuff like func().field and func().next.field)
- allow memory-mapped structs? Something like &Sprite sprite0 = $9000 basically behaves identical to a typed pointer, but the address is immutable as usual
- rather than str or uword parameter types for routines with a string argument, use ^^str (or ^^ubyte maybe? these are more or less identical..?)
- add more unit tests for all changes (pointers and structs)
- add unit tests for all changes (pointers and structs)
- 6502 codegen should warn about writing to initialized struct instances when using romable code, like with arrays "can only be used as read-only in ROMable code"
- 6502 asm symbol name prefixing should work for dereferences too.
- What about static initialization of an array of struct pointers? -> impossible right now because the pointer values are not constants

View File

@@ -22,7 +22,7 @@ main {
^^ubyte @shared ubptr
str name = "irmen"
bptr = &name
bptr = &name as ^^byte
ubptr = &name
stringinfo1("hello")
stringinfo2(name)
@@ -30,6 +30,8 @@ main {
arrayinfo(values)
arrayinfo(&values[2])
arrayinfo2(values)
bptr = name
ubptr = name
@@ -108,6 +110,10 @@ main {
txt.print_w(valueptr^^)
txt.nl()
}
sub arrayinfo2(uword ptr) {
cx16.r0++
}
}
thing {