예제 #1
0
 public static void ProcesarVariable(ref IVariableHardware vHrd, byte[] var)
 {
     if (vHrd is VariableDigital <bool> )
     {
         ((VariableDigital <bool>)vHrd).Valor = Convertir.Booleano(var[3], (int)ValorBooleano.Verdadero);
     }
     else if (vHrd is VariableAnaloga)
     {
         ((VariableAnaloga)vHrd).Valor = Globales.ObtenerValor(var[2], var[3]);
     }
     else if (vHrd is VariableEncoder)
     {
         VariableEncoder enc = (VariableEncoder)vHrd;
         if (Convertir.Booleano(var[2], (int)ValorBooleano.Verdadero))
         {
             enc.Incrementar((var[3] - 0x20));
         }
         else if (var[2] == (byte)ValorBooleano.Falso)
         {
             enc.Decrementar((var[3] - 0x20));
         }
     }
 }
예제 #2
0
        internal void CompileExpression(ParserContext parser, ByteBuffer buffer, Expression expr, bool outputUsed)
        {
            if (expr is FunctionCall)
            {
                FunctionCallEncoder.Compile(this, parser, buffer, (FunctionCall)expr, outputUsed);
            }
            else if (expr is IntegerConstant)
            {
                ConstantEncoder.CompileInteger(parser, buffer, (IntegerConstant)expr, outputUsed);
            }
            else if (expr is Variable)
            {
                VariableEncoder.Compile(parser, buffer, (Variable)expr, outputUsed);
            }
            else if (expr is BooleanConstant)
            {
                ConstantEncoder.CompileBoolean(parser, buffer, (BooleanConstant)expr, outputUsed);
            }
            else if (expr is DotField)
            {
                DotFieldEncoder.Compile(this, parser, buffer, (DotField)expr, outputUsed);
            }
            else if (expr is BracketIndex)
            {
                BracketIndexEncoder.Compile(this, parser, buffer, (BracketIndex)expr, outputUsed);
            }
            else if (expr is OpChain)
            {
                OpChainEncoder.Compile(this, parser, buffer, (OpChain)expr, outputUsed);
            }
            else if (expr is StringConstant)
            {
                ConstantEncoder.CompileString(parser, buffer, (StringConstant)expr, outputUsed);
            }
            else if (expr is NegativeSign)
            {
                NegativeSignEncoder.Compile(this, parser, buffer, (NegativeSign)expr, outputUsed);
            }
            else if (expr is ListDefinition)
            {
                ListDefinitionEncoder.Compile(this, parser, buffer, (ListDefinition)expr, outputUsed);
            }
            else if (expr is Increment)
            {
                IncrementEncoder.Compile(this, parser, buffer, (Increment)expr, outputUsed);
            }
            else if (expr is FloatConstant)
            {
                ConstantEncoder.CompileFloat(parser, buffer, (FloatConstant)expr, outputUsed);
            }
            else if (expr is NullConstant)
            {
                ConstantEncoder.CompileNull(parser, buffer, (NullConstant)expr, outputUsed);
            }
            else if (expr is ThisKeyword)
            {
                ThisEncoder.Compile(parser, buffer, (ThisKeyword)expr, outputUsed);
            }
            else if (expr is Instantiate)
            {
                InstantiateEncoder.Compile(this, parser, buffer, (Instantiate)expr, outputUsed);
            }
            else if (expr is DictionaryDefinition)
            {
                DictionaryDefinitionEncoder.Compile(this, parser, buffer, (DictionaryDefinition)expr, outputUsed);
            }
            else if (expr is BooleanCombination)
            {
                BooleanCombinationEncoder.Compile(this, parser, buffer, (BooleanCombination)expr, outputUsed);
            }
            else if (expr is BooleanNot)
            {
                BooleanNotEncoder.Compile(this, parser, buffer, (BooleanNot)expr, outputUsed);
            }
            else if (expr is Cast)
            {
                CastEncoder.Compile(this, parser, buffer, (Cast)expr, outputUsed);
            }
            else if (expr is Ternary)
            {
                TernaryEncoder.Compile(this, parser, buffer, (Ternary)expr, outputUsed);
            }
            else if (expr is ListSlice)
            {
                ListSliceEncoder.Compile(this, parser, buffer, (ListSlice)expr, outputUsed);
            }
            else if (expr is NullCoalescer)
            {
                NullCoalescerEncoder.Compile(this, parser, buffer, (NullCoalescer)expr, outputUsed);
            }
            else if (expr is BaseMethodReference)
            {
                BaseMethodReferenceEncoder.Compile(parser, buffer, (BaseMethodReference)expr, outputUsed);
            }
            else if (expr is FunctionReference)
            {
                FunctionReferenceEncoder.Compile(parser, buffer, (FunctionReference)expr, outputUsed);
            }
            else if (expr is FieldReference)
            {
                FieldReferenceEncoder.Compile(parser, buffer, (FieldReference)expr, outputUsed);
            }
            else if (expr is CoreFunctionInvocation)
            {
                CoreFunctionInvocationEncoder.Compile(this, parser, buffer, (CoreFunctionInvocation)expr, null, null, outputUsed);
            }
            else if (expr is IsComparison)
            {
                IsComparisonEncoder.Compile(this, parser, buffer, (IsComparison)expr, outputUsed);
            }
            else if (expr is ClassReferenceLiteral)
            {
                ClassReferenceEncoder.Compile(parser, buffer, (ClassReferenceLiteral)expr, outputUsed);
            }
            else if (expr is Lambda)
            {
                LambdaEncoder.Compile(this, parser, buffer, (Lambda)expr, outputUsed);
            }
            else if (expr is PrimitiveMethodReference)
            {
                DotFieldEncoder.Compile(this, parser, buffer, (PrimitiveMethodReference)expr, outputUsed);
            }

            // The following parse tree items must be removed before reaching the byte code encoder.
            else if (expr is BaseKeyword)
            {
                this.CompileBaseKeyword(parser, buffer, (BaseKeyword)expr, outputUsed);
            }
            else if (expr is CompileTimeDictionary)
            {
                this.CompileCompileTimeDictionary((CompileTimeDictionary)expr);
            }


            else
            {
                throw new NotImplementedException();
            }
        }