Пример #1
0
    public static object CreateNewObject(ELEMENT e, object[] args, xmlScriptObj scrObj, STACKVAL stack)
    {
        ELEMENT last       = e.GetPointerLast();
        string  pointerstr = e.GetPointerString();
        string  name       = string.IsNullOrEmpty(pointerstr) ? last.raw : pointerstr + "." + last.raw;
        object  o          = null;

        var t = GetTypeOf(name);

        if (hglEtc.check_head(t.ToString(), "xmlScriptJS."))
        {
            if (args != null)
            {
                var jsargs = new xmlScriptJS.ARGS();
                jsargs.m_args = args;
                o             = System.Activator.CreateInstance(t, jsargs);
            }
            else
            {
                o = System.Activator.CreateInstance(t);
            }

            return(o);
        }

        var nargs = xmlScriptGetMethod.CreateArgsForCreateInstance(t, args);

        o = System.Activator.CreateInstance(t, nargs);

        return(o);
    }
Пример #2
0
    static bool Execute_Func_Pointer_Variable(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, out object o)
    {
        o = null;
        if (e.isFUNCTION())
        {
            if (xmlScriptExecFunc.ExecuteFunction(e, scrObj, stack, out o))
            {
                return(true);
            }
            throw new SystemException("ERROR EXECUTE FUNCTION " + e.raw);
        }
        else if (e.isPOINTER())
        {
            if (xmlScriptExecPointer.ExecutePointer(e, scrObj, stack, out o))
            {
                return(true);
            }
            throw new SystemException("ERROR EXECUTE POINTER" + e.raw);
        }
        else if (e.isVARIABLE())
        {
            if (xmlScriptExecVar.ExecuteVariable(e, scrObj, stack, out o))
            {
                return(true);
            }
            throw new SystemException("ERROR EXECUTE VARIABLE" + e.raw);
        }

        return(false);
    }
Пример #3
0
    public static bool InvokeFunc(ELEMENT ie, object[] args, xmlScriptObj baseObj, STACKVAL stack, out object o)
    {
        // ref :  http://dobon.net/vb/dotnet/programing/typegetmember.html
        o = null;

        ELEMENT e    = ie;
        ELEMENT last = e.GetPointerLast();
        string  func = last.raw;
        object  p    = null;
        Type    t    = null;

        p = GetPropaty(e, baseObj, stack);

        if (p != null)
        {
            t = xmlScriptGetMethod.ObjectGetType(p);
        }
        else //if (xmlEtc.CountCharInString(pointerstr,'.') == 1)  // **.**.
        {
            string pointerstr = e.GetPointerString();
            t = GetTypeOf(pointerstr);
        }
        if (t == null)
        {
            throw new SystemException("ERROR CAN'T SOLVE TYPE :" + e.GetPointerString());
        }
        if (string.IsNullOrEmpty(func) || t == null)
        {
            throw new SystemException("ERROR NOT DEFINED FUNC NAME");
        }

        return(__InvokeFunc(last, args, ref o, func, p, t));
    }
Пример #4
0
    public object RunFunction(string funcname, object args, xmlScriptObj scrObj)
    {
        ELEMENT funcElement;
        ELEMENT pgmElement;
        var     b = ELEMENT.FindFunctionFromRoot(m_rootElement, funcname, out funcElement, out pgmElement);

        if (!b)
        {
            return(false);
        }
        var stack = m_stackval.FindStack(pgmElement.decname);

        return(xmlScriptFunc.ExecuteDEC_FUNC(funcElement, scrObj, stack, args));
    }
Пример #5
0
    public static object[] GetArgs(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (!e.isBLOCK_C())
        {
            return(null);
        }
        var arglist = new object[e.GetListCount()];

        for (int i = 0; i < e.GetListCount(); i++)
        {
            arglist[i] = xmlScriptFunc.Execute(e.GetListElement(i), scrObj, stack);
        }
        return(arglist);
    }
Пример #6
0
    public static object GetArrayIndex(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (!e.isBLOCK_L())
        {
            return(null);
        }
        var p = e.GetListElement(0);

        if (!p.isNONE())
        {
            return(xmlScriptFunc.Execute(p, scrObj, stack));
        }
        return(null);
    }
Пример #7
0
    //static int pgm_num = 0;
    public static void ExecutePROGRAM(ELEMENT i_e, xmlScriptObj scrObj, STACKVAL stack)
    {
        ELEMENT e = i_e;

        if (e.list != null)
        {
            foreach (var sentence in e.list)
            {
                if (sentence.isSENTENCE())
                {
                    Execute(sentence, scrObj, stack);
                }
            }
        }
    }
Пример #8
0
    static object Execute_OP(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (!e.isOP())
        {
            return(null);
        }
        object[] args  = null;
        Type[]   types = null;
        object   o     = null;

        var p0 = Execute(e.GetListElement(0), scrObj, stack);
        var p1 = Execute(e.GetListElement(1), scrObj, stack);

        if (e.GetOP_ARGC() == 2)
        {
            args  = new object[] { p0, p1 };
            types = new Type[] { xmlScriptGetMethod.ObjectGetType(p0), xmlScriptGetMethod.ObjectGetType(p1) };
        }
        else if (e.GetOP_ARGC() == 1)
        {
            args  = new object[] { p0 };
            types = new Type[] { xmlScriptGetMethod.ObjectGetType(p0) };
        }

        o = xmlScriptOP._Execute_OP_INTFLOATDOUBLE(e, e.GetOP_ARGC(), p0, p1, scrObj, stack);
        if (o != null)
        {
            return(o);
        }

        o = xmlScriptOP._Execute_OP_STRING(e, p0, p1, scrObj, stack);
        if (o != null)
        {
            return(o);
        }

        {
            var t = xmlScriptGetMethod.ObjectGetType(p0);                             if (t == null)
            {
                throw new System.Exception(e + " Unexcted Operation, nonetype");
            }
            object[] iparam = new object[] { p0, p1 };
            var      mi     = xmlScriptGetMethod.GetMethod2(t, e.group.ToString(), iparam);
            return(xmlScriptGetMethod.MethodInfoInvoke(mi, null, iparam));
        }

        throw new System.Exception(e + " Unexcted Operation");
    }
Пример #9
0
    public static bool ExecutePointer(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, out object o)
    {
        ELEMENT last       = e.GetPointerLast();
        var     pointerstr = e.GetPointerString();

        if (xmlScriptExecFunc.ExecuteFunction(e, scrObj, stack, out o))
        {
            return(true);
        }
        if (xmlScriptExecVar.ExecuteVariable(e, scrObj, stack, out o))
        {
            return(true);
        }

        throw new SystemException("ERROR EXECUTE POINTER" + e.raw);
    }
Пример #10
0
    public static bool _ObjectInvokeFunc(object ip, ELEMENT e, xmlScriptObj baseObj, STACKVAL stack, out object o)
    {
        o = null;
        if (ip == null)
        {
            throw new SystemException("ERROR THE PARENT OF THE FUNCTION IS NULL :" + e.ToString());
        }
        if (!e.isFUNCTION())
        {
            throw new SystemException("ERROR STATEMENT IS NOT FUNCTION :" + e.ToString());
        }
        var t = xmlScriptGetMethod.ObjectGetType(ip);

        object[] arglist = xmlScriptExecFunc.GetArgs(e, baseObj, stack);
        return(__InvokeFunc(e, arglist, ref o, e.raw, ip, t));
    }
Пример #11
0
    public static bool CallScriptFunction(string funcname, xmlScriptObj scrObj, STACKVAL stack, object args, out object o)
    {
        o = null;
        ELEMENT funcElement;
        ELEMENT pgmElement;
        var     b = ELEMENT.FindFunction(stack, funcname, out funcElement, out pgmElement);

        if (!b)
        {
            b = ELEMENT.FindFunctionFromRoot(scrObj.m_rootElement, funcname, out funcElement, out pgmElement);
        }
        if (!b)
        {
            return(false);
        }
        o = xmlScriptFunc.ExecuteDEC_FUNC(funcElement, scrObj, stack, args);
        return(true);
    }
Пример #12
0
    public static bool ExecuteSetPointer(ELEMENT e, object val, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (!e.isPOINTER())
        {
            return(false);
        }
        ELEMENT last       = e.GetPointerLast();
        var     pointerstr = e.GetPointerString(); // GetPointerToString(e,out last );

        var o = xmlScriptReflection.SetPropaty(e, new object[] { val }, scrObj, stack);

        if (o != null)
        {
            return(true);
        }

        return(false);
    }
Пример #13
0
    public static bool ExecuteValiable_GetFromStack(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, out object o)
    {
        o = null;
        if (!e.isVARIABLE())
        {
            return(false);
        }
        if (e.isVARIABLE_NOTARRAY())
        {
            o = stack.GetVal(e.raw); return(true);
        }

        if (e.GetListCount() == 1)
        {
            var index = xmlScriptArray.GetArrayIndex(e.GetListElement(0), scrObj, stack);// Debug.LogError("index = " + index);
            var array = stack.GetVal(e.raw);
            if (array == null)
            {
                Debug.LogError("ExecuteValiable_GetFromStack #3x ERROR ");   return(false);
            }
            if (xmlScriptGetMethod.ObjectGetType(array) == typeof(xmlScriptJS.Array))
            {
                o = ((xmlScriptJS.Array)array).Get(index);
            }
        }
        else
        {
            object[] indexList = new object[e.GetListCount()];
            for (int i = 0; i < e.GetListCount(); i++)
            {
                indexList[i] = xmlScriptArray.GetArrayIndex(e.GetListElement(i), scrObj, stack);
            }
            var array = stack.GetVal(e.raw);
            if (array == null)
            {
                return(false);
            }
            if (array != null && xmlScriptGetMethod.ObjectGetType(array) == typeof(xmlScriptJS.Array))
            {
                o = xmlScriptJS.Array.GetMultidimension(array, indexList);
            }
        }
        return(true);
    }
Пример #14
0
    public static bool ExecuteVariable(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, out object o)
    {
        string  pointerstr = e.GetPointerString();
        ELEMENT last       = e.GetPointerLast();

        if (e.isVARIABLE())
        {
            if (ExecuteValiable_GetFromStack(e, scrObj, stack, out o))
            {
                return(true);
            }
        }
        o = xmlScriptReflection.GetPropaty(e, scrObj, stack);
        if (o != null)
        {
            return(true);
        }
        return(false);
    }
Пример #15
0
    public static object CreateArray(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (!e.isBLOCK_L())
        {
            return(null);
        }
        if (e.GetListCount() == 0)
        {
            return(null);
        }

        var array = new xmlScriptJS.Array();

        for (int i = 0; i < e.GetListCount(); i++)
        {
            array.Set(i, xmlScriptFunc.Execute(e.GetListElement(i), scrObj, stack));
        }
        return(array);
    }
Пример #16
0
    public static object _Execute_OP_STRING(ELEMENT e, object p0, object p1, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (p0 == null || p1 == null)
        {
            return(null);
        }
        if (xmlScriptGetMethod.ObjectGetType(p0) == typeof(string))
        {
            string a = p0.ToString();
            string b = p1.ToString();
            switch (e.group)
            {
            case GROUP.op_Addition:          return(a + b);

            case GROUP.op_Equality:          return((bool)(a == b));

            case GROUP.op_Inequality:        return((bool)(a != b));
            }
            throw new SystemException(e + "Unexpected Operation");
        }
        return(null);
    }
Пример #17
0
    static object _ObjectGetPropaty(object obj, ELEMENT ie, xmlScriptObj scrObj, STACKVAL stack)
    {
        object o = null;

        if (obj == null)
        {
            throw new SystemException("ERRPOR POINTERS HAS NULL:" + ie);
        }

        ELEMENT e = ie;

        if (ie.isPOINTER())
        {
            e = ie.GetPointerInside();
        }

        switch (e.group)
        {
        case GROUP.VARIABLE:
            if (e.isVARIABLE_ARRAY())
            {
                throw new SystemException("ERROR THE ARRAY IN THE MIDDLE OF POINTER ISN'T SUPPORTED.");
            }
            return(__ObjectGetPropaty(e, obj, e.raw));

        case GROUP.FUNCTION:
            if (_ObjectInvokeFunc(obj, e, scrObj, stack, out o))
            {
                return(o);
            }
            throw new SystemException("ERROR FUNCTION :" + e.ToString());

        default:
            throw new SystemException("ERROR NOT SUPPORTED :" + e.ToString());
        }
    }
Пример #18
0
    public static object ExecuteDEC_FUNC(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, object args)
    {
        if (e == null || !e.isDEC_FUNC())
        {
            return(null);
        }

        var newstack = stack.CreateStack(e.decname, e);

        var block_c = e.GetListElement(0);

        for (int i = 0; i < block_c.GetListCount(); i++)
        {
            var vname = block_c.GetListElement(i).raw;
            var val   = ((object[])args)[i];
            newstack.DeclareLocalVal(vname);
            newstack.SetVal(vname, val);
        }

        var o = Execute(e.GetListElement(1), scrObj, newstack);

        stack.DestroyStack(newstack);
        return(o);
    }
Пример #19
0
    public static object GetPropaty(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack)
    {
        var len = e.GetPointerCount(true);
        var n0  = e.GetPointerName(true);
        var n1  = len > 1 ?  e.GetPointerNext().GetPointerName(true) : null;

        int    index = 0;
        object p     = null;

        {
            var val = e.GetPointerVARIABLE();
            if (val != null)
            {
                object o = null;
                if (xmlScriptExecVar.ExecuteValiable_GetFromStack(val, (xmlScriptObj)scrObj, stack, out o))
                {
                    p = o;
                    if (p != null)
                    {
                        index = 1;
                    }
                }
            }
        }

        if (p == null && scrObj != null)
        {
            p = _ObjectGetPropaty(scrObj, e, scrObj, stack);
            if (p != null)
            {
                index = 1;
            }
        }

        if (p == null)
        {
            p = _StaticGetPropaty(n0, n1);
            if (p != null)
            {
                index = 2;
            }
        }

        if (p == null)
        {
            return(null);
        }

        if (index < len)
        {
            for (int i = index; i < len; i++)
            {
                var ne = e.GetPointerNext(i);
                var pn = ne.GetPointerName(true);
                p = _ObjectGetPropaty(p, ne, scrObj, stack);

                if (p == null)
                {
                    break;
                }
            }
        }
        return(p);
    }
Пример #20
0
 public _TOOL(xmlScriptObj obj)
 {
     m_scrObj = obj;
 }
Пример #21
0
    public static bool ExecuteFunction(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, out object o)
    {
        o = null;
        object[] arglist = null;
        ELEMENT  func    = e.GetPointerLast();

        if (!func.isFUNCTION())
        {
            return(false);
        }

        if (func.raw == "typeof")
        {
            if (func.GetListElement(0).isBLOCK_C())
            {
                var     p0e  = func.GetListElement(0).GetListElement(0);
                ELEMENT last = p0e.GetPointerLast();
                var     pstr = p0e.GetPointerString();
                pstr = string.IsNullOrEmpty(pstr) ? last.raw : pstr + "." + last.raw;
                Type t = xmlScriptReflection.GetTypeOf(pstr);
                if (t == null)
                {
                    var o_1 = xmlScriptFunc.Execute(p0e, scrObj, stack);
                    if (o_1 != null)
                    {
                        t = xmlScriptGetMethod.ObjectGetType(o_1);
                    }
                }
                o = t;
                return(true);
            }
            return(false);
        }
        if (func.raw == "SETUPDATEFUNC" /*"S_SetUpdateFunc"*/)
        {
            if (func.GetListElement(0).isBLOCK_C())
            {
                var p0 = func.GetListElement(0).GetListElement(0);
                var p1 = func.GetListElement(0).GetListElement(1);

                var p0_o     = xmlScriptFunc.Execute(p0, scrObj, stack);
                var funcname = (p1.isQUOTE() ? p1.raw : null);
                if (!string.IsNullOrEmpty(funcname) && xmlScriptGetMethod.ObjectGetType(p0_o) == typeof(GameObject))
                {
                    var scriptMan = scrObj.GetComponent <xmlScriptMan>();
                    if (scriptMan != null)
                    {
                        scriptMan.SetUpdate(funcname, (GameObject)p0_o);
                        return(true);
                    }
                }
            }
            return(false);
        }
        else if (func.raw == "SETSTARTFUNC")
        {
            if (func.GetListElement(0).isBLOCK_C())
            {
                var p0 = func.GetListElement(0).GetListElement(0);
                var p1 = func.GetListElement(0).GetListElement(1);

                var p0_o = xmlScriptFunc.Execute(p0, scrObj, stack);
                var p1_o = xmlScriptFunc.Execute(p1, scrObj, stack);
                //var funcname = p1_o.ToString();
                if (p1_o != null && !string.IsNullOrEmpty(p1_o.ToString()) && (p0_o == null || xmlScriptGetMethod.ObjectGetType(p0_o) == typeof(GameObject)))
                {
                    var scriptMan = scrObj.GetComponent <xmlScriptMan>();
                    if (scriptMan != null)
                    {
                        scriptMan.SetStart(p1_o.ToString(), (GameObject)p0_o);
                        return(true);
                    }
                }
            }
            return(false);
        }
        else if (func.raw == "CALL")
        {
            if (func.GetListElement(0).isBLOCK_C())
            {
                var p0 = func.GetListElement(0).GetListElement(0);

                var p0_o = xmlScriptFunc.Execute(p0, scrObj, stack);
                //var funcname = p1_o.ToString();
                if (p0_o != null && !string.IsNullOrEmpty(p0_o.ToString()))
                {
                    var scriptMan = scrObj.GetComponent <xmlScriptMan>();
                    if (scriptMan != null)
                    {
                        scrObj.m_scriptMan.RunFunction(p0_o.ToString(), null, scrObj);
                        return(true);
                    }
                }
            }
            return(false);
        }

        arglist = GetArgs(func.GetListElement(0), scrObj, stack);

        if (e == func)
        {
            if (xmlScriptFunc.CallScriptFunction(func.raw, scrObj, stack, arglist, out o))
            {
                if (o != null && xmlScriptGetMethod.ObjectGetType(o) == typeof(SENTENCE_STATE))
                {
                    var ss = (SENTENCE_STATE)o;
                    if (ss.state == SENTENCE_STATE.STATE.RETURN)
                    {
                        o = ss.ret;
                    }
                }
                return(true);
            }
        }
        else
        {
            var pointerstr = e.GetPointerString();
            if (xmlScriptReflection.InvokeFunc(e, arglist, scrObj, stack, out o))
            {
                return(true);
            }
        }
        return(false);
    }
Пример #22
0
    public static bool ExecuteSetVariable(ELEMENT e, object val, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (!e.isVARIABLE())
        {
            return(false);
        }
        if (e.isVARIABLE_NOTARRAY())
        {
            return(stack.SetVal(e.raw, val));
        }

        if (e.GetListCount() == 1)
        {
            var index = xmlScriptArray.GetArrayIndex(e.GetListElement(0), scrObj, stack); //Debug.LogError("index = " + index);
            var array = stack.GetVal(e.raw);
            if (array == null)
            {
                array = new xmlScriptJS.Array();
            }
            //Debug.LogError("array = " + array);
            if (xmlScriptGetMethod.ObjectGetType(array) == typeof(xmlScriptJS.Array))
            {
                ((xmlScriptJS.Array)array).Set(index, val);
                if (!stack.isExist(e.raw))
                {
                    stack.SetGlobalVal(e.raw, array);
                }
                else
                {
                    stack.SetVal(e.raw, array);
                }
                //Debug.Log("array1 = " + array);
                //Debug.Log("array2 = " + stack.GetVal(e.raw));
            }
        }
        else
        {
            object[] indexList = new object[e.GetListCount()];
            for (int i = 0; i < e.GetListCount(); i++)
            {
                indexList[i] = xmlScriptArray.GetArrayIndex(e.GetListElement(i), scrObj, stack);
            }
            var array = stack.GetVal(e.raw);
            if (array == null)
            {
                array = new xmlScriptJS.Array();
            }
            if (array != null && xmlScriptGetMethod.ObjectGetType(array) == typeof(xmlScriptJS.Array))
            {
                xmlScriptJS.Array.SetMultidimension(array, indexList, val);
                if (!stack.isExist(e.raw))
                {
                    stack.SetGlobalVal(e.raw, array);
                }
                else
                {
                    stack.SetVal(e.raw, array);
                }
            }
        }
        return(true);
    }
Пример #23
0
 public Document(xmlScriptObj scrObj)
 {
     m_scrObj = scrObj;
 }
Пример #24
0
    public static object Execute(ELEMENT i_e, xmlScriptObj scrObj, STACKVAL stack)
    {
        if (i_e == null || i_e.isNONE())
        {
            return(null);
        }

        ELEMENT e = i_e;
        object  o;

        if (e.isSENTENCE())
        {
            e = e.GetListElement(0);
        }

        if (e.isNUMBER())
        {
            double x = 0;
            double.TryParse(e.raw, out x);
            return(x);
        }
        else if (e.isQUOTE())
        {
            return(e.raw);
        }
        else if (e.isNULL())
        {
            return(null);
        }
        else if (e.isBLOCK_M())
        {
            o = null;
            stack.PushStack();
            var l = e.list;
            if (l != null)
            {
                foreach (var s in l)
                {
                    if (s.isSENTENCE())
                    {
                        o = Execute(s.list[0], scrObj, stack);
                        if (o != null && xmlScriptGetMethod.ObjectGetType(o) == typeof(SENTENCE_STATE))
                        {
                            if (((SENTENCE_STATE)o).state != SENTENCE_STATE.STATE.NONE)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            stack.PopStack();
            return(o);
        }
        else if (e.isBLOCK_L())
        {
            return(xmlScriptArray.CreateArray(e, scrObj, stack));
        }
        else if (e.isBLOCK_C())
        {
            if (e.list == null || e.list.Count == 0)
            {
                return(null);
            }
            o = null;
            foreach (var s in e.list)
            {
                o = Execute(s, scrObj, stack);
            }
            return(o);
        }

        else if (Execute_Func_Pointer_Variable(e, scrObj, stack, out o))
        {
            return(o);
        }
        else if (e.isRETURN())
        {
            var ss = new SENTENCE_STATE();
            ss.state = SENTENCE_STATE.STATE.RETURN;
            ss.ret   = Execute(e.GetListElement(0), scrObj, stack);

            return(ss);
        }
        else if (e.isDEC_VAR())
        {
            stack.DeclareLocalVal(e.decname);
            return(e.decname);
        }
        else if (e.isOP())
        {
            if (e.group == GROUP.op_Assign)
            {
                var p0   = e.GetListElement(0);
                var p1   = e.GetListElement(1);
                var o_p1 = Execute(p1, scrObj, stack);


                if (p0.isVARIABLE())
                {
                    bool b = xmlScriptExecVar.ExecuteSetVariable(p0, o_p1, scrObj, stack);//  stack.SetVal(p0.raw, o_p1);
                    if (!b)
                    {
                        stack.SetGlobalVal(p0.raw, o_p1);
                    }
                }
                else if (p0.isPOINTER())
                {
                    xmlScriptExecPointer.ExecuteSetPointer(p0, o_p1, scrObj, stack);
                }
                else if (p0.isDEC_VAR())
                {
                    stack.SetVal((string)Execute(p0, scrObj, stack), o_p1);
                }
                return(null);
            }
            else
            {
                o = Execute_OP(e, scrObj, stack);

                if (e.group == GROUP.op_Increment_R || e.group == GROUP.op_Decrement_R)
                {
                    var p0 = e.GetListElement(0);
                    if (p0.isVARIABLE())
                    {
                        if (xmlScriptGetMethod.ObjectGetType(o) == typeof(double))
                        {
                            switch (e.group)
                            {
                            case GROUP.op_Increment_R: xmlScriptExecVar.ExecuteSetVariable(p0, (double)o + 1, scrObj, stack); break; //stack.SetVal(p0.raw, (int)o + 1); break;

                            case GROUP.op_Decrement_R: xmlScriptExecVar.ExecuteSetVariable(p0, (double)o - 1, scrObj, stack); break; // stack.SetVal(p0.raw, (int)o - 1); break;
                            }
                        }
                        else if (xmlScriptGetMethod.ObjectGetType(o) == typeof(int))
                        {
                            switch (e.group)
                            {
                            case GROUP.op_Increment_R: xmlScriptExecVar.ExecuteSetVariable(p0, (int)o + 1, scrObj, stack); break; //stack.SetVal(p0.raw, (int)o + 1); break;

                            case GROUP.op_Decrement_R: xmlScriptExecVar.ExecuteSetVariable(p0, (int)o - 1, scrObj, stack); break; // stack.SetVal(p0.raw, (int)o - 1); break;
                            }
                        }
                        else if (xmlScriptGetMethod.ObjectGetType(o) == typeof(float))
                        {
                            switch (e.group)
                            {
                            case GROUP.op_Increment_R: xmlScriptExecVar.ExecuteSetVariable(p0, (float)o + 1.0f, scrObj, stack); break; //  stack.SetVal(p0.raw, (float)o + 1.0f); break;

                            case GROUP.op_Decrement_R: xmlScriptExecVar.ExecuteSetVariable(p0, (float)o - 1.0f, scrObj, stack); break; //stack.SetVal(p0.raw, (float)o - 1.0f); break;
                            }
                        }
                    }
                }
                return(o);
            }
        }
        else if (Execute_FlowControl(e, scrObj, stack, out o))
        {
            return(o);
        }
        else if (e.isNEW())
        {
            ELEMENT last = e.GetListElement(0).GetPointerLast();
            if (!last.isFUNCTION())
            {
                throw new SystemException("ERROR NEW EXPECTED () ");
            }

            object[] args = last.GetListElement(0).GetListCount() > 0 ? new object[last.GetListElement(0).GetListCount()] : null;
            for (int i = 0; i < last.GetListElement(0).GetListCount(); i++)
            {
                args[i] = Execute(last.GetListElement(0).GetListElement(i), scrObj, stack);
            }

            return(xmlScriptReflection.CreateNewObject(e.GetListElement(0), args, scrObj, stack));
        }
        else if (e.isDELETE())
        {
            var p_o = Execute(e.GetListElement(0), scrObj, stack);
            if (p_o is UnityEngine.Object)
            {
                UnityEngine.Object.Destroy((UnityEngine.Object)p_o);
            }
            else if (p_o is System.IDisposable)
            {
                ((System.IDisposable)p_o).Dispose();
            }
            //ELEMENT last;
            //var pointerstr = GetPointerToString(e.GetListElement(0), out last);
            //TBD
        }
        return(null);
    }
Пример #25
0
 public _Debug(xmlScriptObj scrObj)
 {
     m_scrObj = scrObj;
 }
Пример #26
0
 public Location(xmlScriptObj obj)
 {
     m_scrObj = obj;
 }
Пример #27
0
    static bool Execute_FlowControl(ELEMENT e, xmlScriptObj scrObj, STACKVAL stack, out object o)
    {
        o = null;
        if (e.isIF())
        {
            bool b = (bool)Execute(e.GetListElement(0), scrObj, stack);
            if (b)
            {
                o = Execute(e.GetListElement(1), scrObj, stack);  //Debug.LogError("isIF o=" + o);
                return(true);
            }
            for (int i = 2; i < e.list.Count; i++)
            {
                var s = e.GetListElement(i); if (s.isNONE())
                {
                    o = null; return(true);
                }
                if (s.isELSE())
                {
                    o = Execute(s.GetListElement(0), scrObj, stack);
                    return(true);
                }
                else if (s.isELSEIF())
                {
                    bool b2 = (bool)Execute(s.GetListElement(0), scrObj, stack);
                    if (b2)
                    {
                        o = Execute(s.GetListElement(1), scrObj, stack);
                        return(true);
                    }
                }
            }
        }
        else if (e.isSWITCH())
        {
            object x = null;
            {
                var p0 = e.GetListElement(0).GetListElement(0);
                x = Execute(p0, scrObj, stack);
            }

            var block       = e.GetListElement(1);
            int start_index = -1;
            for (int i = 0; i < block.GetListCount(); i++)
            {
                if (!block.GetListElement(i).isSENTENCE())
                {
                    continue;
                }
                var case_e = block.GetListElement(i).GetListElement(0);
                if (case_e.isCASE())
                {
                    var case_a = case_e.GetListElement(0);
                    if (case_a.raw == x.ToString())
                    {
                        start_index = i + 1;
                        break;
                    }
                }
                else if (case_e.isDEFAULT())
                {
                    start_index = i + 1;
                    break;
                }
            }

            if (start_index > 0)
            {
                for (int i = start_index; i < block.GetListCount(); i++)
                {
                    o = Execute(block.GetListElement(i), scrObj, stack);
                    if (o != null && xmlScriptGetMethod.ObjectGetType(o) == typeof(SENTENCE_STATE))
                    {
                        var ss = (SENTENCE_STATE)o;
                        if (ss.state == SENTENCE_STATE.STATE.BREAK)
                        {
                            break;
                        }
                    }
                }
            }
            return(true);
        }
        else if (e.isFOR())
        {
            var e_bc = e.GetListElement(0); //Debug.Log("e_bc" + e_bc); Debug.Log("e_bc.list[0]=" + e_bc.GetListElement(0)); Debug.Log("e_bc.list[1]=" + e_bc.GetListElement(1)); Debug.Log("e_bc.list[2]=" + e_bc.GetListElement(2));
            var e_bm = e.GetListElement(1); //Debug.Log("e_bm" + e_bm);
            stack.PushStack();
            Execute(e_bc.GetListElement(0), scrObj, stack);
            o = null;
            for (var i = 0; i < 200; i++)
            {
                bool b = (bool)Execute(e_bc.GetListElement(1), scrObj, stack);
                if (!b)
                {
                    break;
                }
                o = Execute(e_bm, scrObj, stack);
                if (o != null && xmlScriptGetMethod.ObjectGetType(o) == typeof(SENTENCE_STATE))
                {
                    var state = (SENTENCE_STATE)o;
                    if (state.state == SENTENCE_STATE.STATE.BREAK)
                    {
                        break;
                    }
                    if (state.state == SENTENCE_STATE.STATE.CONTINUE)
                    {
                        goto _FOR_LOOPEND;
                    }
                    if (state.state == SENTENCE_STATE.STATE.RETURN)
                    {
                        break;
                    }
                }
_FOR_LOOPEND:
                Execute(e_bc.GetListElement(2), scrObj, stack);
            }
            stack.PopStack();

            o = null;
            return(true);
        }
        else if (e.isWHILE())
        {
            var e_bc = e.GetListElement(0);
            var e_bm = e.GetListElement(1);

            stack.PushStack();
            Execute(e_bc.GetListElement(0), scrObj, stack);
            o = null;
            for (var i = 0; i < 200; i++)
            {
                bool b = (bool)Execute(e_bc.GetListElement(0), scrObj, stack);
                if (!b)
                {
                    break;
                }
                o = Execute(e_bm, scrObj, stack);
                if (o != null && xmlScriptGetMethod.ObjectGetType(o) == typeof(SENTENCE_STATE))
                {
                    var state = (SENTENCE_STATE)o;
                    if (state.state == SENTENCE_STATE.STATE.BREAK)
                    {
                        break;
                    }
                    if (state.state == SENTENCE_STATE.STATE.CONTINUE)
                    {
                        continue;
                    }
                    if (state.state == SENTENCE_STATE.STATE.RETURN)
                    {
                        break;
                    }
                }
            }
            stack.PopStack();

            o = null;
            return(true);
        }
        else if (e.isBREAK())
        {
            Debug.LogWarning("BREAK " + e);
            o = new SENTENCE_STATE()
            {
                state = SENTENCE_STATE.STATE.BREAK
            };
            return(true);
        }
        else if (e.isCONTINUE())
        {
            o = new SENTENCE_STATE()
            {
                state = SENTENCE_STATE.STATE.CONTINUE
            };
            return(true);
        }
        return(false);
    }
Пример #28
0
    public static object SetPropaty(ELEMENT e, object[] args, xmlScriptObj scrObj, STACKVAL stack)
    {
        var len = e.GetPointerCount(true);
        var n0  = e.GetPointerName(true);
        var n1  = len > 1 ?  e.GetPointerNext().GetPointerName(true) : null;

        int    index = 0;
        object p     = null;

        {
            var val = e.GetPointerVARIABLE();
            if (val != null)
            {
                object o = null;
                if (xmlScriptExecVar.ExecuteValiable_GetFromStack(val, (xmlScriptObj)scrObj, stack, out o))
                {
                    p = o;
                    if (p != null)
                    {
                        index = 1;
                    }
                }
            }
        }

        if (p == null && scrObj != null)
        {
            //p = __ObjectGetPropaty(baseObj,n0);
            p = _ObjectGetPropaty(scrObj, e, scrObj, stack);
            if (p != null)
            {
                index = 1;
            }
        }

        if (p == null)
        {
            if (len == 2)
            {
                return(_StaticSetPropaty(n0, n1, args));
            }
            p = _StaticGetPropaty(n0, n1);
            if (p != null)
            {
                index = 2;
            }
        }

        if (p == null)
        {
            return(null);
        }

        if (index < len - 1)
        {
            for (int i = index; i < len - 1; i++)
            {
                var ne = e.GetPointerNext(i);
                var pn = ne.GetPointerName(true);
                p = __ObjectGetPropaty(ne, p, pn);
                if (p == null)
                {
                    break;
                }
            }
        }

        var setelem = e.GetPointerNext(len - 1);
        var setname = setelem.GetPointerName(true); //names[names.Length-1];

        return(_ObjectSetPropaty(setelem, p, setname, args));
    }
Пример #29
0
    public static object _Execute_OP_INTFLOATDOUBLE(ELEMENT e, int argc, object p0, object p1, xmlScriptObj scrObj, STACKVAL stack) // FOR FAST!
    {
        var p0_type = xmlScriptGetMethod.ObjectGetType(p0);
        var p1_type = xmlScriptGetMethod.ObjectGetType(p1);

        if (argc == 2)
        {
            if (p0_type == typeof(double) && (p1_type == typeof(double) || p1_type == typeof(float) || p1_type == typeof(int)))
            {
                double a = (double)p0;
                double b = (double)(System.Convert.ChangeType(p1, typeof(double)));
                switch (e.group)
                {
                case GROUP.op_Multiply:          return(a * b);

                case GROUP.op_Division:          return(a / b);

                case GROUP.op_Modulus:           return(a % b);

                case GROUP.op_Addition:          return(a + b);

                case GROUP.op_Subtraction:       return(a - b);

                case GROUP.op_Equality:          return((bool)(a == b));

                case GROUP.op_Inequality:        return((bool)(a != b));

                case GROUP.op_LessThan:          return((bool)(a < b));

                case GROUP.op_GreaterThan:       return((bool)(a > b));

                case GROUP.op_LessThanOrEqual:   return((bool)(a <= b));

                case GROUP.op_GreaterThanOrEqua: return((bool)(a >= b));
                }
                throw new SystemException(e + "Unexpected Operation");
            }
            else if (p0_type == typeof(int) && (p1_type == typeof(int) || p1_type == typeof(float) || p1_type == typeof(double)))
            {
                int a = (int)p0;
                int b = (int)(System.Convert.ChangeType(p1, typeof(int)));
                switch (e.group)
                {
                case GROUP.op_Multiply:          return(a * b);

                case GROUP.op_Division:          return(a / b);

                case GROUP.op_Modulus:           return(a % b);

                case GROUP.op_Addition:          return(a + b);

                case GROUP.op_Subtraction:       return(a - b);

                case GROUP.op_Equality:          return((bool)(a == b));

                case GROUP.op_Inequality:        return((bool)(a != b));

                case GROUP.op_LessThan:          return((bool)(a < b));

                case GROUP.op_GreaterThan:       return((bool)(a > b));

                case GROUP.op_LessThanOrEqual:   return((bool)(a <= b));

                case GROUP.op_GreaterThanOrEqua: return((bool)(a >= b));
                }
                throw new SystemException(e + "Unexpected Operation");
            }
            else if (p0_type == typeof(float) && (p1_type == typeof(int) || p1_type == typeof(float) || p1_type == typeof(double)))
            {
                float a = (float)p0;
                float b = (float)(System.Convert.ChangeType(p1, typeof(float)));
                switch (e.group)
                {
                case GROUP.op_Multiply:          return(a * b);

                case GROUP.op_Division:          return(a / b);

                case GROUP.op_Modulus:           return(a % b);

                case GROUP.op_Addition:          return(a + b);

                case GROUP.op_Subtraction:       return(a - b);

                case GROUP.op_Equality:          return((bool)(a == b));

                case GROUP.op_Inequality:        return((bool)(a != b));

                case GROUP.op_LessThan:          return((bool)(a < b));

                case GROUP.op_GreaterThan:       return((bool)(a > b));

                case GROUP.op_LessThanOrEqual:   return((bool)(a <= b));

                case GROUP.op_GreaterThanOrEqua: return((bool)(a >= b));
                }
                throw new SystemException(e + "Unexpected Operation");
            }
        }
        if (argc == 1)
        {
            if (p0_type == typeof(double))
            {
                Action <double> setVal = (i) => {
                    var pe0 = e.GetListElement(0);
                    if (pe0.isVARIABLE())
                    {
                        xmlScriptExecVar.ExecuteSetVariable(pe0, i, scrObj, stack);//stack.SetVal(pe0.raw,i);
                    }
                };

                double a = (double)p0;
                switch (e.group)
                {
                case GROUP.op_Increment_L:    a = a + 1; setVal(a); return(a);

                case GROUP.op_Increment_R:    return(a);

                case GROUP.op_Decrement_L:    a = a - 1; setVal(a); return(a);

                case GROUP.op_Decrement_R:    return(a);



                case GROUP.op_UnaryPlus:      return(a);

                case GROUP.op_UnaryNegation:  return(-a);
                }
                throw new SystemException(e + "Unexpected Operation");
            }
            else if (p0_type == typeof(int))
            {
                Action <int> setVal = (i) => {
                    var pe0 = e.GetListElement(0);
                    if (pe0.isVARIABLE())
                    {
                        xmlScriptExecVar.ExecuteSetVariable(pe0, i, scrObj, stack);//stack.SetVal(pe0.raw,i);
                    }
                };

                int a = (int)p0;
                switch (e.group)
                {
                case GROUP.op_Increment_L:    a = a + 1; setVal(a); return(a);

                case GROUP.op_Increment_R:    return(a);

                case GROUP.op_Decrement_L:    a = a - 1; setVal(a); return(a);

                case GROUP.op_Decrement_R:    return(a);



                case GROUP.op_UnaryPlus:      return(a);

                case GROUP.op_UnaryNegation:  return(-a);
                }
                throw new SystemException(e + "Unexpected Operation");
            }
            else if (p0_type == typeof(float))
            {
                Action <float> setVal = (i) => {
                    var pe0 = e.GetListElement(0);
                    if (pe0.isVARIABLE())
                    {
                        xmlScriptExecVar.ExecuteSetVariable(pe0, i, scrObj, stack);//stack.SetVal(pe0.raw,i);
                    }
                };
                float a = (float)p0;
                switch (e.group)
                {
                case GROUP.op_Increment_L:    a = a + 1; setVal(a); return(a);

                case GROUP.op_Increment_R:    return(a);

                case GROUP.op_Decrement_L:    a = a - 1; setVal(a); return(a);

                case GROUP.op_Decrement_R:    return(a);

                case GROUP.op_UnaryPlus:      return(a);

                case GROUP.op_UnaryNegation:  return(-a);
                }
                throw new SystemException(e + "Unexpected Operation");
            }
        }

        return(null);
    }