Exemplo n.º 1
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 );
        }
Exemplo n.º 2
0
        public override void Execute(RValue[] realParams)
        {
            Variable param = this.Machine.TDS.SolveToVariable( realParams[ 0 ] );

            if ( param.Type != this.Machine.TypeSystem.GetIntType() ) {
                throw new TypeMismatchException( param.Name.Name );
            }

            this.Machine.SetRandomEngine( (long) param.LiteralValue.Value );
            this.Machine.ExecutionStack.Push( new TempVariable( this.Machine.TypeSystem.GetIntType() ) );
        }
Exemplo n.º 3
0
        public override void Execute(RValue[] realParams)
        {
            Variable size = this.Machine.TDS.SolveToVariable( realParams[ 0 ] );

            Variable result = this.Machine.TDS.AddVector(
                                new Id( SymbolTable.GetNextMemoryBlockName() ),
                                CSim.Core.Types.Any.Get(),
                                (long) size.LiteralValue.Value
            );

            this.Machine.ExecutionStack.Push( result );
        }
Exemplo n.º 4
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 );
        }
Exemplo n.º 5
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 );
        }
Exemplo n.º 6
0
        /// <summary>
        /// Executes the function call.
        /// </summary>
        public override void Execute()
        {
            Function f = this.Machine.API.Match( this.Id );

            if ( f != null ) {
                // Take params
                RValue[] args = new RValue[ f.FormalParams.Count ];

                if ( this.Machine.ExecutionStack.Count < args.Length ) {
                    throw new EngineException(
                        L18n.Get( L18n.Id.ErrMissingArguments ) + ": " + this.Id
                    );
                }

                for(int i = args.Length - 1; i >= 0; --i) {
                    args[ i ] = this.Machine.TDS.SolveToVariable( this.Machine.ExecutionStack.Pop() );
                }

                // Check types
                for(int i = 0; i < args.Length; ++i) {
                    CSim.Core.Type t1 = args[ i ].Type;
                    CSim.Core.Type t2 = f.FormalParams[ i ].Type;

                    if ( !t1.IsCompatibleWith( t2 ) ) {
                        throw new TypeMismatchException(
                            string.Format( L18n.Get( L18n.Id.ErrParamType ),
                                i,
                                f.FormalParams[ i ].Name.Name,
                                id,
                                t2.ToString(),
                                t1.ToString()
                            ));
                    }
                }

                // Execute
                f.Execute( args );
            }

            return;
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
 /// <summary>
 /// Execute the function with the specified realParams.
 /// </summary>
 /// <param name="realParams">Real parameters, as a primitive argument collection.</param>
 public abstract void Execute(RValue[] realParams);
Exemplo n.º 9
0
 public void Push(RValue op)
 {
     this.stack.Add( op );
 }