Example #1
0
        public DMProcState(DMProc proc, DreamThread thread, int maxStackSize, DreamObject instance, DreamObject usr, DreamProcArguments arguments)
            : base(thread)
        {
            _proc          = proc;
            _stack         = _stackPool.Rent(maxStackSize);
            Instance       = instance;
            Usr            = usr;
            Arguments      = arguments;
            LocalVariables = _dreamValuePool.Rent(256);

            // args -> locals
            for (int i = 0; i < proc.ArgumentNames.Count; i++)
            {
                string argumentName = proc.ArgumentNames[i];

                if (Arguments.NamedArguments.TryGetValue(argumentName, out DreamValue argumentValue))
                {
                    LocalVariables[i] = argumentValue;
                }
                else if (i < Arguments.OrderedArguments.Count)
                {
                    LocalVariables[i] = Arguments.OrderedArguments[i];
                }
                else
                {
                    LocalVariables[i] = DreamValue.Null;
                }
            }
        }
Example #2
0
 public InitDreamObjectState(DreamThread thread, DreamObject dreamObject, DreamObject usr, DreamProcArguments arguments)
     : base(thread)
 {
     _dreamObject = dreamObject;
     _usr         = usr;
     _arguments   = arguments;
 }
Example #3
0
 public State(NativeProc proc, DreamThread thread, DreamObject src, DreamObject usr, DreamProcArguments arguments)
     : base(thread)
 {
     _proc     = proc;
     Src       = src;
     Usr       = usr;
     Arguments = arguments;
 }
Example #4
0
 public InitDreamObjectState(DreamThread thread, DreamObject dreamObject, DreamObject usr, DreamProcArguments arguments)
     : base(thread)
 {
     IoCManager.InjectDependencies(this);
     _dreamObject = dreamObject;
     _usr         = usr;
     _arguments   = arguments;
 }
Example #5
0
 public State(AsyncNativeProc proc, Func <State, Task <DreamValue> > taskFunc, DreamThread thread, DreamObject src, DreamObject usr, DreamProcArguments arguments)
     : base(thread)
 {
     _proc     = proc;
     _taskFunc = taskFunc;
     Src       = src;
     Usr       = usr;
     Arguments = arguments;
 }
Example #6
0
        public DMProcState(DMProcState other, DreamThread thread)
            : base(thread)
        {
            if (other.EnumeratorStack.Count > 0)
            {
                throw new NotImplementedException();
            }

            _proc     = other._proc;
            Instance  = other.Instance;
            Usr       = other.Usr;
            Arguments = other.Arguments;
            _pc       = other._pc;

            _stack = _stackPool.Rent(other._stack.Length);
            Array.Copy(other._stack, _stack, _stack.Length);

            LocalVariables = _dreamValuePool.Rent(256);
            Array.Copy(other.LocalVariables, LocalVariables, 256);
        }
Example #7
0
            public Task <DreamValue> Call(DreamProc proc, DreamObject src, DreamObject usr, DreamProcArguments arguments)
            {
                _callTcs        = new();
                _callProcNotify = proc.CreateState(Thread, src, usr, arguments);

                // The field may be mutated by SafeResume, so cache the task
                var callTcs = _callTcs;

                SafeResume();
                return(callTcs.Task);
            }
Example #8
0
        public override ProcState CreateState(DreamThread thread, DreamObject src, DreamObject usr, DreamProcArguments arguments)
        {
            if (_defaultArgumentValues != null)
            {
                foreach (KeyValuePair <string, DreamValue> defaultArgumentValue in _defaultArgumentValues)
                {
                    int argumentIndex = ArgumentNames.IndexOf(defaultArgumentValue.Key);

                    if (arguments.GetArgument(argumentIndex, defaultArgumentValue.Key) == DreamValue.Null)
                    {
                        arguments.NamedArguments.Add(defaultArgumentValue.Key, defaultArgumentValue.Value);
                    }
                }
            }

            return(new State(this, _taskFunc, thread, src, usr, arguments));
        }
Example #9
0
 public override DMProcState CreateState(DreamThread thread, DreamObject src, DreamObject usr, DreamProcArguments arguments)
 {
     return(new DMProcState(this, thread, _maxStackSize, src, usr, arguments));
 }
Example #10
0
 public void Push(DreamProcArguments value)
 {
     _stack[_stackIndex++] = new DreamValue(value);
 }
Example #11
0
        public void Call(DreamProc proc, DreamObject src, DreamProcArguments arguments)
        {
            var state = proc.CreateState(Thread, src, Usr, arguments);

            Thread.PushProcState(state);
        }
Example #12
0
        public DMProcState(DMProc proc, DreamThread thread, int maxStackSize, DreamObject instance, DreamObject usr, DreamProcArguments arguments)
            : base(thread)
        {
            _proc           = proc;
            _stack          = _stackPool.Rent(maxStackSize);
            Instance        = instance;
            Usr             = usr;
            ArgumentCount   = Math.Max(arguments.ArgumentCount, proc.ArgumentNames?.Count ?? 0);
            _localVariables = _dreamValuePool.Rent(256);

            //TODO: Positional arguments must precede all named arguments, this needs to be enforced somehow
            //Positional arguments
            for (int i = 0; i < ArgumentCount; i++)
            {
                _localVariables[i] = (i < arguments.OrderedArguments.Count) ? arguments.OrderedArguments[i] : DreamValue.Null;
            }

            //Named arguments
            foreach ((string argumentName, DreamValue argumentValue) in arguments.NamedArguments)
            {
                int argumentIndex = proc.ArgumentNames?.IndexOf(argumentName) ?? -1;
                if (argumentIndex == -1)
                {
                    throw new Exception($"Invalid argument name \"{argumentName}\"");
                }

                _localVariables[argumentIndex] = argumentValue;
            }
        }