Advertisement
Jhynjhiruu

BY thing

May 15th, 2018
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trace("loaded");
  2. if(_root.installed != true)
  3. {
  4.    trace("installed");
  5.    _root.installed = true;
  6.    _root.stack = [["map",0,"_root.test"],["sto","%m0","awesome"],["break"]];
  7.    _root.ret = "";
  8.    _root.toLoop = [];
  9.    _root.endRet = false;
  10.    _root.loopPositions = [];
  11.    _root.acc = "";
  12.    _root.mappable = [];
  13.    _root.doTick = true;
  14.    _root.programCounter = 0;
  15.    _root.execute = function(a)
  16.    {
  17.       if(a[0] == "end")
  18.       {
  19.          _root.endRet = true;
  20.       }
  21.       trace(a);
  22.    };
  23.    _root.cpu = function()
  24.    {
  25.       trace("doCycle " + _root.programCounter);
  26.       _root.toExecute = _root.stack[_root.programCounter];
  27.       h = 0;
  28.       while(h < _root.toExecute.length)
  29.       {
  30.          switch(_root.toExecute[h].slice(0,2))
  31.          {
  32.             case "%m":
  33.                _root.toExecute[h] = _root.mappable[int(_root.toExecute[h].slice(2))];
  34.                _root.stack[_root.programCounter[h]] = _root.mappable[int(_root.toExecute[h].slice(2))];
  35.                break;
  36.             case "%v":
  37.                set("_root.toExecute[" + h + "]",_root.toExecute[h].slice(2));
  38.                break;
  39.             default:
  40.                if(_root.toExecute[h].charAt(0) == "\\")
  41.                {
  42.                   _root.toExecute[h] = _root.toExecute[h].slice(1);
  43.                   break;
  44.                }
  45.          }
  46.          h++;
  47.       }
  48.       switch(_root.toExecute[0])
  49.       {
  50.          case "loop":
  51.             _root.loopPositions.push(_root.programCounter);
  52.             break;
  53.          case "end":
  54.             _root.execute(_root.toExecute);
  55.             if(_root.endRet)
  56.             {
  57.                _root.loopPositions.pop();
  58.             }
  59.             else
  60.             {
  61.                _root.programCounter = _root.loopPositions[_root.loopPositions.length - 1];
  62.             }
  63.             _root.endRet = false;
  64.             break;
  65.          case "map":
  66.             _root.mappable[_root.toExecute[1]] = _root.toExecute[2];
  67.             break;
  68.          case "sto":
  69.             set(_root.toExecute[1],_root.toExecute[2]);
  70.             break;
  71.          case "halt":
  72.             break;
  73.          case "break":
  74.             clearInterval(_root.cpuInterval);
  75.             break;
  76.          default:
  77.             _root.execute(_root.toExecute);
  78.       }
  79.       _root.programCounter++;
  80.       if(_root.programCounter >= _root.stack.length)
  81.       {
  82.          _root.stack = [["halt"]];
  83.       }
  84.    };
  85.    _root.tickCpu = function()
  86.    {
  87.       if(_root.doTick)
  88.       {
  89.          _root.cpu();
  90.       }
  91.    };
  92.    _root.cpuInterval = setInterval(_root.tickCpu,1);
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement