value.h 1.8 KB

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