public EarleStackFrameExecutor(EarleFunction function, EarleStackFrame parentFrame, int callerIp,
     EarleValue target,
     IEarleRuntimeScope superScope, EarleDictionary locals)
     : base(target)
 {
     Frame = parentFrame.SpawnChild(function, this, callerIp);
     Scopes.Push(new EarleRuntimeScope(superScope, locals));
 }
            public WaitFrameExecutor(EarleStackFrame parentFrame, float seconds)
                : base(EarleValue.Undefined)
            {
                if (parentFrame == null) throw new ArgumentNullException(nameof(parentFrame));
                Frame = parentFrame.SpawnChild(null, this, EarleStackFrame.SleepCallIP);

                _stopwatch = new Stopwatch();
                _stopwatch.Start();
                _miliseconds = (long) (seconds*1000);
            }
 public EarleStackFrame(EarleRuntime runtime, EarleFunction function, IEarleStackFrameExecutor executor,
     int callerIp,
     EarleStackFrame superFrame, EarleThread thread)
 {
     if (runtime == null)
         throw new ArgumentNullException(nameof(runtime));
     if (thread == null)
         throw new ArgumentNullException(nameof(thread));
     Runtime = runtime;
     ParentFrame = superFrame;
     Executor = executor;
     CallerIP = callerIp;
     Function = function;
     Thread = thread;
 }
        public virtual IEarleStackFrameExecutor CreateFrameExecutor(EarleStackFrame parentFrame, int callerIp,
            EarleValue target, EarleValue[] arguments)
        {
            if (arguments == null) throw new ArgumentNullException(nameof(arguments));
            var locals = new EarleDictionary();

            var index = 0;

            if (Parameters == null)
            {
                throw new Exception("Parameters cannot be null in order for a EarleStackFrameExecutor to be created.");
            }
            foreach (var parameter in Parameters)
            {
                locals[parameter] = index >= arguments.Length ? EarleValue.Undefined : arguments[index];
                index++;
            }

            return new EarleStackFrameExecutor(this, parentFrame, callerIp, target, File, locals);
        }
        public EarleValue? Invoke(EarleCompletionHandler completionHandler, EarleValue target, params EarleValue[] args)
        {
            var thread = new EarleThread(completionHandler);
            var rootFrame = new EarleStackFrame(File.Runtime, null, null, EarleStackFrame.RootFrameIP, null, thread);
            var frame = CreateFrameExecutor(rootFrame, EarleStackFrame.RootCallIP, target,
                args?.ToArray() ?? new EarleValue[0]);
            thread.AttachExecutor(frame);

            return thread.Run();
        }
 private static void Wait(EarleStackFrame frame, float seconds)
 {
     if (seconds > 0)
         frame.ChildFrame = new WaitFrameExecutor(frame, seconds).Frame;
 }
 private static void SetActiveLanguage(EarleStackFrame frame, string key)
 {
     frame.Runtime.Localizer.Key = key;
 }
 public EarleStackTrace(EarleStackFrame[] frames)
 {
     Frames = frames;
 }