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.

46 lines
796 B

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
  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. internal int pc = 0;
  12. public Runtime(Library library)
  13. {
  14. lib = library;
  15. }
  16. public void OpenFile(string path)
  17. {
  18. code = new Parser(this).ParseFile(path);
  19. }
  20. public void Run()
  21. {
  22. for(pc = 0; pc < code.bytecode.Count;)
  23. {
  24. int opcode = code.bytecode[pc].GetOperand();
  25. int arity = lib.arities[opcode];
  26. IFunction op = lib.functions[opcode];
  27. var args = code.bytecode.GetRange(pc + 1, arity);
  28. SetRegister(op.Apply(args));
  29. pc += arity + 1;
  30. }
  31. }
  32. internal void SetRegister(float value)
  33. {
  34. register = value;
  35. }
  36. internal float GetRegister()
  37. {
  38. return register;
  39. }
  40. }
  41. }