DataType.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 constant : 1;
  16. unsigned int structId : 23;
  17. } DataType;
  18. typedef struct {
  19. const char* name;
  20. DataType type;
  21. } StructVariable;
  22. typedef struct {
  23. const char* name;
  24. int id;
  25. int amount;
  26. StructVariable* vars;
  27. } Struct;
  28. typedef struct {
  29. int capacity;
  30. int entries;
  31. Struct* data;
  32. } Structs;
  33. typedef struct {
  34. int32 array;
  35. int32 offset;
  36. } Pointer;
  37. int dtGetSize(DataType dt, Structs* sts);
  38. DataType dtInt32();
  39. DataType dtInt64();
  40. DataType dtFloat();
  41. DataType dtBool();
  42. DataType dtNull();
  43. DataType dtText();
  44. DataType dtVoid();
  45. DataType dtStruct(Struct* st);
  46. DataType dtReference(DataType dt);
  47. bool dtDereference(DataType* dt);
  48. Struct* dtGetStruct(Structs* sts, DataType dt);
  49. DataType dtToVariable(DataType dt);
  50. bool dtRemoveVariable(DataType* dt);
  51. DataType dtConst(DataType dt);
  52. bool dtCompare(DataType a, DataType b);
  53. bool dtNullCompare(DataType a, DataType bOrNull);
  54. bool dtIsInt32(DataType dt);
  55. bool dtIsInt64(DataType dt);
  56. bool dtIsFloat(DataType dt);
  57. bool dtIsBool(DataType dt);
  58. bool dtIsNull(DataType dt);
  59. bool dtIsVoid(DataType dt);
  60. bool dtIsPointer(DataType dt);
  61. bool dtIsVariable(DataType dt);
  62. const char* dtGetName(Structs* sts, DataType dt);
  63. void stAddVariable(Struct* st, const char* name, DataType type);
  64. void stsInit(Structs* sts);
  65. void stsDelete(Structs* sts);
  66. Struct* stsSearch(Structs* sts, const char* name);
  67. Struct* stsAdd(Structs* sts, const char* name);
  68. void gstsInit();
  69. void gstsDelete();
  70. Structs* gstsGet();
  71. Struct* gstsAdd(const char* name);
  72. #endif