Commit cd07c3c
committed
fix: Correct ToBytes method syntax and GPU declaration parsing
This commit fixes two critical bugs in the GPU code generation:
1. **ToBytes method used invalid syntax**: Changed from the incorrect
type conversion syntax to using unsafe.Slice(), which is the
modern and correct approach for Go 1.17+.
Before (invalid):
(*[unsafe.Sizeof(Type{})]byte)[unsafe.Pointer(s)]
After (correct):
unsafe.Slice((*byte)(unsafe.Pointer(s)), int(unsafe.Sizeof(*s)))
2. **Parser incorrectly matched regular structs as GPU structs**:
GPUStructDecl and GPUFuncDecl used `@@*` (zero or more decorators),
which caused regular structs/functions without decorators to be
treated as GPU code.
Changed both to `@@+` (one or more decorators required), ensuring
only explicitly decorated code is treated as GPU/WGSL code.
This prevents calculator and other non-GPU examples from generating
unnecessary GPU files and fixes compilation errors.
Changes:
- Updated generateToBytesMethod to use unsafe.Slice
- Changed GPUStructDecl decorators from `@@*` to `@@+`
- Changed GPUFuncDecl decorators from `@@*` to `@@+`
- All tests passing
- Pre-commit checks passing1 parent cfb6fa7 commit cd07c3c
2 files changed
Lines changed: 37 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
152 | 156 | | |
153 | 157 | | |
154 | 158 | | |
| |||
175 | 179 | | |
176 | 180 | | |
177 | 181 | | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
183 | 211 | | |
184 | 212 | | |
185 | 213 | | |
186 | 214 | | |
187 | 215 | | |
188 | | - | |
189 | | - | |
| 216 | + | |
| 217 | + | |
190 | 218 | | |
191 | 219 | | |
192 | 220 | | |
193 | | - | |
194 | 221 | | |
195 | 222 | | |
196 | 223 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
204 | 224 | | |
205 | 225 | | |
206 | 226 | | |
| |||
0 commit comments