Commit Graph
66 Commits
Author SHA1 Message Date
Irmen de Jong e92a79c887 Add memory-mapped single struct instances 2026-11-21 12:29:32 +01:00
Irmen de Jong 6842239900 Support typed address-of struct instances in static initializer data
Taking the address of a direct struct instance in static initializer data
(pointer arrays and pointer-typed struct fields) worked on 6502 only. The
typed `&&` operator already provides the needed type, but the IR path broke
on targets without symbol prefixes:

- The virtual target skips symbol prefixing, so address-of symbols kept
  their plain scoped names (`main.p1`) while the struct instance storage is
  registered as `prog8_struct_instances.main_p1`. IRUnusedCodeRemover then
  crashed with "no chunk with label 'main.p1'" (only when optimizing).
  StConvert now resolves both the plain scoped form and the p8i_->p8v_
  prefixed form used on 6502 and m68k targets.

- Both symbol prefixers rebuilt PtAddressOf nodes for static initializer
  elements without their typed/msb flags; the flags are now preserved.
2026-11-20 00:52:52 +01:00
Irmen de Jong c1afe48564 Add real struct instance variables on 6502 targets
Allow `Point p` declarations with direct field access, initialization and
whole-struct copy on the 6502-based targets as well. Remove the checker
rejection and the corresponding doc/table restrictions.

Direct instances are emitted in a prog8_struct_instances block (or its
_bss variant when uninitialized or a union); references get a consistent
label via the new structInstanceLabel mapping, which rewrites the 'v'
declaration prefix to the 'i' reference prefix of the symbol prefixer.
Pointer-deref chains load the instance's storage address as the start
pointer, so field reads, writes and address-of work as expected.
2026-11-19 19:13:37 +01:00
Irmen de Jong 1829191db8 fix docs 2026-11-19 01:26:49 +01:00
Irmen de Jong e954d8b705 Add real struct instance variables on IR/m68k and virtual targets
Allow `Point p` declarations with direct field access, initialization and
whole-struct copy (`q = p` lowers to sys.memcopy) on 32-bit and virtual
targets. 6502 targets reject with a clear error and keep using pointers or
arrays of struct instances.

Direct variables are represented as StStructInstance nodes with static
storage; field access resolves via PtrDereference and address-of/field
addresses use the struct-instances symbol labels. Adds array-literal-to-
struct-initializer lowering and avoids false frame-address-escape warnings.
2026-11-19 00:32:50 +01:00
Irmen de Jong 973e180108 m68k: struct defs now as RS blocks in the .asm instead of hand calculated EQUS 2026-11-15 21:57:32 +01:00
Irmen de Jong 1e7d3b26f7 some deprecation notices, m68k docs fixes 2026-11-13 18:29:27 +01:00
Irmen de Jong 2508b0a9f4 if-expressions are now const folded too
fix invalid a0 instruction
2026-11-03 20:17:52 +01:00
Irmen de Jong eae012fd82 fix compiler crash on field write to a memory-mapped array of struct instances 2026-10-29 21:45:58 +01:00
Irmen de Jong 1f8b42fae5 make user docs and some code comments less convoluted 2026-10-05 20:00:32 +02:00
Irmen de Jong f086918e6f add union types: structs where every field is at offset 0, thus saving memory 2026-09-23 00:07:44 +02:00
Irmen de Jong ef64e2f9a4 fix typed pointer arithmetic p2-p1 to yield the number of elements. fixes #244 2026-09-18 21:22:07 +02:00
Irmen de Jong 7ba2ee9857 added named struct field initializers 2026-09-14 00:56:22 +02:00
Irmen de Jong 9621552056 add 'arena' allocator library
6502 targets use uword sizes with no alignment overhead; m68k/virtual use
long sizes with even-address alignment. Updated the six pointer examples that used to have their own arena implementation.
2026-09-13 05:43:57 +02:00
Irmen de Jong a7cbc2c5bf Review fixes: pointer read desugaring and poke->assignment optimizer 2026-09-09 02:31:21 +02:00
Irmen de Jong 9ac60eec40 fix some more pointer syntax related issues 2026-09-09 01:33:43 +02:00
Irmen de Jong c55b16f4cb todo 2026-09-09 01:01:16 +02:00
Irmen de Jong 9bf8318b1c Support arrays of struct instances
- Parser: parse `StructType[N] var` via elementToArray() for
  STRUCT_INSTANCE (Prog8ANTLR.g4, Antlr2KotlinVisitor)
- Desugar: struct-instance bases via addressOfStructInstance(),
  whole-struct `a[i]=a[j]` -> sys.memcopy, inferred `[[...]]`
  and explicit `Struct : [...]` (without ^^) for value arrays;
  reject `^^Struct : [...]` in instance arrays
- 6502: computeStructArrayElementAddress() with 16-bit
  index*structSize scaling (AssignmentAsmGen, AsmGen)
- IR/VM/m68k/new6502: STRUCTDEFS round-trip, loaders, gens
- AstChecker/IdentifiersChecker: reject struct fields that are
  arrays of structs; fix isArray guards
- Docs: structpointers.rst/variables.rst, todo.rst, examples/test.p8
- Tests: TestArraysOfStructs (pointer vs value init, IR round-trip,
  16-bit strides)
2026-08-30 18:24:14 +02:00
Irmen de Jong 94822b8662 Add arrays of struct instances (StructType[N] vars)
Parser: accept `Type[N] name` between type and identifier
(Prog8ANTLR.g4, Antlr2KotlinVisitor) via elementToArray()
for STRUCT_INSTANCE; CodeDesugarer: handle struct-instance
bases, addressOfStructInstance(), whole-struct memcopy
(points[a]=points[b]), and fix variable-index 16-bit scaling
in 6502 AssignmentAsmGen.computeStructArrayElementAddress();
IR: preserve STRUCTDEFS round-trip, VM loader support;
m68k/new6502/intermediate backends; docs + todo updated.
Limitations: not as struct fields (AstChecker/
AstIdentifiersChecker error) nor as sub params.
2026-08-30 14:14:49 +02:00
Irmen de Jong 27070f31e8 Merge branch 'master' into new-codegens
# Conflicts:
#	codeCore/src/prog8/code/core/DataTypes.kt
#	docs/source/todo.rst
2026-08-28 05:23:30 +02:00
Irmen de Jong 56643f43df tweak m68k tests and docs 2026-08-26 22:31:05 +02:00
Irmen de Jong 561f31329d support pointer assignment targets like (expr as ^^Struct).field = v and func().field = v (grammar + CodeDesugarer poke desugar, IR pointer-cast widening, tests/docs) 2026-08-24 23:00:23 +02:00
Irmen de Jong 2bbbacc46e normal error message instead of crash when typed pointer arrays are used as struct field (currently not supported by the compiler) 2026-08-24 19:21:30 +02:00
Irmen de Jong 894a3e90db codegen: fix pointer-typed struct field reads on 32-bit targets to use peekl and long address arithmetic 2026-08-22 12:40:34 +02:00
Irmen de Jong f3de26bf6c for-loop support for list/node iteration, and reverse str/array iteration using step -1 2026-08-21 07:28:39 +02:00
Irmen de Jong 54a1a0704a allow strings to be used to initialize arrays in struct instances 2026-08-16 23:25:41 +02:00
Irmen de Jong a5978a913b m68k: added coroutines module 2026-08-06 22:08:59 +02:00
Irmen de Jong e645b0abe1 add pokep() and peekp() builtin functions 2026-07-12 12:54:29 +02:00
Irmen de Jong 57714efb40 added pushp() and popp() builtin functions 2026-07-11 21:49:22 +02:00
Irmen de Jong 0e978b250b added 'pointer' as type alias for uword or long depending on the compilation target's pointer size 2026-07-11 16:59:24 +02:00
Irmen de Jong f9b3514f2a fixes and tests for embedded arrays in structs 2026-06-14 16:18:23 +02:00
Irmen de Jong be12fb507e arrays in structs 2026-06-14 15:35:30 +02:00
Irmen de Jong f8b5037924 spelling corrections 2026-05-29 20:58:06 +02:00
Irmen de Jong c291d7d4a8 const memory() support in struct initializers 2026-03-18 04:16:05 +01:00
Andrew Gillham 2bd74b8c44 Add an index and set some non-ASCII fonts to improve the resulting pdf. (#210)
* Add an index and set some non-ASCII fonts to improve the resulting pdf.

* Fix coroutines index interfering with code block

* Add genindex which is needed to get a link to the html index.
2026-01-30 22:03:40 +01:00
Irmen de Jong 014a82a1ee always put all struct types as .struct in asm code to make them all accessible for size and offsets 2025-12-10 21:39:44 +01:00
Irmen de Jong 3e1386a987 remove the -dontsplitarrays compiler option
it was still there for backward compatibility reasons with really old prog8 code. If you need a word array to be not split, just use @nosplit on the array.
2025-10-05 14:44:29 +02:00
Irmen de Jong 71ffbe2ba7 document the long type 2025-10-04 22:33:43 +02:00
Irmen de Jong 2c7256a443 support assignment to indexed pointer targets 2025-09-27 14:52:04 +02:00
Irmen de Jong 54fa72fa98 added sys.waitrasterline() routine like sys.waitvsync() but wait for a given raster line
optimize uword <= $xx00 into msb(uword)<$xx
2025-09-23 01:09:54 +02:00
Irmen de Jong 19f19f3880 doc and opening borders 2025-09-20 21:44:48 +02:00
Irmen de Jong ad0c767ea8 %breakpoint! introduced to place after an assignment to make it parse correctly 2025-09-20 00:46:15 +02:00
Irmen de Jong a8bede17b2 fix defer() with the arena allocator ("return values are evaluated before the defer is executed") 2025-09-17 23:59:32 +02:00
Irmen de Jong 9461e4088c fixed the hashtable example and workarounds for misbehaving defer in allocators 2025-09-17 22:53:01 +02:00
Irmen de Jong 633d6c34e2 add support for struct pointers and short-form initializers in arrays and assignments 2025-09-16 20:37:50 +02:00
Irmen de Jong 6de95f7a3b new static struct initializer syntax ^^Node : [1,2,3]
avoids confusion with function calls
2025-09-10 13:47:12 +02:00
Irmen de Jong 3a0392df8a there's a problem with the struct initializer syntax 2025-09-05 00:18:42 +02:00
Irmen de Jong 5999110e3f avoid using temporary pointer to access struct fields if a simple Y indexed cpu instruction can be used 2025-09-03 18:37:56 +02:00
Irmen de Jong 3ef09d7d9a use LOADFIELD instruction more instead of an extra explicit ADD
add implicit @zp to pointer variables if they don't have a preference
2025-08-31 15:53:44 +02:00
Irmen de Jong 2ca1820d4e Merge branch 'master' into structs6502 2025-08-28 21:55:46 +02:00