Note that there are some explanatory texts on larger screens.

plurals
  1. PORecord containing access to instantiation of generic package based on that record
    primarykey
    data
    text
    <p>This is really an annoying problem. I have a record type that wraps various base types and now I need it to be able to store a vector (from Ada.Containers.Vectors) <em>in itself</em>! I guess that's not possible but can anyone give me advice on how to solve this problem in another way perhaps? To give you a better idea of what I'm up to, here is what does <em>not</em> work:</p> <pre><code>with Base_Types; use Base_Types; with Ada.Strings.Wide_Unbounded; use Ada.Strings.Wide_Unbounded; with Ada.Containers.Vectors; with Green_Tasks; use Green_Tasks; with Ada.Unchecked_Deallocation; package Boxed_Types is type String_Ptr is access Unbounded_Wide_String; procedure Free_Unbounded_Wide_String is new Ada.Unchecked_Deallocation (Object =&gt; Unbounded_Wide_String, Name =&gt; String_Ptr); type Vector_Ptr; -- this won't work type Type_T is (T_Null, T_UInt64, T_Text, T_Bool, T_GTask, T_Vector); type Item (IType : Type_T := T_Null) is record case IType is when T_Null =&gt; null; when T_UInt64 =&gt; UInt64 : UInteger_64; when T_Text =&gt; String : String_Ptr; when T_Bool =&gt; Bool : Boolean; when T_GTask =&gt; Green_Task : Green_Task_Ptr; when T_Vector =&gt; Item_Vector : Vector_Ptr; -- error here end case; end record; package Item_Vectors is new Ada.Containers.Vectors (Index_Type =&gt; Natural, Element_Type =&gt; Item); use Item_Vectors; type Vector_Ptr is access Vector; end Boxed_Types; </code></pre> <p>This gives me the not so unexpected error <em>"invalid use of type before it's full declaration"</em> for Vector_Ptr. However, I cannot instantiate the vector package before I have declared Item either, and I really need the vector and the base types wrapped into one record type. (It's for Interpreter I'm writing in my spare time; the VM must store various different types on the stack, in heterogenous arrays, manipulate them, etc..) </p> <p>Will I have to break type safety entirely and mess around with address to access conversions or is there a cleaner solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload