parametrize your mom?
This commit is contained in:
37
src/types.h
37
src/types.h
@@ -3,9 +3,10 @@
|
||||
|
||||
#include<stddef.h>
|
||||
#include<stdint.h>
|
||||
#include<stdbool.h>
|
||||
|
||||
typedef enum {
|
||||
TYPE_TYPE_PRIMITIVE, TYPE_TYPE_RECORD, TYPE_TYPE_POINTER, TYPE_TYPE_FUNCTION, TYPE_TYPE_ARRAY, TYPE_TYPE_ERROR
|
||||
TYPE_TYPE_PRIMITIVE, TYPE_TYPE_RECORD, TYPE_TYPE_POINTER, TYPE_TYPE_FUNCTION, TYPE_TYPE_ARRAY, TYPE_TYPE_GENERIC, TYPE_TYPE_ERROR
|
||||
} TypeType;
|
||||
|
||||
union Type;
|
||||
@@ -48,7 +49,12 @@ typedef struct TypeArray {
|
||||
TypeType type;
|
||||
|
||||
union Type *of;
|
||||
size_t length; /* 0 means unknown */
|
||||
|
||||
intmax_t length;
|
||||
|
||||
bool lengthIsGeneric;
|
||||
char *lengthGenericParamName;
|
||||
size_t lengthGenericParamIdx;
|
||||
} TypeArray;
|
||||
|
||||
typedef struct TypeRecord {
|
||||
@@ -56,14 +62,19 @@ typedef struct TypeRecord {
|
||||
|
||||
char *name;
|
||||
|
||||
size_t size;
|
||||
|
||||
union Type **fieldTypes;
|
||||
size_t *fieldOffsets;
|
||||
char **fieldNames;
|
||||
size_t fieldCount;
|
||||
} TypeRecord;
|
||||
|
||||
typedef struct TypeGeneric {
|
||||
TypeType type;
|
||||
|
||||
char *paramName;
|
||||
size_t paramIdx;
|
||||
} TypeGeneric;
|
||||
|
||||
typedef union Type {
|
||||
TypeType type;
|
||||
|
||||
@@ -72,6 +83,7 @@ typedef union Type {
|
||||
TypeFunction function;
|
||||
TypeArray array;
|
||||
TypeRecord record;
|
||||
TypeGeneric generic;
|
||||
} Type;
|
||||
|
||||
extern Type TYPE_ERROR;
|
||||
@@ -90,4 +102,21 @@ int type_is_number(Type *t);
|
||||
|
||||
char *type_to_string(Type*);
|
||||
|
||||
typedef struct Parametrization {
|
||||
void *param;
|
||||
|
||||
struct Parametrization *next;
|
||||
} Parametrization;
|
||||
|
||||
typedef struct {
|
||||
Parametrization *typeParams;
|
||||
Parametrization *intParams;
|
||||
} Parametrizations;
|
||||
|
||||
Type *type_parametrize(Type *target, Parametrizations *parametrizations, Parametrizations *renames);
|
||||
|
||||
Type *type_shallow_copy(Type *t);
|
||||
|
||||
bool type_is_generic(Type *t);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user