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 ); }
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() ) ); }
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 ); }
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 ); }
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 ); }
/// <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; }
/// <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; }
/// <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);
public void Push(RValue op) { this.stack.Add( op ); }