You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1001 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace SuperBASIC
  5. {
  6. enum NumberType{
  7. Ans,
  8. Number,
  9. Operand
  10. };
  11. struct BasicNumber
  12. {
  13. internal NumberType type;
  14. readonly Runtime runtime;
  15. readonly private float number;
  16. readonly private int operand;
  17. internal BasicNumber(Runtime rt, float v)
  18. {
  19. type = NumberType.Number;
  20. number = v;
  21. operand = 0;
  22. runtime = rt;
  23. }
  24. internal BasicNumber(Runtime rt)
  25. {
  26. type = NumberType.Ans;
  27. number = 0;
  28. operand = 0;
  29. runtime = rt;
  30. }
  31. internal BasicNumber(Runtime rt, int v)
  32. {
  33. type = NumberType.Operand;
  34. number = 0;
  35. operand = v;
  36. runtime = rt;
  37. }
  38. internal int GetOperand()
  39. {
  40. return operand;
  41. }
  42. public float GetValue()
  43. {
  44. if (type == NumberType.Number)
  45. {
  46. return number;
  47. }
  48. else
  49. {
  50. return runtime.GetRegister();
  51. }
  52. }
  53. public static implicit operator float(BasicNumber v) => v.GetValue();
  54. public override string ToString() => $"{number}";
  55. }
  56. }