I kind of see what you mean now, I've been giving it some thought and this is what I came up with.
Here's my dynamic object definition code:
Code:
typedef struct
{
int memory_address; /* stores the memory address of the current object, accessed/mutated via assembly */
int type; /* stores the type of the object, this may be removed as it might not be needed */
} object;
The memory_address value stores the address of some object type defined by a struct. All those object types need to have data members and methods (function pointers) added to them at runtime, without predeclaring them. Here's an example:
Code:
typedef struct
{
linked_list_of_object_addresses data;
} dynamic_struct;
This will be the base of all objects, built in types will have the linked_list_of_object_addresses filled in with some data members and methods before the program starts. Here's a function that would add a data member if it's not already in the list:
Code:
int append(object &a, object &b) /* a is the object to append to, b is the object to append */
{
for(int i = 0; i < len(*a); i++) /* len returns the length of linked_list_of_object_addresses */
{
if(b = (*a)[i])
{
return 0;
}
(*a).linked_list_of_object_addresses.add(b);
return 1;
}
I know it's pseudocode but the idea would work right?