value.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #ifndef VIRTUALMATH_VALUE_H
  2. #define VIRTUALMATH_VALUE_H
  3. #include "inter.h"
  4. typedef struct VirtualMathValue{
  5. enum ValueType{
  6. none=0,
  7. number=1,
  8. string,
  9. function,
  10. list,
  11. } type;
  12. union data{
  13. struct Number{
  14. NUMBER_TYPE num;
  15. } num;
  16. struct String{
  17. char *str;
  18. } str;
  19. struct {
  20. struct Statement *function;
  21. struct VirtualMathVarList *var;
  22. struct Parameter *pt;
  23. } function;
  24. struct {
  25. enum {
  26. value_tuple,
  27. value_list,
  28. } type;
  29. struct VirtualMathLinkValue **list;
  30. long int size;
  31. } list;
  32. }data;
  33. struct VirtualMathValue *next;
  34. struct VirtualMathValue *last;
  35. } Value;
  36. typedef struct VirtualMathLinkValue{
  37. struct VirtualMathValue *value;
  38. struct VirtualMathLinkValue *father;
  39. struct VirtualMathLinkValue *next;
  40. struct VirtualMathLinkValue *last;
  41. } LinkValue;
  42. typedef struct VirtualMathResult{
  43. enum ResultType{
  44. not_return = 1, // 无返回值
  45. function_return, // 函数返回值
  46. operation_return, // 表达式返回值
  47. error_return, // 错误
  48. break_return,
  49. continue_return,
  50. rego_return,
  51. restart_return,
  52. } type;
  53. struct VirtualMathLinkValue *value;
  54. int times;
  55. } Result;
  56. Value *makeValue(Inter *inter);
  57. void freeValue(Value *value, Inter *inter);
  58. LinkValue *makeLinkValue(Value *value, LinkValue *linkValue,Inter *inter);
  59. void freeLinkValue(LinkValue *value, Inter *inter);
  60. Value *makeNumberValue(long num, Inter *inter);
  61. Value *makeStringValue(char *str, Inter *inter);
  62. Value *makeFunctionValue(Statement *st, struct Parameter *pt, struct VirtualMathVarList *var_list, Inter *inter);
  63. Value *makeListValue(struct Parameter **pt_ad, Result *result_tmp, struct globalInterpreter *inter, struct VirtualMathVarList *var_list,
  64. int type);
  65. void setResult(Result *ru, bool link, Inter *inter);
  66. void setResultError(Result *ru, Inter *inter);
  67. void setResultOperation(Result *ru, Inter *inter);
  68. void printValue(Value *value, FILE *debug);
  69. void printLinkValue(LinkValue *value, char *first, char *last, FILE *debug);
  70. #endif //VIRTUALMATH_VALUE_H