From c2bf9024f866f3bb698edd75b8e1458d3a184495 Mon Sep 17 00:00:00 2001 From: Irmen de Jong Date: Wed, 18 Jun 2025 18:38:53 +0200 Subject: [PATCH] start writing docs about structs and pointers, update syntax files with ^^ --- .idea/libraries/eclipse_lsp4j.xml | 4 +- README.md | 1 + docs/source/comparing.rst | 18 ++++-- docs/source/index.rst | 2 + docs/source/programming.rst | 2 +- docs/source/structpointers.rst | 7 +++ docs/source/technical.rst | 3 +- docs/source/todo.rst | 5 +- docs/source/variables.rst | 6 +- examples/test.p8 | 56 ++----------------- syntax-files/NotepadPlusPlus/Prog8.xml | 2 +- syntax-files/NotepadPlusPlus/Prog8dark.xml | 2 +- syntax-files/SublimeText/Prog8.sublime-syntax | 2 + syntax-files/Vim/prog8.vim | 2 +- 14 files changed, 45 insertions(+), 67 deletions(-) create mode 100644 docs/source/structpointers.rst diff --git a/.idea/libraries/eclipse_lsp4j.xml b/.idea/libraries/eclipse_lsp4j.xml index 9405f8511..ea32d9e69 100644 --- a/.idea/libraries/eclipse_lsp4j.xml +++ b/.idea/libraries/eclipse_lsp4j.xml @@ -4,8 +4,8 @@ - - + + diff --git a/README.md b/README.md index a3bf47ef3..1a9534e46 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,7 @@ What does Prog8 provide? - code often is smaller and faster than equivalent C code compiled with CC65 or even LLVM-MOS - modularity, symbol scoping, subroutines. No need for forward declarations. - various data types other than just bytes (16-bit words, floats, strings) +- Structs and typed pointers - floating point math is supported on certain targets - access to most Kernal ROM routines as external subroutine definitions you can call normally - tight control over Zeropage usage diff --git a/docs/source/comparing.rst b/docs/source/comparing.rst index 7bbabdcaa..307455d22 100644 --- a/docs/source/comparing.rst +++ b/docs/source/comparing.rst @@ -46,6 +46,7 @@ Data types - maximum storage size for arrays is 256 bytes (512 for split word arrays) , the maximum number of elements in the array depends on the size of a single element value. you can use larger "arrays" via pointer indexing, see below at Pointers. One way of obtaining a piece of memory to store such an "array" is by using ``memory()`` builtin function. +- there is limited support for structs and typed pointers, see below at "Pointers and Structs". Variables @@ -76,10 +77,13 @@ Subroutines With only a little bit of code it is possible to implement a simple cooperative multitasking system that runs multiple tasks simultaneously. See the "multitasking" example, which uses the "coroutines" library. Each task is a subroutine and it simply has its state stored in the statically allocated variables so it can resume after yielding, without doing anything special. -Pointers --------- -- There is no specific pointer datatype. - However, variables of the ``uword`` datatype can be used as a pointer to one of the possible 65536 memory locations, +Pointers and Structs +-------------------- + +Legacy 'untyped' pointers: + +- In Prog8 versions before 12.0 there was no support for typed pointers, only 'untyped' ones: + Variables of the ``uword`` datatype can be used as a pointer to one of the possible 65536 memory locations, so the value it points to is always a single byte. This is similar to ``uint8_t*`` from C. You have to deal with the uword manually if the object it points to is something different. - Note that there is the ``peekw`` builtin function that *does* allow you to directy obtain the *word* value at the given memory location. @@ -88,6 +92,12 @@ Pointers - Pointers don't have to be a variable, you can immediately access the value of a given memory location using ``@($d020)`` for instance. Reading is done by assigning it to a variable, writing is done by just assigning the new value to it. +Typed pointers and structs: + +- Since version 12, prog8 supports struct types and typed pointers. +- Structs are a grouping of one or more fields, that together make up the struct type. +- Typed pointers are just that: a pointer to a specific type (which can be a simple type such as float, or a struct type.) + Foreign function interface (external/ROM calls) ----------------------------------------------- diff --git a/docs/source/index.rst b/docs/source/index.rst index b76c45a77..c1565f52a 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -96,6 +96,7 @@ Features and inline assembly to have full control when every register, cycle or byte matters - Variables are all allocated statically, no memory allocation overhead - Variable data types include signed and unsigned bytes and words, arrays, strings. +- Structs and typed pointers - Tight control over Zeropage usage - Programs can be restarted after exiting (i.e. run them multiple times without having to reload everything), due to automatic variable (re)initializations. - Programs can be configured to execute in ROM @@ -222,6 +223,7 @@ Look in the `syntax-files uword { - defer next += size - return next + ^^Node l1 + + l1^^.s[0] = 4242 } } diff --git a/syntax-files/NotepadPlusPlus/Prog8.xml b/syntax-files/NotepadPlusPlus/Prog8.xml index cf8946019..33062f4ed 100644 --- a/syntax-files/NotepadPlusPlus/Prog8.xml +++ b/syntax-files/NotepadPlusPlus/Prog8.xml @@ -13,7 +13,7 @@ - @ & &< &> | ^ ~ >> << += -= *= = **= &= |= ^= <<= >>= -> = == != < > <= >= , + ++ - -- * ** / ( ) [ ] + @ & &< &> | ^ ~ >> << += -= *= = **= &= |= ^= <<= >>= -> = == != < > <= >= , + ++ - -- * ** ^^ / ( ) [ ] { {{ diff --git a/syntax-files/NotepadPlusPlus/Prog8dark.xml b/syntax-files/NotepadPlusPlus/Prog8dark.xml index f94f14737..eec09eeef 100644 --- a/syntax-files/NotepadPlusPlus/Prog8dark.xml +++ b/syntax-files/NotepadPlusPlus/Prog8dark.xml @@ -13,7 +13,7 @@ - @ & &< &> | ^ ~ >> << += -= *= = **= &= |= ^= <<= >>= -> = == != < > <= >= , + ++ - -- * ** / ( ) [ ] + @ & &< &> | ^ ~ >> << += -= *= = **= &= |= ^= <<= >>= -> = == != < > <= >= , + ++ - -- * ** ^^ / ( ) [ ] { {{ diff --git a/syntax-files/SublimeText/Prog8.sublime-syntax b/syntax-files/SublimeText/Prog8.sublime-syntax index 85bfb5eb4..f11bb3529 100644 --- a/syntax-files/SublimeText/Prog8.sublime-syntax +++ b/syntax-files/SublimeText/Prog8.sublime-syntax @@ -151,6 +151,8 @@ contexts: storage: - match: (\b(ubyte|byte|word|uword|long|float|str|struct)\b) scope: storage.type.prog8 + - match: (\^\^) + scope: storage.modifier.prog8 - match: (\b(const)\b) scope: storage.modifier.prog8 support: diff --git a/syntax-files/Vim/prog8.vim b/syntax-files/Vim/prog8.vim index 2222185a2..786a3357f 100644 --- a/syntax-files/Vim/prog8.vim +++ b/syntax-files/Vim/prog8.vim @@ -38,7 +38,7 @@ syn match prog8Directive "\(^\|\s\)%\(zpreserved\|zpallowed\|address\|encoding\| syn match prog8Directive "\(^\|\s\)%\(align\|asmbinary\|asminclude\|breakpoint\)\>" syn match prog8Directive "\(^\|\s\)%\(asm\|ir\)\>" -syn match prog8Type "\<\%(u\?byte\|u\?word\|float\|str\|bool\|long\)\>" +syn match prog8Type "\<\%(u\?byte\|u\?word\|float\|str\|bool\|long\|\^\^\)\>" syn region prog8ArrayType matchgroup=prog8Type \ start="\<\%(u\?byte\|u\?word\|float\|str\|bool\)\[" end="\]" \ transparent