(index, value)
| 185 | } |
| 186 | |
| 187 | set(index, value) { |
| 188 | // Validate baseType is 'storage' and has _originalIdentifier |
| 189 | const nodeData = getNodeDataFromID(this.strandsContext.dag, this.id); |
| 190 | if (nodeData.baseType !== 'storage') { |
| 191 | throw new Error('set() can only be used on storage buffers'); |
| 192 | } |
| 193 | if (!this._originalIdentifier) { |
| 194 | throw new Error('set() can only be used on storage buffers with an identifier'); |
| 195 | } |
| 196 | |
| 197 | // If value is a plain object (struct literal), expand to per-field assignments |
| 198 | // e.g. buf[idx] = { position: pos, velocity: vel } |
| 199 | // becomes buf[idx].position = pos; buf[idx].velocity = vel; |
| 200 | if (value !== null && typeof value === 'object' && !value.isStrandsNode && this._schema) { |
| 201 | const proxy = createStructArrayElementProxy(this.strandsContext, this, index, this._schema); |
| 202 | for (const [fieldName, fieldValue] of Object.entries(value)) { |
| 203 | proxy[fieldName] = fieldValue; |
| 204 | } |
| 205 | return this; |
| 206 | } |
| 207 | |
| 208 | // Create array assignment node: buffer.set(index, value) -> buffer[index] = value |
| 209 | // This creates an ASSIGNMENT node and records it in the CFG basic block |
| 210 | // CFG preserves sequential order, preventing reordering of assignments |
| 211 | arrayAssignmentNode(this.strandsContext, this, index, value); |
| 212 | |
| 213 | // Return this for chaining |
| 214 | return this; |
| 215 | } |
| 216 | } |
| 217 | export function createStrandsNode(id, dimension, strandsContext, onRebind) { |
| 218 | return new Proxy( |
no test coverage detected