Author Topic: Typeinfo at runtime  (Read 9690 times)

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Typeinfo at runtime
« on: December 01, 2018, 10:59:10 AM »
I want to suggest that type info should be available at runtime. There are various way to implement this. In the end, the type should only be reduced to a number that’s used to access a generated a set of functions that are built during code generation.

To do this we need to introduce another built in type, ”vtype”.

Code: [Select]
vtype x = typeof(a);
bool y = is_struct(x);

What’s interesting here is for scripting and very dynamic plugins.
A function may take a void* plus the vtype and work on the data as if it was the given type, even though the code was built BEFORE the type was written.

The most general use for this is to dump structure data for debugging.
The macro can then be something like:

Code: [Select]
#define DUMP(x) dump_data(typeof(x), (void*)&x)

(Very rough, but hopefully you see what I mean)

dump_data here is a FUNCTION not a macro.

This is just a discussion starter. Add to the idea!

bas

  • Full Member
  • ***
  • Posts: 220
    • View Profile
Re: Typeinfo at runtime
« Reply #1 on: December 02, 2018, 12:11:32 PM »
For the macro system we will need something like typeof(), eg for swap() (pseudo code)

Code: [Select]
macro swap(x, y) {
   typeof(x) tmp = x;
   x = y;
   y = tmp;
}

I don't really like the vtype as it makes the language more complex again..

lerno

  • Full Member
  • ***
  • Posts: 247
    • View Profile
Re: Typeinfo at runtime
« Reply #2 on: December 03, 2018, 02:08:56 AM »
vtype could actually be simply an enum, generated at runtime.