diff options
author | Matthew Sotoudeh <matthew@masot.net> | 2023-07-27 12:06:17 -0700 |
---|---|---|
committer | Matthew Sotoudeh <matthew@masot.net> | 2023-07-27 12:06:17 -0700 |
commit | 578531395ecbabd8179e31520c2832ac7d6d3765 (patch) | |
tree | a19666928bb0d8aa47c9c9135cd80268b124ec82 /python/examples/dynamic_typing/runtime/dynamic_typing.h | |
parent | e29b2b00691b12ae70e97a072664bad073d81c4f (diff) |
add dynamic typing example
Diffstat (limited to 'python/examples/dynamic_typing/runtime/dynamic_typing.h')
-rw-r--r-- | python/examples/dynamic_typing/runtime/dynamic_typing.h | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/python/examples/dynamic_typing/runtime/dynamic_typing.h b/python/examples/dynamic_typing/runtime/dynamic_typing.h new file mode 100644 index 0000000..4f7b1aa --- /dev/null +++ b/python/examples/dynamic_typing/runtime/dynamic_typing.h @@ -0,0 +1,48 @@ +#ifndef DYNAMIC_TYPING_ +#define DYNAMIC_TYPING_ + +enum TYPE_KIND { + TY_BASIC, + TY_ARRAY, + TY_POINTER, + TY_FUNCTION, + TY_STRUCT, + TY_UNION, +}; + +struct type { + enum TYPE_KIND kind; + unsigned long size; + + // basic types: + const char *basic; + + // array & pointer types: + struct type *base; + unsigned long length; + + // struct & union types + struct type *members; + struct type *next_member; + unsigned long offset; + const char *field_name; + + // function types: + struct type *return_type; + struct type *params; + struct type *next_param; +}; + +struct type *dynamic_typeof(void *ptr); + +struct type *make_basic(const char *type, unsigned long size); +struct type *make_array(struct type *base, unsigned long len); +struct type *make_pointer(struct type *base); +// function not supported yet +// for struct & union, the members are initialized by the caller +struct type *make_struct(unsigned long size); +struct type *make_union(unsigned long size); +void prepend_member(struct type *aggregate, struct type *member, const char *name, unsigned long offset); +void annotate_type(void *ptr, struct type *type); + +#endif |