value.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. rego_return,
  41. } type;
  42. struct VirtualMathLinkValue *value;
  43. int times;
  44. } Result;
  45. Value *makeValue(Inter *inter);
  46. void freeValue(Value *value, Inter *inter);
  47. LinkValue *makeLinkValue(Value *value, LinkValue *linkValue,Inter *inter);
  48. void freeLinkValue(LinkValue *value, Inter *inter);
  49. Value *makeNumberValue(long num, Inter *inter);
  50. Value *makeStringValue(char *str, Inter *inter);
  51. Value *makeFunctionValue(Statement *st, struct VirtualMathVarList *var_list, Inter *inter);
  52. void setResult(Result *ru, bool link, Inter *inter);
  53. void setResultError(Result *ru, Inter *inter);
  54. void setResultOperation(Result *ru, Inter *inter);
  55. #endif //VIRTUALMATH_VALUE_H