diff options
author | pommicket <pommicket@gmail.com> | 2022-02-03 21:46:36 -0500 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2022-02-03 21:46:36 -0500 |
commit | fd02968c23739e4289c9b675c5d50d8b1f51153d (patch) | |
tree | 36fab64491b87ee14096c4176ca1751c203bf9cd | |
parent | 3e6cacfb7c57fc8b6969c5939e88ba75089c0161 (diff) |
dereferencing function pointers
-rw-r--r-- | 05/constants.b | 16 | ||||
-rw-r--r-- | 05/main.c | 2 | ||||
-rw-r--r-- | 05/parse.b | 5 |
3 files changed, 15 insertions, 8 deletions
diff --git a/05/constants.b b/05/constants.b index 3d0e30a..983bc2a 100644 --- a/05/constants.b +++ b/05/constants.b @@ -216,14 +216,16 @@ #define TYPE_INT 7 #define TYPE_UNSIGNED_INT 8 #define TYPE_LONG 9 -#define TYPE_UNSIGNED_LONG 10 -#define TYPE_FLOAT 11 +#define TYPE_UNSIGNED_LONG 0xa +#define TYPE_FLOAT 0xb ; note that long double is treated the same as double. -#define TYPE_DOUBLE 12 -#define TYPE_POINTER 13 -#define TYPE_STRUCT 14 -#define TYPE_ARRAY 16 -#define TYPE_FUNCTION 17 +#define TYPE_DOUBLE 0xc +#define TYPE_POINTER 0xd +#define TYPE_STRUCT 0xe +#define TYPE_ARRAY 0xf +#define TYPE_FUNCTION 0x10 +; reading the first 16 bits of type data as a word will give this if the type refers to a function pointer. +#define TYPE2_FUNCTION_POINTER 0x100d ; types willl be initialized (in main) so that this refers to the type char* #define TYPE_POINTER_TO_CHAR 20 @@ -53,5 +53,7 @@ struct { typedef int Blah[sizeof((B *)0)->c.y]; unsigned marker = 0xdeadbeef; +typedef int (*FUNCTION)(void); +typedef int AAAA[sizeof*****((FUNCTION)0)]; /* typedef int X[sizeof(int)+4]; */ @@ -1620,10 +1620,13 @@ function parse_expression return out :unary_dereference type_decay_array_to_pointer(*4a) - ; @TODO : dereferencing a function (annoyingly, p is the same as *p for function pointers) + if *2p == TYPE2_FUNCTION_POINTER goto type_deref_fpointer if *1p != TYPE_POINTER goto unary_bad_type *4type = *4a + 1 return out + :type_deref_fpointer + *4type = *4a + return out :unary_type_logical_not type_decay_array_to_pointer(*4a) if *1p > TYPE_POINTER goto unary_bad_type |