value.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. } type;
  11. union data{
  12. struct Number{
  13. NUMBER_TYPE num;
  14. } num;
  15. struct String{
  16. char *str;
  17. } str;
  18. struct {
  19. struct Statement *function;
  20. struct VirtualMathVarList *var;
  21. } function;
  22. }data;
  23. struct VirtualMathValue *next;
  24. struct VirtualMathValue *last;
  25. } Value;
  26. typedef struct VirtualMathLinkValue{
  27. struct VirtualMathValue *value;
  28. struct VirtualMathLinkValue *father;
  29. struct VirtualMathLinkValue *next;
  30. struct VirtualMathLinkValue *last;
  31. } LinkValue;
  32. typedef struct VirtualMathResult{
  33. enum ResultType{
  34. not_return = 1, // 无返回值
  35. function_return, // 函数返回值
  36. operation_return, // 表达式返回值
  37. error_return, // 错误
  38. break_return,
  39. continue_return,
  40. } type;
  41. struct VirtualMathLinkValue *value;
  42. int times;
  43. } Result;
  44. Value *makeValue(Inter *inter);
  45. void freeValue(Value *value, Inter *inter);
  46. LinkValue *makeLinkValue(Value *value, LinkValue *linkValue,Inter *inter);
  47. void freeLinkValue(LinkValue *value, Inter *inter);
  48. Value *makeNumberValue(long num, Inter *inter);
  49. Value *makeStringValue(char *str, Inter *inter);
  50. Value *makeFunctionValue(Statement *st, struct VirtualMathVarList *var_list, Inter *inter);
  51. void setResult(Result *ru, bool link, Inter *inter);
  52. void setResultError(Result *ru, Inter *inter);
  53. void setResultOperation(Result *ru, Inter *inter);
  54. #endif //VIRTUALMATH_VALUE_H