Пример #1
0
        public Term PerformOperation(Executer exec, Operator op, Term otherTerm)
        {
            //these should be in Types.Object really...
            Types.Object oThis = null;

            //TODO: if it's already been evaluated this time, no need to do it again!
            if (this.Expression != null)
            {
                this.Value = this.Expression.Evaluate(exec);
            }

            oThis = this.Value;

            Types.Object oOther = null;
            if (otherTerm != null)
            {
                //TODO: if it's already been evaluated this time, no need to do it again!
                if (otherTerm.Expression != null)
                {
                    otherTerm.Value = otherTerm.Expression.Evaluate(exec);
                }

                oOther = otherTerm.Value;
            }

            //Here's the bad one: can't well set Value - what about next execution?? E.g. if it was a Variable??
            //this.Value = oThis.PerformOperation(exec, op, oOther);
            //return this.Value;
            Term tNew = new Term();

            tNew.Value = oThis.PerformOperation(exec, op, oOther);
            return(tNew);
        }
Пример #2
0
        public Term PerformOperation(Executer exec, Operator op, Term otherTerm)
        {
            //these should be in Types.Object really...
            Types.Object oThis = null;

            //TODO: if it's already been evaluated this time, no need to do it again!
            if (this.Expression!=null)
                this.Value = this.Expression.Evaluate(exec);

            oThis = this.Value;

            Types.Object oOther = null;
            if (otherTerm!=null)
            {
                //TODO: if it's already been evaluated this time, no need to do it again!
                if (otherTerm.Expression!=null)
                    otherTerm.Value = otherTerm.Expression.Evaluate(exec);

                oOther = otherTerm.Value;
            }

            //Here's the bad one: can't well set Value - what about next execution?? E.g. if it was a Variable??
            //this.Value = oThis.PerformOperation(exec, op, oOther);
            //return this.Value;
            Term tNew = new Term();
            tNew.Value = oThis.PerformOperation(exec, op, oOther);
            return tNew;
        }
Пример #3
0
        public Types.Object Evaluate(Executer exec)
        {
            //when an operator has been applied to two terms, other operators that involve
            //any of those terms must use the result of that operation.
            //So, keep a list of pointers that point to the resulting terms.
            Hashtable htTermPointers = new Hashtable();

            for (int i = 0; i < this.m_aChunks.Count; i++)
            {
                ArrayList a = new ArrayList();
                a.Add(i);
                htTermPointers.Add(i, a);
            }

            if (this.m_slCalcOrder == null)             //don't why this should happen, though...
            {
                this.ArrangeOpsInExecutionOrder();
            }

            //ArrayList aChunksCopy = new ArrayList();
            ArrayList aChunksCopy = (ArrayList)this.m_aChunks.Clone();

            Term t1   = null;
            Term tNew = null;

            for (int i = 0; i < this.m_slCalcOrder.Count; i++)
            {
                OperatorAndTerms opt       = (OperatorAndTerms)this.m_slCalcOrder.GetByIndex(i);
                ArrayList        aTerm1Ptr = (ArrayList)htTermPointers[opt.Term1Index];
                ArrayList        aTerm2Ptr = null;

                t1 = (Term)aChunksCopy[(int)aTerm1Ptr[0]];                 //this.m_aChunks
                Term t2 = null;
                if (opt.Term2Index > 0)
                {
                    aTerm2Ptr = (ArrayList)htTermPointers[opt.Term2Index];
                    t2        = (Term)aChunksCopy[(int)aTerm2Ptr[0]];              //this.m_aChunks
                }

                //now we've got the term(s). Perform the operation
                tNew = t1.PerformOperation(exec, opt.Op, t2);
                aChunksCopy[(int)aTerm1Ptr[0]] = tNew;

                //if there's a second term, change the pointer to it to the first term instead
                //so that successive operations use the result of this operation instead of the inital value
                if (t2 != null)
                {
                    //aTerm2Ptr = (ArrayList)htTermPointers[opt.Term2Index];
                    //aTerm2Ptr[0] = opt.Term1Index;
                    //htTermPointers[opt.Term1Index] = aTerm2Ptr;
                    htTermPointers[opt.Term2Index] = aTerm1Ptr;
                }
            }

            //NOPE - no restoring, we've still got the originals (after rewrite):
            //Always restore directly after execution, making it ready for next execution:
            Types.Object o = tNew.Value;             // t1.Value;
            //this.Restore();

            return(o);
        }
Пример #4
0
 public void ConvertToMethod()
 {
     this.m_sTerm += "()";           //mark as a function for next round of execution (after Restore)
     this.Value    = ((Variable)this.Value).ToMethod();
 }
Пример #5
0
 public void ConvertToMethod()
 {
     this.m_sTerm+="()"; //mark as a function for next round of execution (after Restore)
     this.Value = ((Variable)this.Value).ToMethod();
 }