parametrize your mom?

This commit is contained in:
Mid
2025-05-03 09:59:30 +03:00
parent 2c6033e501
commit 56c10daaa7
16 changed files with 1156 additions and 214 deletions

View File

@@ -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