DataType.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #ifndef DATATYPE_H
  2. #define DATATYPE_H
  3. #include <stdbool.h>
  4. #include "Types.h"
  5. #define DT_INT32 0
  6. #define DT_INT64 1
  7. #define DT_FLOAT 2
  8. #define DT_BOOL 3
  9. #define DT_NULL 4
  10. #define DT_VOID 5
  11. #define DT_STRUCT 6
  12. typedef struct {
  13. unsigned int type : 4;
  14. unsigned int pointers : 4;
  15. unsigned int structId : 24;
  16. } DataType;
  17. typedef struct {
  18. const char* name;
  19. DataType type;
  20. } StructVariable;
  21. typedef struct {
  22. const char* name;
  23. int id;
  24. int amount;
  25. StructVariable* vars;
  26. } Struct;
  27. typedef struct {
  28. int capacity;
  29. int entries;
  30. Struct* data;
  31. } Structs;
  32. typedef struct {
  33. int32 array;
  34. int32 offset;
  35. } Pointer;
  36. int dtGetSize(DataType dt, Structs* sts);
  37. DataType dtInt32();
  38. DataType dtInt64();
  39. DataType dtFloat();
  40. DataType dtBool();
  41. DataType dtNull();
  42. DataType dtText();
  43. DataType dtVoid();
  44. DataType dtStruct(Struct* st);
  45. DataType dtReference(DataType dt);
  46. bool dtDereference(DataType* dt);
  47. Struct* dtGetStruct(Structs* sts, DataType dt);
  48. DataType dtToVariable(DataType dt);
  49. bool dtRemoveVariable(DataType* dt);
  50. bool dtCompare(DataType a, DataType b);
  51. bool dtIsInt32(DataType dt);
  52. bool dtIsInt64(DataType dt);
  53. bool dtIsFloat(DataType dt);
  54. bool dtIsBool(DataType dt);
  55. bool dtIsNull(DataType dt);
  56. bool dtIsVoid(DataType dt);
  57. bool dtIsPointer(DataType dt);
  58. bool dtIsVariable(DataType dt);
  59. const char* dtGetName(Structs* sts, DataType dt);
  60. void stAddVariable(Struct* st, const char* name, DataType type);
  61. void stsInit(Structs* sts);
  62. void stsDelete(Structs* sts);
  63. Struct* stsSearch(Structs* sts, const char* name);
  64. Struct* stsAdd(Structs* sts, const char* name);
  65. #endif