Пример #1
0
        private bool ParseNotExpression(TokenReader reader, out Expression expression)
        {
            expression = null;
            Token start = reader.Peek();
            if (!this.Expect(reader, Keyword.Not))
            {
                return false;
            }

            Expression inner = null;
            if (!this.ParseFactorExpression(reader, out inner))
            {
                return false;
            }

            expression = new NotExpression(start, inner);
            return true;
        }
Пример #2
0
        private bool TryEmitNotExpression(
            NotExpression expression, 
            CompilerContext context, 
            Scope scope, 
            MethodImpl method, 
            out TypeDefinition valueType)
        {
            if (!this.TryEmitExpression(expression.Inner, context, scope, method, out valueType))
            {
                return false;
            }

            if (valueType.IsPointer || valueType.IsClass || valueType.IsArray || valueType.IsInterface || valueType.IsFloatingPoint
                || valueType.Size > 4)
            {
                string message = string.Format(
                    System.Globalization.CultureInfo.CurrentCulture,
                    Properties.Resources.CodeGenerator_NotNotSupported,
                    valueType.FullName);
                this.log.Write(new Message(
                    expression.Start.Path,
                    expression.Start.Line,
                    expression.Start.Column,
                    Severity.Error,
                    message));
                return false;
            }
            else
            {
                switch (valueType.Size)
                {
                    case 4:
                        method.Statements.Add(new AsmStatement { Instruction = "not eax" });
                        break;
                    case 2:
                        method.Statements.Add(new AsmStatement { Instruction = "not ax" });
                        break;
                    case 1:
                        method.Statements.Add(new AsmStatement { Instruction = "not al" });
                        break;
                }

                if (string.CompareOrdinal(valueType.MangledName, "f") == 0)
                {
                    method.Statements.Add(new AsmStatement { Instruction = "and al,1" });
                }
            }

            return true;
        }