Пример #1
0
        /// <summary>
        /// Returns the address of the variable, given its id
        /// </summary>
        public override void Execute()
        {
            Variable toret = null;
            long address = 0;
            var vble = this.Machine.TDS.LookUp( this.Id.Name );

            if ( vble != null ) {
                toret = new TempVariable( this.Machine.TypeSystem.GetIntType() );
                var vbleAsRef = vble as RefVariable;
                address = vble.Address;

                // If the vble at the right is a reference, dereference it
                if ( vbleAsRef != null  ) {
                    address = vbleAsRef.PointedVble.Address;
                }

                // Store in the temp vble and end
                toret.LiteralValue = new IntLiteral( this.Machine, address );
                this.Machine.ExecutionStack.Push( toret );
            } else {
                throw new EngineException( "lvalue should be a variable" );
            }

            return;
        }
Пример #2
0
        public override void Execute(RValue[] realParams)
        {
            var result = new TempVariable( this.Machine.TypeSystem.GetIntType() );
            result.LiteralValue = new IntLiteral( this.Machine, 0 );

            this.Machine.ExecutionStack.Push( result );
        }
Пример #3
0
        public override void Execute(RValue[] realParams)
        {
            long address = this.Machine.Memory.Max;
            Variable vble = this.Machine.TDS.SolveToVariable( realParams[ 0 ] );
            var ptrVble = vble as PtrVariable;

            if ( ptrVble != null ) {
                address = ptrVble.IntValue.Value;
            }
            else
            if ( vble.Type == this.Machine.TypeSystem.GetIntType() ) {
                address = (long) vble.LiteralValue.Value;
            }
            else {
                throw new TypeMismatchException(
                    L18n.Get( L18n.Id.LblPointer ).ToLower()
                    + " (" + L18n.Get( L18n.Id.ErrNotAPointer )
                    + ": " + this.Id + ")"
                    );
            }

            this.Machine.TDS.DeleteBlk( address );

            Variable result = new TempVariable( Machine.TypeSystem.GetIntType() );
            result.LiteralValue = new IntLiteral( this.Machine, 0 );
            this.Machine.ExecutionStack.Push( result );
        }
Пример #4
0
        public override void Execute(RValue[] realParams)
        {
            Variable param = this.Machine.TDS.SolveToVariable( realParams[ 0 ] );
            int valueFromStr = Convert.ToInt32( param.LiteralValue.Value );
            Variable result = new TempVariable( this.Machine.TypeSystem.GetIntType() );
            result.LiteralValue = new IntLiteral( this.Machine, valueFromStr );

            this.Machine.ExecutionStack.Push( result );
        }
Пример #5
0
        public override void Execute(RValue[] realParams)
        {
            var result = new TempVariable( this.Machine.TypeSystem.GetIntType() );
            result.LiteralValue = new IntLiteral(
                this.Machine,
                Convert.ToInt64( Math.Ceiling( DateTime.Now.TimeOfDay.TotalSeconds ) ) );

            this.Machine.ExecutionStack.Push( result );
        }
Пример #6
0
        public override void Execute(RValue[] realParams)
        {
            Variable param = this.Machine.TDS.SolveToVariable( realParams[ 0 ] );

            if ( !( param.Type.IsArithmetic() ) ) {
                throw new TypeMismatchException( param.ToString() );
            }

            double value = Convert.ToDouble( param.LiteralValue.Value );
            Variable result = new TempVariable( this.Machine.TypeSystem.GetDoubleType() );
            result.LiteralValue = new DoubleLiteral( this.Machine, Math.Floor( value ) );
            this.Machine.ExecutionStack.Push( result );
        }
Пример #7
0
        /// <summary>
        /// Returns the result of a - b
        /// </summary>
        public override void Execute()
        {
            // Check arguments in stack
            if ( this.Machine.ExecutionStack.Count < 2 ) {
                throw new EngineException( L18n.Get( L18n.Id.ErrMissingArguments ) );
            }

            // Take ops
            Variable op1 = this.Machine.TDS.SolveToVariable( this.Machine.ExecutionStack.Pop() );
            Variable op2 = this.Machine.TDS.SolveToVariable( this.Machine.ExecutionStack.Pop() );

            // Check ops
            if ( op1 == null
                || !( op1.Type.IsArithmetic() ) )
            {
                throw new TypeMismatchException( ": op1" );
            }

            if ( op2 == null
                || !( op2.Type.IsArithmetic() ) )
            {
                throw new TypeMismatchException( ": op2" );
            }

            // If the operands are references, dereference it
            var refOp1 = op1 as RefVariable;
            var refOp2 = op2 as RefVariable;

            if ( refOp1 != null ) {
                op1 = refOp1.PointedVble;
            }

            if ( refOp2 != null ) {
                op2 = refOp2.PointedVble;
            }

            // Now yes, do it
            long op1Value = ( (long) op1.LiteralValue.Value );

            if ( op1Value == 0 ) {
                throw new EngineException( "/0??" );
            }

            long divRes = ( (long) op2.LiteralValue.Value ) / op1Value;

            // Store in the temp vble and end
            Variable result = new TempVariable( new IntLiteral( this.Machine, divRes ) );
            this.Machine.ExecutionStack.Push( result );
            return;
        }
Пример #8
0
        public override void Execute(RValue[] realParams)
        {
            Variable x = this.Machine.TDS.SolveToVariable( realParams[ 0 ] );
            Variable result = new TempVariable( this.Machine.TypeSystem.GetIntType() );

            if ( !( x.Type.IsArithmetic() ) ) {
                throw new TypeMismatchException( x.LiteralValue.ToString() + "?" );
            }

            result.LiteralValue = new IntLiteral(
                                    this.Machine,
                                    Math.Abs( Convert.ToInt64( x.LiteralValue.Value ) )
            );
            this.Machine.ExecutionStack.Push( result );
        }
Пример #9
0
        /// <summary>
        /// Solves the rvalue to a variable.
        /// </summary>
        /// <returns>A variable, being a TempVariable or a true one.</returns>
        /// <param name="rvalue">The rvalue to be solved.</param>
        public Variable SolveToVariable(RValue rvalue)
        {
            Variable toret = null;
            var lit = rvalue as Literal;
            var id = rvalue as Id;
            var vble = rvalue as Variable;

            if ( lit != null ) {
                // Plain value
                toret = new TempVariable( lit );
            }
            else
            if ( id != null ) {
                toret = this.LookUp( id.Name );
            }
            else
            if ( vble != null ) {
                toret = vble;
            }

            return toret;
        }
Пример #10
0
        /// <summary>
        /// Returns the variable pointed by the pointer variable, or a
        /// temporary variable for that address.
        /// </summary>
        /// <returns>A temporary or a true variable</returns>
        /// <param name="ptrVble">A PtrVariable object.</param>
        public Variable GetPointedValueAsVariable(PtrVariable ptrVble)
        {
            Variable toret = this.LookForAddress( ptrVble.IntValue );

            if ( toret == null
              || toret.GetTargetType() != ptrVble.AssociatedType )
            {
                toret = new TempVariable( ptrVble.AssociatedType );
                toret.Address = ptrVble.IntValue.Value;
                toret.LiteralValue = new IntLiteral( this.machine, ptrVble.Access );
            }

            return toret;
        }