示例#1
0
        private void AddParameters(ValueStack stack, Stream messageBody)
        {
            var ps = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters;

            for (int i = 0; i < ps.Count; i++)
            {
                object v = ps.GetValues(i);
                if (v.GetType() == typeof(String[]))
                {
                    v = ((String[])v)[0].ToString();
                }

                stack.Push(ps.GetKey(i), v);
            }

            if (messageBody != null)
            {
                using (System.IO.StreamReader r = new StreamReader(messageBody, System.Text.Encoding.UTF8, false, 1024, true))
                {
                    while (!r.EndOfStream)
                    {
                        string line = r.ReadLine();
                        if (!String.IsNullOrEmpty(line))
                        {
                            string[] arr = line.Split('=');
                            if (arr.Length == 2)
                            {
                                String v = System.Net.WebUtility.UrlDecode(arr[1].Trim());
                                stack.Push(arr[0].Trim(), v);
                            }
                        }
                    }
                }
            }
        }
示例#2
0
        public static void PopTest()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(3)
                        );

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(2)
                        );

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(1)
                        );

            Assert.That(() => valueStack.Pop(),
                        Throws.InvalidOperationException
                        );

            valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            _ = valueStack.Pop();
            valueStack.Push(4);

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(4)
                        );

            _ = valueStack.Pop();
            valueStack.Push(5);
            valueStack.Push(6);

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(6)
                        );

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(5)
                        );

            Assert.That(() => valueStack.Pop(),
                        Is.EqualTo(1)
                        );

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(3)
                        .And.Count.EqualTo(0)
                        );

            valueStack = new ValueStack <int>();

            Assert.That(() => valueStack.Pop(),
                        Throws.InvalidOperationException
                        );
        }
示例#3
0
        public static void PeekInt32Test()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            Assert.That(() => valueStack.Peek(0),
                        Is.EqualTo(3)
                        );

            valueStack.Push(4);

            Assert.That(() => valueStack.Peek(0),
                        Is.EqualTo(4)
                        );

            Assert.That(() => valueStack.Peek(3),
                        Is.EqualTo(1)
                        );

            _ = valueStack.Pop();
            valueStack.Push(5);

            Assert.That(() => valueStack.Peek(0),
                        Is.EqualTo(5)
                        );

            Assert.That(() => valueStack.Peek(1),
                        Is.EqualTo(3)
                        );

            _ = valueStack.Pop();
            valueStack.Push(6);
            valueStack.Push(7);

            Assert.That(() => valueStack.Peek(0),
                        Is.EqualTo(7)
                        );

            Assert.That(() => valueStack.Peek(2),
                        Is.EqualTo(3)
                        );

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(6)
                        .And.Count.EqualTo(5)
                        );

            valueStack = new ValueStack <int>();

            Assert.That(() => valueStack.Peek(0),
                        Throws.InstanceOf <ArgumentOutOfRangeException>()
                        .And.Property("ActualValue").EqualTo(0)
                        .And.Property("ParamName").EqualTo("index")
                        );
        }
示例#4
0
        public static void TrimExcessTest()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            valueStack.TrimExcess();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(3)
                        .And.Count.EqualTo(3)
                        );

            valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            _ = valueStack.Pop();

            valueStack.Push(4);
            valueStack.TrimExcess();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(3)
                        .And.Count.EqualTo(3)
                        );

            valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            valueStack.Push(4);
            valueStack.Push(5);

            valueStack.TrimExcess();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(5)
                        .And.Count.EqualTo(5)
                        );

            valueStack.EnsureCapacity(15);
            valueStack.TrimExcess(0.3f);

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(15)
                        .And.Count.EqualTo(5)
                        );

            valueStack = new ValueStack <int>();
            valueStack.TrimExcess();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(0)
                        .And.Count.EqualTo(0)
                        );
        }
示例#5
0
        public static void CopyToTest()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            var destination = new int[3];

            valueStack.CopyTo(destination);

            Assert.That(() => destination,
                        Is.EquivalentTo(new int[] { 1, 2, 3 })
                        );

            _ = valueStack.Pop();
            valueStack.Push(4);

            valueStack.CopyTo(destination);

            Assert.That(() => destination,
                        Is.EquivalentTo(new int[] { 1, 2, 4 })
                        );

            destination = new int[6];
            valueStack.CopyTo(destination);

            Assert.That(() => destination,
                        Is.EquivalentTo(new int[] { 1, 2, 4, 0, 0, 0 })
                        );

            _ = valueStack.Pop();
            valueStack.Push(5);
            valueStack.Push(6);

            valueStack.CopyTo(destination);

            Assert.That(() => destination,
                        Is.EquivalentTo(new int[] { 1, 2, 5, 6, 0, 0 })
                        );

            Assert.That(() => valueStack.CopyTo(Array.Empty <int>()),
                        Throws.ArgumentException
                        .And.Property("ParamName").EqualTo("destination")
                        );

            valueStack = new ValueStack <int>();

            Assert.That(() => valueStack.CopyTo(Array.Empty <int>()),
                        Throws.Nothing
                        );
        }
示例#6
0
        /// <summary>
        /// Shift.
        /// </summary>
        /// <param name="stateIndex">state index.</param>
        private void Shift(int stateIndex)
        {
            FsaState = states[stateIndex];

            ValueStack.Push(Scanner.yylval);
            StateStack.Push(FsaState);
            LocationStack.Push(Scanner.yylloc);

            if (recovering)
            {
                if (NextToken != errorToken)
                {
                    tokensSinceLastError++;
                }

                if (tokensSinceLastError > 5)
                {
                    recovering = false;
                }
            }

            if (NextToken != endOfFileToken)
            {
                NextToken = 0;
            }
        }
        private void Shift(int stateIndex)
        {
#if TRACE_ACTIONS
            Console.Error.Write("Shifting token {0}, ", TerminalToString(NextToken));
#endif
            FsaState = states[stateIndex];

            ValueStack.Push(Scanner.yylval);
            StateStack.Push(FsaState);
            LocationStack.Push(Scanner.yylloc);

            if (recovering)
            {
                if (NextToken != errorToken)
                {
                    tokensSinceLastError++;
                }

                if (tokensSinceLastError > 5)
                {
                    recovering = false;
                }
            }

            if (NextToken != endOfFileToken)
            {
                NextToken = 0;
            }
        }
示例#8
0
        public static void TryPopTest()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });
            var result     = valueStack.TryPop(out var value);

            Assert.That(() => result,
                        Is.True
                        );

            Assert.That(() => value,
                        Is.EqualTo(3)
                        );

            valueStack.Push(4);
            result = valueStack.TryPop(out value);

            Assert.That(() => result,
                        Is.True
                        );

            Assert.That(() => value,
                        Is.EqualTo(4)
                        );

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(3)
                        .And.Count.EqualTo(2)
                        );

            valueStack = new ValueStack <int>();

            Assert.That(() => valueStack.TryPop(out _),
                        Is.False
                        );
        }
示例#9
0
 public bool Fail(string message)
 {
     Dispose();
     HasFailed = true;
     ValueStack.Push(new InvalidExpression(message));
     return(false);
     //Results.Add(new InvalidExpression(message));
 }
示例#10
0
        private void Reduce(int ruleNumber)
        {
#if TRACE_ACTIONS
            DisplayRule(ruleNumber);
#endif
            Rule rule  = rules[ruleNumber];
            int  rhLen = rule.RightHandSide.Length;
            //
            //  Default actions for unit productions.
            //
            if (rhLen == 1)
            {
                CurrentSemanticValue = ValueStack.TopElement();    // Default action: $$ = $1;
                CurrentLocationSpan  = LocationStack.TopElement(); // Default action "@$ = @1;
            }
            else if (rhLen == 0)
            {
                // Create a new blank value.
                // Explicit semantic action may mutate this value
                CurrentSemanticValue = default(TValue);
                // The location span for an empty production will start with the
                // beginning of the next lexeme, and end with the finish of the
                // previous lexeme.  This gives the correct behaviour when this
                // nonsense value is used in later Merge operations.
                CurrentLocationSpan = (Scanner.yylloc != null && LastSpan != null ?
                                       Scanner.yylloc.Merge(LastSpan) :
                                       default(TSpan));
            }
            else
            {
                // Default action: $$ = $1;
                CurrentSemanticValue = ValueStack[LocationStack.Depth - rhLen];
                //  Default action "@$ = @1.Merge(@N)" for location info.
                TSpan at1 = LocationStack[LocationStack.Depth - rhLen];
                TSpan atN = LocationStack[LocationStack.Depth - 1];
                CurrentLocationSpan =
                    ((at1 != null && atN != null) ? at1.Merge(atN) : default(TSpan));
            }

            DoAction(ruleNumber);

            for (int i = 0; i < rule.RightHandSide.Length; i++)
            {
                StateStack.Pop();
                ValueStack.Pop();
                LocationStack.Pop();
            }
            FsaState = StateStack.TopElement();

            if (FsaState.Goto.ContainsKey(rule.LeftHandSide))
            {
                FsaState = states[FsaState.Goto[rule.LeftHandSide]];
            }

            StateStack.Push(FsaState);
            ValueStack.Push(CurrentSemanticValue);
            LocationStack.Push(CurrentLocationSpan);
        }
示例#11
0
        public static void ClearTest()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            valueStack.Clear();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(3)
                        .And.Count.EqualTo(0)
                        );

            valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            _ = valueStack.Pop();

            valueStack.Push(4);
            valueStack.Clear();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(3)
                        .And.Count.EqualTo(0)
                        );

            valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            _ = valueStack.Pop();

            valueStack.Push(4);
            valueStack.Push(5);

            valueStack.Clear();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(6)
                        .And.Count.EqualTo(0)
                        );

            valueStack = new ValueStack <int>();
            valueStack.Clear();

            Assert.That(() => valueStack,
                        Has.Property("Capacity").EqualTo(0)
                        .And.Count.EqualTo(0)
                        );
        }
示例#12
0
        public static void ContainsTest()
        {
            var valueStack = new ValueStack <int>(new int[] { 1, 2, 3 });

            Assert.That(() => valueStack.Contains(1),
                        Is.True
                        );

            Assert.That(() => valueStack.Contains(4),
                        Is.False
                        );

            _ = valueStack.Pop();
            valueStack.Push(4);

            Assert.That(() => valueStack.Contains(3),
                        Is.False
                        );

            Assert.That(() => valueStack.Contains(4),
                        Is.True
                        );

            _ = valueStack.Pop();
            valueStack.Push(5);
            valueStack.Push(6);

            Assert.That(() => valueStack.Contains(4),
                        Is.False
                        );

            Assert.That(() => valueStack.Contains(5),
                        Is.True
                        );

            Assert.That(() => valueStack.Contains(6),
                        Is.True
                        );

            valueStack = new ValueStack <int>();

            Assert.That(() => valueStack.Contains(0),
                        Is.False
                        );
        }
示例#13
0
        public bool Step(out IExpression result)
        {
            result = null;
            if (processStack.Count <= 0)
            {
                return(false);
            }

            result = processStack.Dequeue();

            switch (result.Type)
            {
            case ExpressionType.Value:
                ValueStack.Push(result as VauleExpression);
                return(true);

            case ExpressionType.Operator:
                return((result as IOperatorExpression).Process(this));

            case ExpressionType.Command:
                if (StepThrough())
                {
                    return((result as IOperatorExpression).Process(this));
                }
                else
                {
                    return(false);
                }

            case ExpressionType.OpenParentheses:
                return(stepTillClose());

            case ExpressionType.CloseParentheses:
                if (depth > 0)
                {
                    return(false);
                }
                else
                {
                    return(Fail("Internal parsing error: Expected opening parentheses."));
                }

            //case ExpressionType.OpenCurlyBraces:
            //curlyDepth = true;
            //return (result as CurlyBracesExpression).Process(this);
            //case ExpressionType.CloseCurlyBraces:
            //if (curlyDepth)
            //{
            //    curlyDepth = false;
            //    return true;
            //}
            //return Fail("Internal parsing error: Was expecting a '{'.");
            default:
                return(false);
            }
        }
示例#14
0
        IBusinessProcess LoadBusinessProcess()
        {
            ValueStack = ValueStackContext.Current.CreateValueStack(_exceptionHandler);
            ValueStack.Push("context", this);
            ValueStack.Push("isTablet", UIDevice.CurrentDevice.Model.Contains("iPad"));

            _configuration = BusinessProcessContext.Current.CreateConfigurationFactory().CreateConfiguration(ValueStack);

            return(BusinessProcessContext.Current.CreateBusinessProcessFactory().CreateBusinessProcess(_configuration.BusinessProcess.File, ValueStack));
        }
示例#15
0
 internal NsScriptThread(uint id, ref CallFrame frame, uint?declaredId = null)
 {
     Id             = id;
     DeclaredId     = declaredId ?? id;
     CallFrameStack = new ValueStack <CallFrame>(4);
     CallFrameStack.Push(ref frame);
     EvalStack   = new ValueStack <ConstantValue>(8);
     EntryModule = frame.Module.Name;
     Process     = null !;
 }
示例#16
0
        /// <summary>
        /// 1値取得
        /// </summary>
        /// <param name="pValueStack">ValueStack</param>
        /// <param name="pValue1">値1</param>
        /// <returns>値1のコピー(pValueStackの先頭にpush済み)</returns>
        protected virtual CalculatorValue Get1Value(ValueStack pValueStack, out CalculatorValue pValue1)
        {
            pValue1 = pValueStack.Pop();

            // pValue1破壊防止のため、身代わりのコピーを作ってスタックに積む
            CalculatorValue newValue = new CalculatorValue(pValue1);

            pValueStack.Push(newValue);
            return(newValue);
        }
示例#17
0
        void StartApplication()
        {
            _commonData.UserId = Dal.UserId;

            ValueStack = ValueStackContext.Current.CreateValueStack(BitBrowserApp.Current.ExceptionHandler);
            ValueStack.Push("context", this);
            ValueStack.Push("common", _commonData);
            ValueStack.Push("isTablet", IsTablet());

            try
            {
                _configuration = BusinessProcessContext.Current.CreateConfigurationFactory().CreateConfiguration(ValueStack);
            }
            catch (ResourceNotFoundException e)
            {
                ReturnToStartMenu(e.FriendlyMessage, e.Report);
                return;
            }

            try
            {
                _businessProcess = BusinessProcessContext.Current.CreateBusinessProcessFactory()
                                   .CreateBusinessProcess(_configuration.BusinessProcess.File, ValueStack);
            }
            catch (ResourceNotFoundException e)
            {
                ReturnToStartMenu(e.FriendlyMessage, e.Report);
                return;
            }

            InitializePushNotifications();

            LoadingProgress = null;

            _loadComplete();
            _loadComplete = null;

            _settings.SetClearCacheDisabled();

            _businessProcess.Start(this);
        }
示例#18
0
        /// <summary>
        /// Main entry point of the Shift-Reduce Parser.
        /// </summary>
        /// <returns>True if parse succeeds, else false for
        /// unrecoverable errors</returns>
        public bool Parse()
        {
            _valueParameterList = new TValue[15]; // added Nate Wallace
            _errorOccured       = false;

            Initialize();       // allow derived classes to instantiate rules, states and nonTerminals

            NextToken = 0;
            FsaState  = states[0];

            StateStack.Push(FsaState);
            ValueStack.Push(CurrentSemanticValue);
            LocationStack.Push(CurrentLocationSpan);

            while (true)
            {
                int action = FsaState.defaultAction;

                if (FsaState.ParserTable != null)
                {
                    if (NextToken == 0)
                    {
                        // We save the last token span, so that the location span
                        // of production right hand sides that begin or end with a
                        // nullable production will be correct.
                        LastSpan  = Scanner.yylloc;
                        NextToken = Scanner.yylex();
                    }

                    if (FsaState.ParserTable.ContainsKey(NextToken))
                    {
                        action = FsaState.ParserTable[NextToken];
                    }
                }

                if (action > 0)         // shift
                {
                    Shift(action);
                }
                else if (action < 0)   // reduce
                {
                    try
                    {
                        Reduce(-action);
                        if (action == -1)       // accept
                        {
                            return(true);
                        }
                    }
                    catch (Exception x)
                    {
                        if (x is AbortException)
                        {
                            return(false);
                        }
                        else if (x is AcceptException)
                        {
                            return(true);
                        }
                        else if (x is ErrorException && !ErrorRecovery())
                        {
                            return(false);
                        }
                        else
                        {
                            throw;  // Rethrow x, preserving information.
                        }
                    }
                }
                else if (action == 0)   // error
                {
                    _tokenOnError    = NextToken;
                    _locationOnError = Scanner.yylloc;
                    if (!ErrorRecovery())
                    {
                        return(false);
                    }
                }
            }
        }
示例#19
0
 public void Message(string message)
 {
     ValueStack.Push(new MessageExpression(message));
 }
示例#20
0
        public bool OpenScreen(String screenName
                               , string controllerName, Dictionary <String
                                                                    , object> parameters = null
                               , bool isBackCommand = false
                               , bool isRefresh     = false)
        {
            try {
                Busy = true;

                _back    = null;
                _forward = null;

                ValueStack = ValueStackContext.Current.CreateValueStack(_exceptionHandler);
                ValueStack.Push("common", _commonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", Dal.Dao);

                foreach (var variable in GlobalVariables)
                {
                    ValueStack.Push(variable.Key, variable.Value);
                }

                if (parameters != null)
                {
                    foreach (KeyValuePair <String, object> item in parameters)
                    {
                        ValueStack.Push(item.Key, item.Value);
                    }
                }

                var newController = BusinessProcessContext.Current.CreateScreenController(controllerName);
                ValueStack.Push("controller", newController);
                screenName = newController.GetView(screenName);

                TabOrderManager.Create(this);

                IStyleSheet styleSheet = StyleSheetContext.Current.CreateStyleSheet();

                Screen scr = (Screen)BusinessProcessContext.Current.CreateScreenFactory().CreateScreen(screenName, ValueStack, newController, styleSheet);

                if (CurrentScreen != null)
                {
                    ((IDisposable)CurrentScreen.Screen).Dispose();
                }
                CurrentScreen = ControlsContext.Current.CreateScreenData(screenName, controllerName, scr);

                ScreenController viewController = new ScreenController(scr.View);

                if (!isRefresh)
                {
                    _controller.SetViewControllers(new UIViewController[] {
                        _controller.TopViewController
                    }, false);

                    if (!isBackCommand)
                    {
                        _controller.PushViewController(viewController, true);
                    }
                    else
                    {
                        _controller.SetViewControllers(new UIViewController[] {
                            viewController,
                            _controller.TopViewController
                        }, false);
                        _controller.PopViewControllerAnimated(true);
                    }
                }
                else
                {
                    _controller.PopViewControllerAnimated(false);
                    _controller.PushViewController(viewController, false);
                }
            } catch (Exception ex) {
                HandleException(ex);
            } finally {
                ControlsContext.Current.ActionHandlerIsBusy   = false;
                ControlsContext.Current.ActionHandlerExIsBusy = false;
                Busy = false;
            }
            return(true);
        }
示例#21
0
        public bool OpenScreen(string screenName, String controllerName
                               , Dictionary <string, object> parameters = null
                               , bool isBackCommand = false
                               , bool isRefresh     = false)
        {
            try
            {
                ControlsContext.Current.ActionHandlerLocker.Acquire();

                LogManager.Logger.ScreenOpening(screenName, controllerName, parameters);

                _baseActivity.ClearNavigationEvents();

                DateTime startLoading = DateTime.Now;

                ValueStack = ValueStackContext.Current.CreateValueStack(BitBrowserApp.Current.ExceptionHandler);
                ValueStack.Push("common", _commonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", Dal.Dao);
                ValueStack.Push("activity", _baseActivity);
                ValueStack.Push("isTablet", IsTablet());

                foreach (var variable in GlobalVariables)
                {
                    ValueStack.Push(variable.Key, variable.Value);
                }

                if (parameters != null)
                {
                    foreach (KeyValuePair <String, object> item in parameters)
                    {
                        ValueStack.Push(item.Key, item.Value);
                    }
                }

                var controller = BusinessProcessContext.Current.CreateScreenController(controllerName);
                ValueStack.SetCurrentController(controller);
                ValueStack.Push("controller", controller);
                screenName = controller.GetView(screenName);

                var imageCashe = new ImageCache(this);
                var scr        = (Screen)BusinessProcessContext.Current.CreateScreenFactory()
                                 .CreateScreen(screenName, ValueStack, controller, imageCashe);
                var currentScreen = ControlsContext.Current.CreateScreenData(screenName, controllerName, scr);

                FlipScreen(scr.View, isBackCommand, isRefresh);

                if (Settings.DevelopModeEnabled)
                {
                    Runtime runtime         = Runtime.GetRuntime();
                    long    usedMemInMb     = (runtime.TotalMemory() - runtime.FreeMemory()) / 1048576L;
                    long    maxHeapSizeInMb = runtime.MaxMemory() / 1048576L;
                    string  memory          = string.Format("{0}/{1}", usedMemInMb, maxHeapSizeInMb);

                    string message = string.Format("{0}\n{1}\n{2}"
                                                   , screenName
                                                   , (DateTime.Now - startLoading).ToString("ss\\.ff")
                                                   , memory);
                    Toast.MakeText(_baseActivity, message, ToastLength.Short).Show();
                }

                ThreadPool.QueueUserWorkItem(Finish, new object[] { CurrentScreen, _currentImageCache });

                CurrentScreen      = currentScreen;
                _currentImageCache = imageCashe;

                return(true);
            }
            catch (Exception e)
            {
                HandleException(e);

                return(false);
            }
        }
示例#22
0
            private bool Execute(ResolvedInstruction inst)
            {
                switch (inst.Operation)
                {
                case Operation.NOP:
                    break;

                case Operation.BRK:
                    return(false);

                case Operation.HLT:
                    Halted = true;
                    return(false);

                case Operation.ADD:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) + ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.INC:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) + 1));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.SUB:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) - ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.DEC:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) - 1));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.MLT:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) * ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.DIV:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) / ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.MOD:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) % ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.CMP:
                    if (inst.Exists(Operand.A) && inst.Exists(Operand.B))
                    {
                        Flags = (ResolveValue(inst[Operand.A]) - ResolveValue(inst[Operand.B]));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.AND:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) & ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.OR:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) | ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.XOR:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) ^ ResolveValue(inst[Operand.C])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.NAND:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (~(ResolveValue(inst[Operand.B]) & ResolveValue(inst[Operand.C]))));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.NOR:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (~(ResolveValue(inst[Operand.B]) | ResolveValue(inst[Operand.C]))));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.XNOR:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (~(ResolveValue(inst[Operand.B]) ^ ResolveValue(inst[Operand.C]))));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.NOT:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], Flags = (~ResolveValue(inst[Operand.B])));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.LSH:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) << 1));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BSL:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) << (int)(ResolveValue(inst[Operand.C]) & 0x7F)));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.RSH:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) >> 1));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BSR:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B) && inst.Exists(Operand.C))
                    {
                        SetRegister(inst[Operand.A], Flags = (ResolveValue(inst[Operand.B]) >> (int)(ResolveValue(inst[Operand.C]) & 0x7F)));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.MOV:
                case Operation.IMM:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], ResolveValue(inst[Operand.B]));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.LOAD:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        var address = ResolveValue(inst[Operand.B]);

                        if (address > (ulong)Host.RAM.LongLength)
                        {
                            throw new InvalidOperationException(this, InvalidOperationException.NotEnoughMemory);
                        }

                        SetRegister(inst[Operand.A], ResolveValue(Host.RAM[address]));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.STORE:
                    if (inst.Exists(Operand.A) && inst.Exists(Operand.B))
                    {
                        var address = ResolveValue(inst[Operand.A]);
                        var value   = ResolveValue(inst[Operand.B]);

                        if (address > (ulong)Host.RAM.LongLength)
                        {
                            throw new InvalidOperationException(this, InvalidOperationException.NotEnoughMemory);
                        }

                        Host.RAM[address] = value;
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.IN:
                    if (inst.IsRegister(Operand.A) && inst.Exists(Operand.B))
                    {
                        SetRegister(inst[Operand.A], Host.IoBus[ResolveValue(inst[Operand.B])]);
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.OUT:
                    if (inst.Exists(Operand.A) && inst.Exists(Operand.B))
                    {
                        Host.IoBus[ResolveValue(inst[Operand.A])] = ResolveValue(inst[Operand.B]);
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.PSH:
                    if (inst.Exists(Operand.A))
                    {
                        ValueStack.Push(ResolveValue(inst[Operand.A]));
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.POP:
                    if (inst.IsRegister(Operand.A))
                    {
                        SetRegister(inst[Operand.A], ValueStack.Pop());
                    }
                    else if (!inst.Exists(Operand.A))
                    {
                        ValueStack.Pop();
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BRA:
                    if (inst.Exists(Operand.A))
                    {
                        InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BRZ:
                    if (inst.Exists(Operand.A))
                    {
                        if (Flags == 0)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BNZ:
                    if (inst.Exists(Operand.A))
                    {
                        if (Flags != 0)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BRC:
                    if (inst.Exists(Operand.A))
                    {
                        if (Flags > Host.BitMask)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BNC:
                    if (inst.Exists(Operand.A))
                    {
                        if (Flags <= Host.BitMask)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BRP:
                    if (inst.Exists(Operand.A))
                    {
                        if (Flags <= long.MaxValue)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BRN:
                    if (inst.Exists(Operand.A))
                    {
                        if (Flags > long.MaxValue)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BEV:
                    if (inst.Exists(Operand.A) && inst.Exists(Operand.B))
                    {
                        if (ResolveValue(inst[Operand.B]) % 2 == 0)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.BOD:
                    if (inst.Exists(Operand.A) && inst.Exists(Operand.B))
                    {
                        if (ResolveValue(inst[Operand.B]) % 2 == 1)
                        {
                            InstructionPointer = ResolveValue(inst[Operand.A]) - 1;
                        }
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.CAL:
                    if (inst.Exists(Operand.A))
                    {
                        CallStack.Push(InstructionPointer);
                        InstructionPointer = ResolveValue(inst[Operand.A]);
                    }
                    else
                    {
                        Invalid();
                    }
                    break;

                case Operation.RET:
                    if (CallStack.Count == 0)
                    {
                        Halted = true;
                        return(false);
                    }
                    else
                    {
                        InstructionPointer = CallStack.Pop();
                    }
                    break;

                case Operation.MINRAM:
                case Operation.BENCHMARK:
                case Operation.COMPILER_CREATELABEL:
                case Operation.COMPILER_MARKLABEL:
                case Operation.COMPILER_MAXREG:
                    break;

                default:
                    Invalid();
                    break;
                }

                InstructionPointer++;
                return(true);
            }
示例#23
0
        /// <summary>
        /// Main entry point of the Shift-Reduce Parser.
        /// </summary>
        /// <returns>True if parse succeeds, else false for
        /// unrecoverable errors</returns>
        public bool Parse()
        {
            Initialize();       // allow derived classes to instantiate rules, states and nonTerminals

            NextToken = 0;
            FsaState  = states[0];

            StateStack.Push(FsaState);
            ValueStack.Push(CurrentSemanticValue);
            LocationStack.Push(CurrentLocationSpan);

            while (true)
            {
#if TRACE_ACTIONS
                Console.Error.WriteLine("Entering state {0} ", FsaState.number);
                DisplayStack();
#endif
                int action = FsaState.defaultAction;

                if (FsaState.ParserTable != null)
                {
                    if (NextToken == 0)
                    {
                        // We save the last token span, so that the location span
                        // of production right hand sides that begin or end with a
                        // nullable production will be correct.
                        LastSpan  = Scanner.yylloc;
                        NextToken = Scanner.yylex();
#if TRACE_ACTIONS
                        Console.Error.WriteLine("Reading: Next token is {0}", TerminalToString(NextToken));
#endif
                    }
#if TRACE_ACTIONS
                    else
                    {
                        Console.Error.WriteLine("Next token is still {0}", TerminalToString(NextToken));
                    }
#endif
                    if (FsaState.ParserTable.ContainsKey(NextToken))
                    {
                        action = FsaState.ParserTable[NextToken];
                    }
                }

                if (action > 0)         // shift
                {
                    Shift(action);
                }
                else if (action < 0)   // reduce
                {
                    try {
                        Reduce(-action);
                        if (action == -1)       // accept
                        {
                            return(true);
                        }
                    }
                    catch (Exception x) {
                        if (x is AbortException)
                        {
                            return(false);
                        }
                        else if (x is AcceptException)
                        {
                            return(true);
                        }
                        else if (x is ErrorException && !ErrorRecovery())
                        {
                            return(false);
                        }
                        else
                        {
                            throw;  // Rethrow x, preserving information.
                        }
                    }
                }
                else if (action == 0)   // error
                {
                    if (!ErrorRecovery())
                    {
                        return(false);
                    }
                }
            }
        }
示例#24
0
 public void AppendTail(int value)
 {
     ValueStack.Push(value);
 }
示例#25
0
        /// <summary>
        /// Reduce.
        /// </summary>
        /// <param name="ruleNumber">The rule to reduce by.</param>
        private void Reduce(int ruleNumber)
        {
            Rule rule = rules[ruleNumber];

            //
            //  Default actions for unit productions.
            //
            if (rule.RightHandSide.Length == 1)
            {
                CurrentSemanticValue = ValueStack.TopElement();    // Default action: $$ = $1;
                CurrentLocationSpan  = LocationStack.TopElement(); // Default action "@$ = @1;
            }
            else
            {
                if (rule.RightHandSide.Length == 0)
                {
                    // Create a new blank value.
                    // Explicit semantic action may mutate this value
                    CurrentSemanticValue = default(TValue);
                    // The location span for an empty production will start with the
                    // beginning of the next lexeme, and end with the finish of the
                    // previous lexeme.  This gives the correct behaviour when this
                    // nonsense value is used in later Merge operations.
                    CurrentLocationSpan = (Scanner.yylloc != null && LastSpan != null ?
                                           Scanner.yylloc.Merge(LastSpan) :
                                           default(TSpan));
                }
                else
                {
                    // Default action: $$ = $1;
                    CurrentSemanticValue = ValueStack.TopElement();
                    //  Default action "@$ = @1.Merge(@N)" for location info.
                    TSpan at1 = LocationStack[LocationStack.Depth - rule.RightHandSide.Length];
                    TSpan atN = LocationStack[LocationStack.Depth - 1];
                    CurrentLocationSpan =
                        ((at1 != null && atN != null) ? at1.Merge(atN) : default(TSpan));
                }
            }

            DoAction(ruleNumber);

            for (int i = rule.RightHandSide.Length - 1; i >= 0; i--)
            {
                _valueParameterList[i] = ValueStack.Pop(); // capture the values - added by Nate Wallace
                StateStack.Pop();
                LocationStack.Pop();
            }

            if (!_errorOccured)
            {
                ProcessReduce(rule.LeftHandSide, _valueParameterList, rule.RightHandSide.Length); // process the reduce action - added by Nate Wallace
            }
            else
            {
                _errorOccured = false;
            }

            FsaState = StateStack.TopElement();

            if (FsaState.Goto.ContainsKey(rule.LeftHandSide))
            {
                FsaState = states[FsaState.Goto[rule.LeftHandSide]];
            }

            StateStack.Push(FsaState);
            ValueStack.Push(CurrentSemanticValue);
            LocationStack.Push(CurrentLocationSpan);
        }
示例#26
0
        public bool OpenScreen(String screenName
                               , string controllerName, Dictionary <String
                                                                    , object> parameters = null
                               , bool isBackCommand = false
                               , bool isRefresh     = false)
        {
            IDisposable rootControl = null;

            try
            {
                Busy = true;

                LogManager.Logger.ScreenOpening(screenName, controllerName, parameters);

                _back    = null;
                _forward = null;

                ValueStack = ValueStackContext.Current.CreateValueStack(_exceptionHandler);
                ValueStack.Push("common", CommonData);
                ValueStack.Push("context", this);
                ValueStack.Push("dao", Dal.Dao);
                ValueStack.Push("isTablet", UIDevice.CurrentDevice.Model.Contains("iPad"));

                foreach (var variable in GlobalVariables)
                {
                    ValueStack.Push(variable.Key, variable.Value);
                }

                if (parameters != null)
                {
                    foreach (var item in parameters)
                    {
                        ValueStack.Push(item.Key, item.Value);
                    }
                }

                IScreenController newController = BusinessProcessContext.Current.CreateScreenController(controllerName);
                ValueStack.SetCurrentController(newController);
                ValueStack.Push("controller", newController);
                screenName = newController.GetView(screenName);

                TabOrderManager.Create(this);

                var scr =
                    (Screen)
                    BusinessProcessContext.Current.CreateScreenFactory()
                    .CreateScreen(screenName, ValueStack, newController, null);

                rootControl   = RootControl;
                CurrentScreen = ControlsContext.Current.CreateScreenData(screenName, controllerName, scr);

                var viewController = new ScreenController(scr.View);

                if (!isRefresh)
                {
                    _controller.SetViewControllers(new[]
                    {
                        _controller.TopViewController
                    }, false);

                    if (!isBackCommand)
                    {
                        _controller.PushViewController(viewController, true);
                    }
                    else
                    {
                        _controller.SetViewControllers(new[]
                        {
                            viewController,
                            _controller.TopViewController
                        }, false);
                        _controller.PopViewControllerAnimated(true);
                    }
                }
                else
                {
                    _controller.PopViewControllerAnimated(false);
                    _controller.PushViewController(viewController, false);
                }
            }
            catch (Exception ex)
            {
                HandleException(ex);
            }
            finally
            {
                LogManager.Logger.ScreenOpened();

                if (rootControl != null)
                {
                    rootControl.Dispose();
                }

                GC.Collect();

                ControlsContext.Current.ActionHandlerLocker.Release();
                Busy = false;
            }
            return(true);
        }