Ejemplo n.º 1
0
        static void _EnqueueFiber(ref int lcount, ref TokenizerFiber[] l, TokenizerFiber t, int sp)
        {
            // really shouldn't happen, but maybe it might
            if (l.Length <= lcount)
            {
                var newarr = new TokenizerFiber[l.Length * 2];
                Array.Copy(l, 0, newarr, 0, l.Length);
                l = newarr;
            }
            l[lcount] = t;
            ++lcount;
            var pc = t.Program[t.Index];
            var op = pc[0];

            if (_Jmp == op)
            {
                for (var j = 1; j < pc.Length; ++j)
                {
                    _EnqueueFiber(ref lcount, ref l, new TokenizerFiber(t.Program, pc[j], t.Saved), sp);
                }
                return;
            }
            if (_Save == op)
            {
                var slot = pc[1];
                var max  = t.Saved.Length;
                if (slot > max)
                {
                    max = slot;
                }
                var saved = new int[max];
                for (var i = 0; i < t.Saved.Length; ++i)
                {
                    saved[i] = t.Saved[i];
                }
                saved[slot] = sp;
                _EnqueueFiber(ref lcount, ref l, new TokenizerFiber(t, t.Index + 1, saved), sp);
                return;
            }
        }
Ejemplo n.º 2
0
 public TokenizerFiber(TokenizerFiber fiber, int index, int[] saved)
 {
     Program = fiber.Program;
     Index   = index;
     Saved   = saved;
 }