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.

45 lines
782 B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace SuperBASIC
  5. {
  6. class Runtime
  7. {
  8. float register;
  9. internal Library lib;
  10. Bytecode code;
  11. public Runtime(Library library)
  12. {
  13. lib = library;
  14. }
  15. public void OpenFile(string path)
  16. {
  17. code = new Parser(this).ParseFile(path);
  18. }
  19. public void Run()
  20. {
  21. for(int idx = 0; idx < code.bytecode.Count;)
  22. {
  23. int opcode = code.bytecode[idx].GetOperand();
  24. int arity = lib.arities[opcode];
  25. IFunction op = lib.functions[opcode];
  26. var args = code.bytecode.GetRange(idx + 1, arity);
  27. SetRegister(op.Apply(args));
  28. idx += arity + 1;
  29. }
  30. }
  31. internal void SetRegister(float value)
  32. {
  33. register = value;
  34. }
  35. internal float GetRegister()
  36. {
  37. return register;
  38. }
  39. }
  40. }