@@ -342,6 +342,199 @@ WASM_API_EXTERN bool wasmtime_eqref_as_struct(wasmtime_context_t *context,
342342 const wasmtime_eqref_t * eqref ,
343343 wasmtime_structref_t * out );
344344
345+ /**
346+ * \brief An opaque handle to a WebAssembly array type definition.
347+ *
348+ * An array type describes the element type of an array. It is used to create a
349+ * #wasmtime_array_ref_pre_t, which can then allocate array instances.
350+ *
351+ * Owned. Must be deleted with #wasmtime_array_type_delete.
352+ */
353+ typedef struct wasmtime_array_type wasmtime_array_type_t ;
354+
355+ /**
356+ * \brief Create a new array type.
357+ *
358+ * \param engine The engine to register the type with.
359+ * \param field The element type descriptor.
360+ *
361+ * \return Returns a new array type.
362+ */
363+ WASM_API_EXTERN wasmtime_array_type_t *
364+ wasmtime_array_type_new (const wasm_engine_t * engine ,
365+ const wasmtime_field_type_t * field );
366+
367+ /**
368+ * \brief Delete an array type.
369+ */
370+ WASM_API_EXTERN void wasmtime_array_type_delete (wasmtime_array_type_t * ty );
371+
372+ /**
373+ * \brief An opaque pre-allocated array layout for fast allocation.
374+ *
375+ * Created from a #wasmtime_array_type_t and a store context. Reusable for
376+ * allocating many array instances of the same type.
377+ *
378+ * Owned. Must be deleted with #wasmtime_array_ref_pre_delete.
379+ */
380+ typedef struct wasmtime_array_ref_pre wasmtime_array_ref_pre_t ;
381+
382+ /**
383+ * \brief Create a new array pre-allocator.
384+ *
385+ * \param context The store context.
386+ * \param ty The array type (not consumed; caller retains ownership).
387+ *
388+ * \return Returns a new array ref pre-allocator.
389+ */
390+ WASM_API_EXTERN wasmtime_array_ref_pre_t *
391+ wasmtime_array_ref_pre_new (wasmtime_context_t * context ,
392+ const wasmtime_array_type_t * ty );
393+
394+ /**
395+ * \brief Delete an array pre-allocator.
396+ */
397+ WASM_API_EXTERN void
398+ wasmtime_array_ref_pre_delete (wasmtime_array_ref_pre_t * pre );
399+
400+ /**
401+ * \typedef wasmtime_arrayref_t
402+ * \brief Convenience alias for #wasmtime_arrayref
403+ *
404+ * \struct wasmtime_arrayref
405+ * \brief A WebAssembly `arrayref` value.
406+ *
407+ * This structure represents a reference to a GC array. It is a subtype of
408+ * `eqref` and `anyref`.
409+ *
410+ * Values must be explicitly unrooted via #wasmtime_arrayref_unroot.
411+ */
412+ typedef struct wasmtime_arrayref {
413+ /// Internal metadata.
414+ uint64_t store_id ;
415+ /// Internal to Wasmtime.
416+ uint32_t __private1 ;
417+ /// Internal to Wasmtime.
418+ uint32_t __private2 ;
419+ /// Internal to Wasmtime.
420+ void * __private3 ;
421+ } wasmtime_arrayref_t ;
422+
423+ /// \brief Initialize the `ref` to a null `arrayref` value.
424+ static inline void wasmtime_arrayref_set_null (wasmtime_arrayref_t * ref ) {
425+ ref -> store_id = 0 ;
426+ }
427+
428+ /// \brief Returns whether the provided `ref` is a null `arrayref` value.
429+ static inline bool wasmtime_arrayref_is_null (const wasmtime_arrayref_t * ref ) {
430+ return ref -> store_id == 0 ;
431+ }
432+
433+ /**
434+ * \brief Allocate a new array instance.
435+ *
436+ * All elements are initialized to the same value.
437+ *
438+ * \param context The store context.
439+ * \param pre The array pre-allocator.
440+ * \param elem The initial element value.
441+ * \param len The number of elements.
442+ * \param out Receives the new arrayref on success.
443+ *
444+ * \return NULL on success, or a #wasmtime_error_t on failure.
445+ */
446+ WASM_API_EXTERN wasmtime_error_t * wasmtime_arrayref_new (
447+ wasmtime_context_t * context , const wasmtime_array_ref_pre_t * pre ,
448+ const wasmtime_val_t * elem , uint32_t len , wasmtime_arrayref_t * out );
449+
450+ /**
451+ * \brief Clone an `arrayref`, creating a new root.
452+ */
453+ WASM_API_EXTERN void
454+ wasmtime_arrayref_clone (const wasmtime_arrayref_t * arrayref ,
455+ wasmtime_arrayref_t * out );
456+
457+ /**
458+ * \brief Unroot an `arrayref` to allow garbage collection.
459+ */
460+ WASM_API_EXTERN void wasmtime_arrayref_unroot (wasmtime_arrayref_t * ref );
461+
462+ /**
463+ * \brief Upcast an `arrayref` to an `anyref`.
464+ */
465+ WASM_API_EXTERN void
466+ wasmtime_arrayref_to_anyref (const wasmtime_arrayref_t * arrayref ,
467+ wasmtime_anyref_t * out );
468+
469+ /**
470+ * \brief Upcast an `arrayref` to an `eqref`.
471+ */
472+ WASM_API_EXTERN void
473+ wasmtime_arrayref_to_eqref (const wasmtime_arrayref_t * arrayref ,
474+ wasmtime_eqref_t * out );
475+
476+ /**
477+ * \brief Get the length of an array.
478+ *
479+ * \param context The store context.
480+ * \param arrayref The array (not consumed).
481+ * \param out Receives the length on success.
482+ *
483+ * \return NULL on success, or a #wasmtime_error_t on failure.
484+ */
485+ WASM_API_EXTERN wasmtime_error_t *
486+ wasmtime_arrayref_len (wasmtime_context_t * context ,
487+ const wasmtime_arrayref_t * arrayref , uint32_t * out );
488+
489+ /**
490+ * \brief Read an element from an array.
491+ *
492+ * \param context The store context.
493+ * \param arrayref The array (not consumed).
494+ * \param index The element index.
495+ * \param out Receives the element value on success.
496+ *
497+ * \return NULL on success, or a #wasmtime_error_t on failure.
498+ */
499+ WASM_API_EXTERN wasmtime_error_t *
500+ wasmtime_arrayref_get (wasmtime_context_t * context ,
501+ const wasmtime_arrayref_t * arrayref , uint32_t index ,
502+ wasmtime_val_t * out );
503+
504+ /**
505+ * \brief Set an element of an array.
506+ *
507+ * \param context The store context.
508+ * \param arrayref The array (not consumed).
509+ * \param index The element index.
510+ * \param val The value to write.
511+ *
512+ * \return NULL on success, or a #wasmtime_error_t on failure.
513+ */
514+ WASM_API_EXTERN wasmtime_error_t *
515+ wasmtime_arrayref_set (wasmtime_context_t * context ,
516+ const wasmtime_arrayref_t * arrayref , uint32_t index ,
517+ const wasmtime_val_t * val );
518+
519+ /**
520+ * \brief Test whether an `eqref` is an `arrayref`.
521+ *
522+ * Returns `false` for null references.
523+ */
524+ WASM_API_EXTERN bool wasmtime_eqref_is_array (wasmtime_context_t * context ,
525+ const wasmtime_eqref_t * eqref );
526+
527+ /**
528+ * \brief Downcast an `eqref` to an `arrayref`.
529+ *
530+ * If the given `eqref` is an `arrayref`, a new root for it is stored in `out`
531+ * and `true` is returned. Otherwise `false` is returned and `out` is set to
532+ * null.
533+ */
534+ WASM_API_EXTERN bool wasmtime_eqref_as_array (wasmtime_context_t * context ,
535+ const wasmtime_eqref_t * eqref ,
536+ wasmtime_arrayref_t * out );
537+
345538#ifdef __cplusplus
346539} // extern "C"
347540#endif
0 commit comments