Exemplo n.º 1
0
 public AnyBlueprint(VM interpreter, VM.State target, IEnumerable <Token <R> > payload)
     : base(interpreter)
 {
     _target  = target;
     _payload = payload;
     _old     = _target.Output.Size;
 }
Exemplo n.º 2
0
        public override bool Use()
        {
            // Fill in empty string arguments with state results.
            for (int i = 0; i < _args.Length; i++)
            {
                if (_args[i] == null)
                {
                    _args[i] = Argument.FromString(I.PopResultString());
                }
            }

            // Create an argument table so the args can be accessed by name.
            var argTable =
                _args.Select((arg, i) => new KeyValuePair <string, Argument>(_subroutine.Parameters[i].Item1, arg)).ToDictionary(pair => pair.Key, pair => pair.Value);

            // Create the state for the subroutine code
            var state = new VM.State(I, _subroutine.Source, I.CurrentState.Output);

            // Pre-blueprint pushes args
            state.Pre(new DelegateBlueprint(I, _ =>
            {
                _.SubArgStack.Push(argTable);
                return(false);
            }));

            // Post-blueprint pops args
            state.Post(new DelegateBlueprint(I, _ =>
            {
                _.SubArgStack.Pop();
                return(false);
            }));

            // Push the state onto the stack
            I.PushState(state);

            return(true);
        }