public override void Eval(EvaluatorState ev) { //Console.WriteLine(this.ToString()); // returnning from a function = going one run level up ev.DecreaseRunLevel(); // free all localy created data (==GBC==) // -- not needed -- // restore stack pointer ev.Stack.StackTop = ev.RegFP; // get old FP value IValue oldFPValue = ev.Stack.ReadTop(); ev.Stack.Pop(); if (oldFPValue.TypeOf() == ValueTypeID.TYPE_STFP) { ev.RegFP = oldFPValue.GetIntValue(); } else { throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPESTFP)); } }
/// <summary> /// <see cref="ICondition.Evaluate" /> /// </summary> public bool Evaluate() { try{ switch (_equationtype) { case EquationType.EQ: return(_leftValue.GetIntValue() == _rightValue.GetIntValue()); case EquationType.GR: return(_leftValue.GetIntValue() > _rightValue.GetIntValue()); case EquationType.LT: return(_leftValue.GetIntValue() < _rightValue.GetIntValue()); case EquationType.GREQ: return(_leftValue.GetIntValue() >= _rightValue.GetIntValue()); case EquationType.LTEQ: return(_leftValue.GetIntValue() <= _rightValue.GetIntValue()); case EquationType.STREQ: return(_leftValue.GetStringValue().Equals(_rightValue.GetStringValue())); case EquationType.CONT: return((_leftValue.GetStringValue().Contains(_rightValue.GetStringValue()) && !_rightValue.GetStringValue().Equals(string.Empty)) || (_rightValue.GetStringValue().Contains(_leftValue.GetStringValue()) && !_leftValue.GetStringValue().Equals(string.Empty))); case EquationType.STRCONT: return((_leftValue.GetStringValue().Contains(_rightValue.GetStringValue()) && !_rightValue.GetStringValue().Equals(string.Empty))); default: return(false); } } catch (Exception) { return(false); } }
private IValue DoOperation(IValue a, IValue b, TokenID variation) { switch (variation) { case TokenID.T_ASSIGN_OP: // a = b return(b); case TokenID.T_ADD_ASSIGN_OP: // a += b // is it a numeric operation or a string concatenation? if (a.TypeOf() != ValueTypeID.TYPE_STRING && b.TypeOf() != ValueTypeID.TYPE_STRING) { return(new NumericValue(a.GetNumericValue() + b.GetNumericValue())); } else { return(new StringValue(a.GetStringValue() + b.GetStringValue())); } case TokenID.T_SUB_ASSIGN_OP: // a -= b return(new NumericValue(a.GetNumericValue() - b.GetNumericValue())); case TokenID.T_MUL_ASSIGN_OP: // a *= b return(new NumericValue(a.GetNumericValue() * b.GetNumericValue())); case TokenID.T_DIV_ASSIGN_OP: // a /= b (allways real-number op.) double bn = b.GetNumericValue(); // do not divide by zero! if (bn == 0.0) { throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_DIVZERO)); } return(new NumericValue(a.GetNumericValue() / bn)); case TokenID.T_MOD_ASSIGN_OP: // a %= b int bi = b.GetIntValue(); // do not divide by zero! if (bi == 0) { throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_DIVZERO)); } int ai = a.GetIntValue(); return(new NumericValue((double)(ai % bi))); case TokenID.T_POW_ASSIGN_OP: // a **= b return(new NumericValue(Math.Pow(a.GetNumericValue(), b.GetNumericValue()))); case TokenID.T_STRCAT_ASSIGN_OP: // a ..= b return(new StringValue(a.GetStringValue() + b.GetStringValue())); default: throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_BADSTOREOPERATIONOP)); } }
public override void Eval(EvaluatorState ev) { // Console.WriteLine(this.ToString()); // second operand is in R IValue b = ev.GetVal(); int bi = b.GetIntValue(); // do not divide by zero! if (bi == 0) { throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_DIVZERO)); } // first operand IValue a = ev.GetStackTopVal(); ev.Stack.Pop(); // pop a int ai = a.GetIntValue(); ev.RegR = new NumericValue((double)(ai / bi)); }