mirror of
https://github.com/KarolS/millfork.git
synced 2025-04-13 21:37:08 +00:00
Fix raw views of typed pointers
This commit is contained in:
parent
9881bc0284
commit
31a8504195
docs/lang
src
@ -82,6 +82,8 @@ You can create pointer values by suffixing `.pointer` to the name of a variable,
|
||||
|
||||
You can replace C-style pointer arithmetic by combining indexing and `.pointer`: C `p+5`, Millfork `p[5].pointer`.
|
||||
|
||||
You can use the typed pointer as a raw pointer by suffixing `.raw`.
|
||||
|
||||
Examples:
|
||||
|
||||
pointer.t p
|
||||
@ -93,6 +95,7 @@ Examples:
|
||||
p[i] // accessing the ith element; if 'sizeof(t) == 1', then equivalent to 't(p.raw[i])'
|
||||
p->x // valid only if the type 't' has a field called 'x', accesses the field 'x' of the pointed element
|
||||
p->x.y[0]->z[0][6] // you can stack it
|
||||
p.raw += sizeof(t) // if p points to an element of an array, then advances it to the next element
|
||||
|
||||
## `nullptr`
|
||||
|
||||
|
@ -2038,14 +2038,14 @@ class Environment(val parent: Option[Environment], val prefix: String, val cpuFa
|
||||
}
|
||||
case _ => Nil
|
||||
}
|
||||
case p: PointerType => if (options.isBigEndian) List(
|
||||
Subvariable(".raw", 0, p),
|
||||
case _: PointerType => if (options.isBigEndian) List(
|
||||
Subvariable(".raw", 0, get[VariableType]("pointer")),
|
||||
Subvariable(".raw.lo", 1, b),
|
||||
Subvariable(".raw.hi", 0, b),
|
||||
Subvariable(".lo", 1, b),
|
||||
Subvariable(".hi", 0, b)
|
||||
) else List(
|
||||
Subvariable(".raw", 0, p),
|
||||
Subvariable(".raw", 0, get[VariableType]("pointer")),
|
||||
Subvariable(".raw.lo", 0, b),
|
||||
Subvariable(".raw.hi", 1, b),
|
||||
Subvariable(".lo", 0, b),
|
||||
|
@ -475,4 +475,20 @@ class PointerSuite extends FunSuite with Matchers with AppendedClues {
|
||||
m.readWord(0xc000) should be <(256)
|
||||
m.readWord(0xc002) should be <(256)
|
||||
}
|
||||
|
||||
test("Raw pointers should work") {
|
||||
val m = EmuUnoptimizedRun(
|
||||
"""
|
||||
|
|
||||
| array(word) arr [252] @$c000
|
||||
|
|
||||
| void main () {
|
||||
| pointer.word p
|
||||
| p = arr.pointer
|
||||
| p.raw += sizeof(word)
|
||||
| p[0] = 4
|
||||
| }
|
||||
|""".stripMargin)
|
||||
m.readWord(0xc002) should equal(4)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user