Example #1
0
 public override void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression)
 {
     symbol.CompileGet(compiler);
     expression.Compile(compiler);
     compiler.Binary.WriteSHR();
     symbol.CompileSet(compiler);
 }
Example #2
0
 public sunConstantSymbol(string name, sunExpression expression)
     : base(name)
 {
     if (expression == null)
     {
         throw new ArgumentNullException("expression");
     }
     mExpression = expression;
 }
Example #3
0
        public sunConstantSymbol DeclareConstant(string name, sunExpression expression)
        {
            if (GetIsDeclared(name))
            {
                return(null);
            }
            var symbol = new sunConstantSymbol(name, expression);

            mStorables.Add(symbol);
            return(symbol);
        }
Example #4
0
        sunConstantSymbol DeclareConstant(sunIdentifier node, sunExpression expression, sunSymbolModifiers modifiers)
        {
            var local  = (modifiers & sunSymbolModifiers.Local) != 0;
            var name   = MangleSymbolName(node.Value, node.Location.ScriptId, false, local);
            var symbol = Scopes.DeclareConstant(name, expression);

            if (symbol == null)
            {
                throw new sunRedeclaredVariableException(node);
            }
            return(symbol);
        }
Example #5
0
        static sunExpressionFlags AnalyzeExpression(sunContext context, sunExpression expression)
        {
            var flags = sunExpressionFlags.None;

            foreach (var operand in expression.OfType <sunOperand>())
            {
                var term = operand.Term as sunTerm;
                if (term != null)
                {
                    flags |= term.GetExpressionFlags(context);
                }
            }
            return(flags);
        }
Example #6
0
        static void CompileExpression(sunCompiler compiler, sunExpression expression, Stack <sunOperator> operatorStack)
        {
            var stackCount = operatorStack.Count;

            foreach (var node in expression)
            {
                if (node is sunOperand)
                {
                    var operand = node as sunOperand;

                    // term
                    var term = operand.Term;
                    if (term is sunExpression)
                    {
                        CompileExpression(compiler, term as sunExpression, operatorStack);
                    }
                    else
                    {
                        term.Compile(compiler);
                    }
                    var unaryOperators = operand.UnaryOperators;
                    if (unaryOperators != null)
                    {
                        unaryOperators.Compile(compiler);
                    }
                }
                else if (node is sunOperator)
                {
                    var operatorNode = node as sunOperator;
                    while (operatorStack.Count > stackCount &&
                           (operatorNode.IsLeftAssociative && operatorNode.Precedence <= operatorStack.Peek().Precedence) ||
                           (operatorNode.IsRightAssociative && operatorNode.Precedence < operatorStack.Peek().Precedence))
                    {
                        operatorStack.Pop().Compile(compiler);
                    }
                    operatorStack.Push(operatorNode);
                }
            }
            while (operatorStack.Count > stackCount)
            {
                operatorStack.Pop().Compile(compiler);
            }
        }
Example #7
0
 public sunConstantSymbol DeclareConstant(string name, sunExpression expression)
 {
     return(Top.DeclareConstant(name, expression));
 }
Example #8
0
 public virtual void Compile(sunCompiler compiler, sunStorableSymbol symbol, sunExpression expression)
 {
     expression.Compile(compiler);
     symbol.CompileSet(compiler);
 }