Exemple #1
0
        public override void Eval(EvaluatorState ev)
        {
            //Console.WriteLine(this.ToString());

            // index is in R
            IValue keyValue = ev.GetVal();

            // get table (it is on the stack[top])
            IValue tableValue = ev.GetStackTopVal();

            ev.Stack.Pop();

            // for array returns ptr to array[index] as TYPE_TABLEDATAREF
            // else raises an error
            if (tableValue.TypeOf() == ValueTypeID.TYPE_TABLEREF)
            {
                string         key   = keyValue.GetStringValue();
                ValueTable     table = (ValueTable)tableValue.GetObjectValue();
                ValueTableItem vti   = table.Search(key);
                if (vti == null)
                {
                    vti = table.Insert(key, new UndefinedValue());
                }

                ev.RegR = new TableDataRefValue(vti);
            }
            else
            {
                throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPETABLEREF));
            }
        }
Exemple #2
0
        /*
         * O_NEXT
         * sp:   unchanged
         * in:   S[top-1] = arrayref
         * out:  R = arrayref[arrayref->cindex];
         * op:   if (arrayref->cindex >= arrayref->size) {
         *        R = END-OF-READ;
         *      }
         *      else {
         *        R = arrayref[arrayref->cindex]; arrayref->cindex++;
         *      }
         */

        public override void Eval(EvaluatorState ev)
        {
            //Console.WriteLine(this.ToString());

            // get the array reference
            IValue tableValue = ev.Stack.ReadN(ev.Stack.StackTop - 1);

            // work with arrays only
            if (tableValue.TypeOf() == ValueTypeID.TYPE_TABLEREF)
            {
                ValueTable table = (ValueTable)tableValue.GetObjectValue();

                ValueTableItem vti = table.Next();
                if (vti == null)
                {
                    ev.RegR = new DoneValue();
                }
                else
                {
                    ev.RegR = new TableDataRefValue(vti); // should be TYPE_STOREREF?
                }
            }
            else
            {
                //Console.WriteLine(">> nextop tableval.type = {0}", tableValue.TypeOf().ToString());
                throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPETABLEREF));
            }
        }
Exemple #3
0
        /*
         * O_NEXT_KEY
         * sp:   unchanged
         * in:   S[top-2] = arrayref
         * out:  R = arrayref->cindex
         * op:   if (arrayref->cindex >= arrayref->size) {
         *        R = END-OF-READ;
         *      }
         *      else {
         *        R = arrayref->cindex; arrayref->cindex++;
         *      }
         */

        public override void Eval(EvaluatorState ev)
        {
            //Console.WriteLine(this.ToString());

            // get the array reference
            IValue tableValue = ev.Stack.ReadN(ev.Stack.StackTop - 2);

            // work with arrays only
            if (tableValue.TypeOf() == ValueTypeID.TYPE_TABLEREF)
            {
                ValueTable table = (ValueTable)tableValue.GetObjectValue();

                ValueTableItem vti = table.Next();
                if (vti == null)
                {
                    ev.RegR = new DoneValue();
                }
                else
                {
                    ev.RegR = new StringValue(vti.Key);
                }
            }
            else
            {
                throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPETABLEREF));
            }
        }
Exemple #4
0
        /*
         * O_FSTORE
         * sin:  S[top] = varref; S[top-1] = arrayref
         * sout: S[top] = arrayref
         * in:   R = index; S[top] = varref; S[top-1] = arrayref
         * out:  R = arrayref[index]; S[top] = arrayref;
         * op:   R = arrayref[index]; store;
         */

        public override void Eval(EvaluatorState ev)
        {
            //Console.WriteLine(this.ToString());

            // get the array reference
            IValue tableValue = ev.Stack.ReadN(ev.Stack.StackTop - 1);

            // work with arrays only
            if (tableValue.TypeOf() == ValueTypeID.TYPE_TABLEREF)
            {
                ValueTable table = (ValueTable)tableValue.GetObjectValue();

                // if this creates a new array item, foreach fall into a endless loop!
                ValueTableItem vti = table.Search(ev.RegR.GetStringValue());
                if (vti != null)
                {
                    ev.RegR = new TableDataRefValue(vti);
                }
                else
                {
                    throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_BADKEYINFOREACH));
                }
            }
            else
            {
                throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPETABLEREF));
            }

            // store the R to the var
            // TODO: remove the new opcode creation here
            AOpCode storeOpCode = new StoreOpCode(this.line, this.linePosition, TokenID.T_ASSIGN_OP);

            storeOpCode.Eval(ev);
        }
Exemple #5
0
        public override void Eval(EvaluatorState ev)
        {
            //Console.WriteLine(this.ToString());

            // second operand (source)
            ev.GetVal();

            // first operand (destination)
            IValue storeValue = ev.Stack.ReadTop();

            ev.Stack.Pop(); // pop destination or index

            if (storeValue.TypeOf() == ValueTypeID.TYPE_STOREREF)
            {
                DoStoreOp((ValueStore)storeValue.GetObjectValue(), ev.RegR, variation);
            }
            else if (storeValue.TypeOf() == ValueTypeID.TYPE_TABLEDATAREF)
            {
                ValueTableItem vti = (ValueTableItem)storeValue.GetObjectValue();

                if (ev.RegR.TypeOf() == ValueTypeID.TYPE_UNDEFINED)
                {
                    ValueTable table = vti.Parent;
                    table.Delete(vti.Key);
                }
                else
                {
                    DoTableOp(vti, ev.RegR, variation);
                }
            }
            else
            {
                throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPESTOREREF));
            }
        }
Exemple #6
0
        public override void Register()
        {
            this.RegisterFunction("strcat", StrCatF, 2);
            this.RegisterFunction("nump", NumPF, -1);


            //ValueTableItem testObj = this.RegisterObject("testObj");
            //testObj.Value = new StringValue("testObj: The test object.");

            ValueTableItem gObj = this.RegisterObject(ScriptState.BASE_LF_VAR_NAME);

            gObj.Value = new StringValue(System.Environment.NewLine);
        }
Exemple #7
0
        public override void Eval(EvaluatorState ev)
        {
            //Console.WriteLine(this.ToString());

            if (ev.RegR.TypeOf() == ValueTypeID.TYPE_STOREREF)
            {
                ValueStore store  = (ValueStore)ev.RegR.GetObjectValue();
                double     number = store.Value.GetNumericValue();
                ev.RegR     = store.Value;
                store.Value = new NumericValue(number + 1.0);
            }
            else if (ev.RegR.TypeOf() == ValueTypeID.TYPE_TABLEDATAREF)
            {
                ValueTableItem item   = (ValueTableItem)ev.RegR.GetObjectValue();
                double         number = item.Value.GetNumericValue();
                ev.RegR    = item.Value;
                item.Value = new NumericValue(number + 1.0);
            }
            else
            {
                throw new SharpNektonException(new SharpNektonError(SharpNektonErrorID.E_EXPTYPESTOREREF));
            }
        }
Exemple #8
0
 public TableDataRefValue(ValueTableItem valueTableItem)
 {
     valueType = ValueTypeID.TYPE_TABLEDATAREF;
     val       = valueTableItem;
 }
Exemple #9
0
 private void DoTableOp(ValueTableItem dest, IValue b, TokenID variation)
 {
     dest.Value = DoOperation(dest.Value, b, variation);
 }