public RunExpressions(Func<SpokeObject[], SpokeObject>[] internalMethods, SpokeMethod[] mets)
        {
            Methods = mets;
            InternalMethods = internalMethods;
            ints=new SpokeObject[100];
            for (int i = 0; i < 100; i++) {
                ints[i] = new SpokeObject(ObjectType.Int) {IntVal = i};

            }
        }
 public void loadUp(Func<SpokeObject[], SpokeObject>[] internalMethods, SpokeMethod[] mets)
 {
     Methods = mets;
     InternalMethods = internalMethods;
     ints = new SpokeObject[100];
     for (int i = 0; i < 100; i++)
     {
         ints[i] = new SpokeObject(i);
     }
 }
        public RunInstructions(Func<SpokeObject[], SpokeObject>[] internalMethods, SpokeMethod[] mets, string stack, int returnIndex, Dictionary<string, string[]> variableLookup)
        {
            Methods = mets;
            myVariableLookup = variableLookup;
            InternalMethods = internalMethods;
            ints = new SpokeObject[100];
            for (int i = 0; i < 100; i++)
            {
                ints[i] = new SpokeObject(ObjectType.Int) { IntVal = i };
            }

            if (stack.Length != 0)
            {
                deserialize(stack);
                reprintStackTrace[reprintStackIndex - 1].Answer = new SpokeObject(returnIndex);
            }
        }
        private SpokeObject evaluate(SpokeMethod fm, SpokeObject parent, SpokeObject[] paras)
        {
            #if Stacktrace
            dfss.AppendLine(fm.MethodName);
            #endif

            SpokeObject[] variables = new SpokeObject[fm.NumOfVars];

            for (int i = 0; i < fm.Parameters.Length; i++)
            {
                variables[i] = paras[i];
            }

            var sm = new SpokeMethodRun();
            sm.RunningClass = parent;

            return evaluateLines(fm.Lines, sm, variables);
        }
Exemple #5
0
        private void runClass2(Func<SpokeObject[], SpokeObject>[] rv, SpokeMethod[] dms, SpokeConstruct k)
        {
            RunClass2 d = new RunClass2();
            d.loadUp(rv, dms);
            d.Run();

        }
Exemple #6
0
 private void runClass(Command d, Func<SpokeObject[], SpokeObject>[] rv, SpokeMethod[] methods)
 {
     d.loadUp(rv, methods);
     d.Run();
 }
        private Tuple<string, List<PostParseExpression>> buildMethod(SpokeMethod fm)
        {
            StringBuilder sb = new StringBuilder();

            #if stacktrace
            dfss.AppendLine( fm.Class.Name +" : : "+fm.MethodName+" Start");
            #endif
            List<PostParseExpression> exps = new List<PostParseExpression>();

            for (int index = 0; index < fm.Instructions.Length; index++)
            {
                var ins = fm.Instructions[index];
            #if stacktrace
                dfss.AppendLine(stackIndex + " ::  " + ins.ToString());
            #endif
                int gj;
                PostParseVariable[] pps;
                switch (ins.Type)
                {
                    case SpokeInstructionType.CreateReference:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("new SpokeObject(new SpokeObject[{0}])", ins.Index)), false));

                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(new SpokeObject[{1}]);", ins.StackBefore_, ins.Index));
                        break;
                    case SpokeInstructionType.Comment:
                        exps.Add(new PostParseString(string.Format("/*{0}*/", ins.StringVal)));
                        sb.AppendLine(string.Format("/*{0}*/", ins.StringVal));
                        break;
                    case SpokeInstructionType.CreateArray:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("new SpokeObject(new List<SpokeObject>(20))")), false));

                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(new List<SpokeObject>(20) );", ins.StackBefore_));
                        break;
                    case SpokeInstructionType.CreateMethod:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("NULL")), false));
                        sb.AppendLine(string.Format("stack[{0}]=NULL;", ins.StackBefore_));
                        break;
                    case SpokeInstructionType.Label:
                        exps.Add(new PostParseString(ins.labelGuy + ":"));
                        sb.AppendLine(string.Format("{0}:", ins.labelGuy));
                        break;
                    case SpokeInstructionType.Goto:
                        exps.Add(new PostParseString("goto " + ins.gotoGuy + ";"));
                        sb.AppendLine(string.Format("goto {0};", ins.gotoGuy));
                        break;
                    case SpokeInstructionType.CallMethod:

                        pps = new PostParseVariable[ins.Index3];
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                            pps[i] = new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1 - i);

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1), new PostParseMethod(Methods[ins.Index].Class.Name + Methods[ins.Index].CleanMethodName, pps.Reverse().ToArray(), ins.Index3), true));

                        sb.AppendLine(string.Format("sps = new SpokeObject[{0}];", Methods[ins.Index].NumOfVars));
                        gj = ins.StackBefore_ - 1;
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            sb.AppendLine(string.Format("sps[{1}] = stack[{0}];", gj--, i));
                        }
                        sb.AppendLine(string.Format("stack[{0}] = {1}(sps);", ins.StackAfter_ - 1, Methods[ins.Index].Class.Name + Methods[ins.Index].CleanMethodName));

                        break;
                    case SpokeInstructionType.CallMethodFunc:

                        pps = new PostParseVariable[ins.Index3];
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            pps[i] = new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1 - i);
                        }
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1), new PostParseMethod(string.Format("Methods[{0}].MethodFunc", ins.Index), pps.Reverse().ToArray(), ins.Index3), true));

                        sb.AppendLine(string.Format("sps = new SpokeObject[{0}];", ins.Index3));
                        gj = ins.StackBefore_ - 1;
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            sb.AppendLine(string.Format("sps[{1}] = stack[{0}];", gj--, i));
                        }
                        sb.AppendLine(string.Format("stack[{0}] = Methods[{1}].MethodFunc(sps);", ins.StackAfter_ - 1, ins.Index));
                        break;
                    case SpokeInstructionType.CallInternal:

                        pps = new PostParseVariable[ins.Index3];
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            pps[i] = new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1 - i);
                        }

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1), new PostParseMethod(string.Format("InternalMethods[{0}]", ins.Index), pps.Reverse().ToArray(), ins.Index3), true));

                        sb.AppendLine(string.Format("sps = new SpokeObject[{0}];", ins.Index3));
                        gj = ins.StackBefore_ - 1;
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            sb.AppendLine(string.Format("sps[{1}] = stack[{0}];", gj--, i));
                        }

                        sb.AppendLine(string.Format("stack[{0}] = InternalMethods[{1}](sps);", ins.StackAfter_ - 1, ins.Index));

                        break;
                    case SpokeInstructionType.BreakpointInstruction:
                        Console.WriteLine("BreakPoint");
                        break;
                    case SpokeInstructionType.Return:
                        exps.Add(new PostParseStatement("return {0};", new PostParseVariable(VariableType.Stack, ins.StackBefore_)));
                        sb.AppendLine(string.Format("return stack[{0}];", ins.StackBefore_));
                        break;
                    case SpokeInstructionType.IfTrueContinueElse:
                        exps.Add(new PostParseStatement("if(!({0}).BoolVal) ", new PostParseVariable(VariableType.Stack, ins.StackBefore_)));
                        exps.Add(new PostParseString("goto " + ins.elseGuy + ";"));

                        sb.AppendLine(string.Format("if(!stack[{0}].BoolVal) goto {1};", ins.StackBefore_, ins.elseGuy));

                        break;
                    case SpokeInstructionType.Or:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                                                  new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                                                                         new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                                                                         "(({0}.BoolVal || {1}.BoolVal)?TRUE:FALSE)"), true));
                        sb.AppendLine(string.Format("stack[{0}] = (stack[{0}].BoolVal || stack[{1}].BoolVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackBefore_));
                        break;
                    case SpokeInstructionType.And:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                                                 new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                                                 "(({0}.BoolVal && {1}.BoolVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}] = (stack[{0}].BoolVal && stack[{1}].BoolVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackBefore_));
                        break;
                    case SpokeInstructionType.StoreLocalInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Variable, ins.Index), new PostParseStatement("intCache({0}.IntVal)", new PostParseVariable(VariableType.Stack, ins.StackBefore_)), true));

                        sb.AppendLine(string.Format("variables[{0}] = intCache(stack[{1}].IntVal);", ins.Index, ins.StackBefore_));
                        break;
                    case SpokeInstructionType.StoreLocalFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Variable, ins.Index),
                            new PostParseStatement("new SpokeObject({0}.FloatVal)", new PostParseVariable(VariableType.Stack, ins.StackBefore_)), true));

                        sb.AppendLine(string.Format("variables[{0}] = new SpokeObject(stack[{1}].FloatVal);", ins.Index, ins.StackBefore_));
                        break;
                    case SpokeInstructionType.StoreLocalBool:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Variable, ins.Index),
                            new PostParseStatement("new SpokeObject({0}.BoolVal)", new PostParseVariable(VariableType.Stack, ins.StackBefore_)), true));

                        sb.AppendLine(string.Format("variables[{0}] = stack[{1}].BoolVal ? TRUE : FALSE;", ins.Index, ins.StackBefore_));

                        //      variables[ins.Index] = lastStack.BoolVal ? TRUE : FALSE;
                        break;
                    case SpokeInstructionType.StoreLocalString:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Variable, ins.Index), new PostParseStatement("new SpokeObject({0}.StringVal)", new PostParseVariable(VariableType.Stack, ins.StackBefore_)), true));

                        sb.AppendLine(string.Format("variables[{0}] = new SpokeObject(stack[{1}].StringVal);", ins.Index, ins.StackBefore_));
                        break;

                    case SpokeInstructionType.StoreLocalMethod:
                    case SpokeInstructionType.StoreLocalObject:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Variable, ins.Index), new PostParseVariable(VariableType.Stack, ins.StackBefore_), true));

                        sb.AppendLine(string.Format("variables[{0}] = stack[{1}];", ins.Index, ins.StackBefore_));

                        break;
                    case SpokeInstructionType.StoreLocalRef:
                        exps.Add(
                            new PostParseStatement(
                                @"

            //{1}={0};

            lastStack = {0};
            bm2 = {1};
            bm2.Variables = lastStack.Variables;
            bm2.ArrayItems = lastStack.ArrayItems;
            bm2.StringVal = lastStack.StringVal;
            bm2.IntVal = lastStack.IntVal;
            bm2.BoolVal = lastStack.BoolVal;
            bm2.FloatVal = lastStack.FloatVal;
            ",
                                new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Variable, ins.Index)));

                        sb.AppendLine(string.Format("lastStack = stack[{0}];", ins.StackBefore_));
                        sb.AppendLine(string.Format("bm = variables[{0}];", ins.Index));
                        sb.AppendLine(@"
            bm.Variables = lastStack.Variables;
            bm.ArrayItems = lastStack.ArrayItems;
            bm.StringVal = lastStack.StringVal;
            bm.IntVal = lastStack.IntVal;
            bm.BoolVal = lastStack.BoolVal;
            bm.FloatVal = lastStack.FloatVal;
            ");

                        break;

                    case SpokeInstructionType.StoreFieldBool:

                        exps.Add(new PostParseStatement("{0}.Variables[" + ins.Index + "]={1}.BoolVal?TRUE:FALSE;", new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)));

                        sb.AppendLine(string.Format("stack[{0}].Variables[{2}]=stack[{1}].BoolVal?TRUE:FALSE;", ins.StackBefore_, ins.StackAfter_, ins.Index));
                        break;
                    case SpokeInstructionType.StoreFieldInt:
                        exps.Add(new PostParseStatement("{0}.Variables[" + ins.Index + "]=intCache({1}.IntVal);", new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)));

                        sb.AppendLine(string.Format("stack[{0}].Variables[{2}]=intCache(stack[{1}].IntVal );", ins.StackBefore_, ins.StackAfter_, ins.Index));
                        break;
                    case SpokeInstructionType.StoreFieldFloat:
                        exps.Add(new PostParseStatement("{0}.Variables[" + ins.Index + "]=new SpokeObject({1}.FloatVal);", new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)));

                        sb.AppendLine(string.Format("stack[{0}].Variables[{2}]=new SpokeObject( stack[{1}].FloatVal );", ins.StackBefore_, ins.StackAfter_, ins.Index));
                        break;
                    case SpokeInstructionType.StoreFieldString:
                        exps.Add(new PostParseStatement("{0}.Variables[" + ins.Index + "]=new SpokeObject({1}.StringVal);", new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)));

                        sb.AppendLine(string.Format("stack[{0}].Variables[{2}]=new SpokeObject(stack[{1}].StringVal );", ins.StackBefore_, ins.StackAfter_, ins.Index));
                        break;
                    case SpokeInstructionType.StoreFieldMethod:
                    case SpokeInstructionType.StoreFieldObject:

                        exps.Add(new PostParseStatement("{0}.Variables[" + ins.Index + "]={1};", new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)));

                        sb.AppendLine(string.Format("stack[{0}].Variables[{2}]=stack[{1}];", ins.StackBefore_, ins.StackAfter_, ins.Index));
                        break;
                    case SpokeInstructionType.StoreToReference:

                        exps.Add(new PostParseStatement("{0}.Variables[" + ins.Index + "] = {1};", new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_)));

                        sb.AppendLine(string.Format("stack[{1}].Variables[{2}] = stack[{0}];", ins.StackBefore_, ins.StackBefore_ - 1, ins.Index));
                        break;
                    case SpokeInstructionType.GetField:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseStatement("{0}.Variables[" + ins.Index + "]", new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)), true));

                        sb.AppendLine(string.Format("stack[{0}] = stack[{0}].Variables[{1}];", ins.StackBefore_ - 1, ins.Index));
                        break;
                    case SpokeInstructionType.GetLocal:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseVariable(VariableType.Variable, ins.Index), true));

                        sb.AppendLine(string.Format("stack[{0}] = variables[{1}];", ins.StackBefore_, ins.Index));
                        break;
                    case SpokeInstructionType.PopStack:
                        var d = (PostParseSet)exps.Last(a => a.ExpressionType == PPExpressionType.Set);

                        if (d.Right.ItemType == PPItemType.Variable)
                        {
                            d.MarkForRemoval = true;
                        }
                        else d.RemoveLeft = true;

                        break;
                    case SpokeInstructionType.Not:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseStatement("{0}.BoolVal?FALSE:TRUE", new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1)), true));
                        sb.AppendLine(string.Format("stack[{0}] = stack[{0}].BoolVal?FALSE:TRUE;", ins.StackBefore_ - 1));
                        break;
                    case SpokeInstructionType.IntConstant:
                        if (ins.Index >= 0 && ins.Index < 100)
                        {
                            exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("ints[{0}]", ins.Index)), true));
                            sb.AppendLine(string.Format("stack[{0}] = ints[{1}];", ins.StackBefore_, ins.Index));
                        }
                        else
                        {
                            exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("new SpokeObject( {0} )", ins.Index)), true));
                            sb.AppendLine(string.Format("stack[{0}] = new SpokeObject( {1} );", ins.StackBefore_, ins.Index));
                        }
                        break;
                    case SpokeInstructionType.BoolConstant:
                        sb.AppendLine(string.Format("stack[{0}] = {1};", ins.StackBefore_, ins.BoolVal ? "TRUE" : "FALSE"));
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(ins.BoolVal ? "TRUE" : "FALSE"), true));

                        break;
                    case SpokeInstructionType.FloatConstant:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("new SpokeObject( {0}f )", ins.FloatVal)), true));

                        sb.AppendLine(string.Format("stack[{0}] = new SpokeObject({1}f );", ins.StackBefore_, ins.FloatVal));
                        break;
                    case SpokeInstructionType.StringConstant:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString(string.Format("new SpokeObject( \"{0}\" )", ins.StringVal)), true));
                        sb.AppendLine(string.Format("stack[{0}] = new SpokeObject( \"{1}\" );", ins.StackBefore_, ins.StringVal));
                        break;

                    case SpokeInstructionType.Null:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_), new PostParseString("NULL"), true));
                        sb.AppendLine(string.Format("stack[{0}] = NULL;", ins.StackBefore_));
                        break;
                    case SpokeInstructionType.AddIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "intCache({0}.IntVal + {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=intCache(stack[{0}].IntVal + stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddStringInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.StringVal + {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject( stack[{0}].StringVal + stack[{1}].IntVal );", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddIntString:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.IntVal + {1}.StringVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].IntVal + stack[{1}].StringVal );", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddFloatString:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal + {1}.StringVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject( stack[{0}].FloatString + stack[{1}].StringVal );", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddStringFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.StringVal + {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].StringVal + stack[{1}].FloatVal );", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddStringString:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.StringVal + {1}.StringVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].StringVal + stack[{1}].StringVal );", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.SubtractIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "intCache({0}.IntVal - {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=intCache (stack[{0}].IntVal - stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.MultiplyIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "intCache({0}.IntVal * {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=intCache (stack[{0}].IntVal * stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.DivideIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "intCache({0}.IntVal / {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=intCache (stack[{0}].IntVal / stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_), "(({0}.IntVal > {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal > stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterIntFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_), "(({0}.IntVal > {1}.FloatVal)?TRUE:FALSE)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal > stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterFloatInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_), "(({0}.FloatVal > {1}.IntVal)?TRUE:FALSE)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal > stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_), "(({0}.FloatVal > {1}.FloatVal)?TRUE:FALSE)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal > stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.IntVal < {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal < stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessIntFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.IntVal < {1}.FloatVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal < stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessFloatInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.FloatVal < {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal < stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.FloatVal < {1}.FloatVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal < stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterEqualIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.IntVal >= {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal >= stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterEqualIntFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.IntVal >= {1}.FloatVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal >= stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterEqualFloatInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.FloatVal >= {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal >= stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.GreaterEqualFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.FloatVal >= {1}.FloatVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal >= stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessEqualIntInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.IntVal <= {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal <= stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessEqualIntFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.IntVal <= {1}.FloatVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].IntVal <= stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessEqualFloatInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "(({0}.FloatVal <= {1}.IntVal)?TRUE:FALSE)"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal <= stack[{1}].IntVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.LessEqualFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                          new PostParseOperation(
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                              new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                              "({0}.FloatVal <= {1}.FloatVal)?TRUE:FALSE"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].FloatVal <= stack[{1}].FloatVal)?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.Equal:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                                                  new PostParseOperation(
                                                      new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1),
                                                      new PostParseVariable(VariableType.Stack, ins.StackBefore_),
                                                      "(({0}.Compare({1})?TRUE:FALSE))"), true));

                        sb.AppendLine(string.Format("stack[{0}]=(stack[{0}].Compare(stack[{1}]))?TRUE:FALSE;", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;

                    case SpokeInstructionType.AddToArray:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1),
                                                  new PostParseStatement("{0}.AddArray({1})",
                                                                         new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1),
                                                                         new PostParseVariable(VariableType.Stack, ins.StackAfter_)), true));

                        sb.AppendLine(string.Format("stack[{0}].AddArray(stack[{1}]);", ins.StackAfter_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddRangeToArray:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1), new PostParseStatement("{0}.AddArrayRange({1})",
                                                                                                                            new PostParseVariable(VariableType.Stack, ins.StackAfter_ - 1),
                                                                                                                            new PostParseVariable(VariableType.Stack, ins.StackAfter_)), true));

                        sb.AppendLine(string.Format("stack[{0}].AddArrayRange(stack[{1}]);", ins.StackAfter_ - 1, ins.StackAfter_));
                        break;

                    case SpokeInstructionType.ArrayElem:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseStatement("{0}.ArrayItems[{1}.IntVal]", new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_)), true));
                        sb.AppendLine(string.Format("stack[{0}]=stack[{0}].ArrayItems[stack[{1}].IntVal];", ins.StackBefore_ - 1, ins.StackBefore_));

                        break;
                    case SpokeInstructionType.StoreArrayElem:

                        exps.Add(new PostParseStatement("{0}.ArrayItems[{1}.IntVal] = {2};", new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 2), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 3)));

                        sb.AppendLine(string.Format("stack[{1}].ArrayItems[stack[{0}].IntVal] = stack[{2}];", ins.StackBefore_ - 1, ins.StackBefore_ - 2, ins.StackBefore_ - 3));

                        break;

                    case SpokeInstructionType.AddIntFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.IntVal + {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].IntVal + stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_));

                        break;
                    case SpokeInstructionType.AddFloatInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal + {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].IntVal + stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.AddFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal + {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal + stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.SubtractIntFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.IntVal - {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].IntVal + stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.SubtractFloatInt:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal - {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal -stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.SubtractFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal - {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal - stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.MultiplyIntFloat:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.IntVal * {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].IntVal * stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_)); break;
                    case SpokeInstructionType.MultiplyFloatInt:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal * {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal * stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_)); break;
                    case SpokeInstructionType.MultiplyFloatFloat:
                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal *{1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal + stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_));
                        break;
                    case SpokeInstructionType.DivideIntFloat:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.IntVal / {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].IntVal / stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_)); break;
                    case SpokeInstructionType.DivideFloatInt:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal / {1}.IntVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal / stack[{1}].IntVal);", ins.StackBefore_ - 1, ins.StackAfter_)); break;
                    case SpokeInstructionType.DivideFloatFloat:

                        exps.Add(new PostParseSet(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseOperation(new PostParseVariable(VariableType.Stack, ins.StackBefore_ - 1), new PostParseVariable(VariableType.Stack, ins.StackAfter_), "new SpokeObject({0}.FloatVal / {1}.FloatVal)"), true));
                        sb.AppendLine(string.Format("stack[{0}]=new SpokeObject(stack[{0}].FloatVal / stack[{1}].FloatVal);", ins.StackBefore_ - 1, ins.StackAfter_)); break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            return new Tuple<string, List<PostParseExpression>>(sb.ToString(), exps);
        }
        private SpokeObject evaluateMethod(SpokeMethod fm, SpokeObject[] paras)
        {
            SpokeObject[] variables;

            #if stacktrace
            dfss.AppendLine( fm.Class.Name +" : : "+fm.MethodName+" Start");
            #endif

            SpokeObject lastStack;
            int stackIndex = 0;
            SpokeObject[] stack = new SpokeObject[3000];
            int index = 0;
            StackTracer st;
            if (reprintStackIndex == -1)
            {
                variables = new SpokeObject[fm.NumOfVars];

                for (int i = 0; i < fm.Parameters.Length; i++)
                {
                    variables[i] = paras[i];
                }

                stackTrace.Add(st = new StackTracer(stack, variables));
            }
            else
            {
                StackTracer rp = reprintStackTrace[stackTrace.Count];
                stack = rp.StackObjects;
                variables = rp.StackVariables;
                index = rp.InstructionIndex;
                stackIndex = rp.StackIndex;
                stackTrace.Add(st = new StackTracer(stack, variables));
                if (stackTrace.Count == reprintStackIndex)
                {
                    stack[stackIndex++] = rp.Answer;
                    reprintStackIndex = -1;
                    reprintStackTrace = null;
                }
            }

            for (; index < fm.Instructions.Length; index++)
            {
                var ins = fm.Instructions[index];
            #if stacktrace
                dfss.AppendLine(stackIndex + " ::  " + ins.ToString());
            #endif

                //        var fs = new fixStackTracer(stackTrace.ToArray());
                //       stackTrace = new List<StackTracer>(fs.Start(true));

                SpokeObject[] sps;

                SpokeObject bm;
                switch (ins.Type)
                {
                    case SpokeInstructionType.CreateReference:
                        stack[stackIndex++] = new SpokeObject(new SpokeObject[ins.Index], ins.StringVal);
                        break;
                    case SpokeInstructionType.CreateArray:
                        stack[stackIndex++] = new SpokeObject(new List<SpokeObject>(20));
                        break;
                    case SpokeInstructionType.CreateMethod:
                        stack[stackIndex++] = NULL;//new SpokeObject(ObjectType.Method) { AnonMethod = ins.anonMethod };
                        break;
                    case SpokeInstructionType.Label:
                        //   throw new NotImplementedException("");
                        break;
                    case SpokeInstructionType.Goto:

                        index = ins.Index;

                        break;
                    case SpokeInstructionType.Comment:

                        break;
                    case SpokeInstructionType.CallMethod:
                        st.InstructionIndex = index;
                        st.StackIndex = stackIndex;
                        sps = new SpokeObject[ins.Index3];
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            sps[i] = stack[--stackIndex];
                        }
                        stack[stackIndex++] = evaluateMethod(Methods[ins.Index], sps);
                        break;
                    case SpokeInstructionType.CallMethodFunc:
                        st.InstructionIndex = index;
                        st.StackIndex = stackIndex;
                        sps = new SpokeObject[ins.Index3];
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            sps[i] = stack[--stackIndex];
                        }

                        stack[stackIndex++] = Methods[ins.Index].MethodFunc(sps);
                        break;
                    case SpokeInstructionType.CallInternal:
                        sps = new SpokeObject[ins.Index3];
                        for (int i = ins.Index3 - 1; i >= 0; i--)
                        {
                            sps[i] = stack[--stackIndex];
                        }
                        st.InstructionIndex = index + 1;
                        st.StackIndex = stackIndex;

                        SpokeObject l = InternalMethods[ins.Index](sps);

                        if (ins.Index == 16)
                        {
                            GameBoard d = buildBoard(sps[4]);

                            throw new AskQuestionException(stackTrace,
                                                           new SpokeQuestion(sps[1].Variables[0].StringVal, sps[2].StringVal,
                                                                             sps[3].ArrayItems.Select(a => a.StringVal).ToArray()), d);
                        }
                        else
                        {
                            stack[stackIndex++] = l;
                        }

                        break;
                    case SpokeInstructionType.BreakpointInstruction:
                        Console.WriteLine("BreakPoint");
                        break;
                    case SpokeInstructionType.Return:
            #if stacktrace
                        dfss.AppendLine(fm.Class.Name + " : : " + fm.MethodName + " End");
            #endif
                        stackTrace.Remove(st);
                        return stack[--stackIndex];
                        break;
                    case SpokeInstructionType.IfTrueContinueElse:

                        if (stack[--stackIndex].BoolVal)
                            continue;

                        index = ins.Index;

                        break;
                    case SpokeInstructionType.Or:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].BoolVal || stack[stackIndex - 1].BoolVal) ? TRUE : FALSE;
                        stackIndex--;
                        break;
                    case SpokeInstructionType.And:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].BoolVal && stack[stackIndex - 1].BoolVal) ? TRUE : FALSE;
                        stackIndex--;
                        break;
                    case SpokeInstructionType.StoreLocalInt:
                        lastStack = stack[--stackIndex];
                        bm = variables[ins.Index];
                        variables[ins.Index] = new SpokeObject(ObjectType.Int) { IntVal = lastStack.IntVal };
                        break;
                    case SpokeInstructionType.StoreLocalFloat:
                        lastStack = stack[--stackIndex];
                        bm = variables[ins.Index];
                        variables[ins.Index] = new SpokeObject(ObjectType.Float) { FloatVal = lastStack.FloatVal };
                        break;
                    case SpokeInstructionType.StoreLocalBool:
                        lastStack = stack[--stackIndex];
                        bm = variables[ins.Index];
                        variables[ins.Index] = lastStack.BoolVal ? TRUE : FALSE;
                        break;
                    case SpokeInstructionType.StoreLocalString:
                        lastStack = stack[--stackIndex];
                        bm = variables[ins.Index];
                        variables[ins.Index] = new SpokeObject(ObjectType.String) { StringVal = lastStack.StringVal };
                        break;

                    case SpokeInstructionType.StoreLocalMethod:
                    case SpokeInstructionType.StoreLocalObject:
                        lastStack = stack[--stackIndex];
                        variables[ins.Index] = lastStack;
                        break;
                    case SpokeInstructionType.StoreLocalRef:
                        lastStack = stack[--stackIndex];
                        bm = variables[ins.Index];
                        bm.ClassName = lastStack.ClassName;
                        bm.Type = lastStack.Type;
                        //bm.Variables = lastStack.Variables;
                        //bm.ArrayItems = lastStack.ArrayItems;
                        bm.StringVal = lastStack.StringVal;
                        bm.IntVal = lastStack.IntVal;
                        bm.BoolVal = lastStack.BoolVal;
                        bm.FloatVal = lastStack.FloatVal;
                        break;

                    case SpokeInstructionType.StoreFieldBool:
                        lastStack = stack[--stackIndex];
                        lastStack.Variables[ins.Index] = stack[--stackIndex].BoolVal ? TRUE : FALSE;

                        break;
                    case SpokeInstructionType.StoreFieldInt:
                        lastStack = stack[--stackIndex];
                        lastStack.Variables[ins.Index] = new SpokeObject(ObjectType.Int) { IntVal = stack[--stackIndex].IntVal };

                        break;
                    case SpokeInstructionType.StoreFieldFloat:
                        lastStack = stack[--stackIndex];
                        lastStack.Variables[ins.Index] = new SpokeObject(ObjectType.Float) { FloatVal = stack[--stackIndex].FloatVal };

                        break;
                    case SpokeInstructionType.StoreFieldString:
                        lastStack = stack[--stackIndex];
                        lastStack.Variables[ins.Index] = new SpokeObject(ObjectType.String) { StringVal = stack[--stackIndex].StringVal };
                        break;

                    case SpokeInstructionType.StoreFieldMethod:
                    case SpokeInstructionType.StoreFieldObject:
                        lastStack = stack[--stackIndex];
                        lastStack.Variables[ins.Index] = stack[--stackIndex];

                        break;

                    case SpokeInstructionType.IfEqualsContinueAndPopElseGoto:

                        if (SpokeObject.Compare(stack[stackIndex - 2],
                                stack[stackIndex - 1]))
                        {
                            stackIndex = stackIndex - 2;
                            continue;
                        }

                        stackIndex = stackIndex - 1;
                        index = ins.Index;
                        break;
                    case SpokeInstructionType.StoreToReference:

                        lastStack = stack[--stackIndex];
                        stack[stackIndex - 1].Variables[ins.Index] = lastStack;
                        break;
                    case SpokeInstructionType.GetField:

                        stack[stackIndex - 1] = stack[stackIndex - 1].Variables[ins.Index];

                        break;
                    case SpokeInstructionType.GetLocal:

                        stack[stackIndex++] = variables[ins.Index];
                        break;
                    case SpokeInstructionType.PopStack:
                        stackIndex--;
                        break;
                    case SpokeInstructionType.Not:
                        stack[stackIndex - 1] = stack[stackIndex - 1].BoolVal ? FALSE : TRUE;
                        break;
                    case SpokeInstructionType.AddStringInt:
                        stack[stackIndex - 2] = new SpokeObject(ObjectType.String) { StringVal = stack[stackIndex - 2].StringVal + stack[stackIndex - 1].IntVal };
                        stackIndex--;

                        break;
                    case SpokeInstructionType.AddIntString:

                        stack[stackIndex - 2] = new SpokeObject(ObjectType.String) { StringVal = stack[stackIndex - 2].IntVal + stack[stackIndex - 1].StringVal };
                        stackIndex--;
                        break;
                    case SpokeInstructionType.IntConstant:
                        stack[stackIndex++] = intCache(ins.Index);
                        break;
                    case SpokeInstructionType.BoolConstant:

                        stack[stackIndex++] = ins.BoolVal ? TRUE : FALSE;
                        break;
                    case SpokeInstructionType.FloatConstant:
                        stack[stackIndex++] = new SpokeObject(ObjectType.Float) { FloatVal = ins.FloatVal };
                        break;
                    case SpokeInstructionType.StringConstant:

                        stack[stackIndex++] = new SpokeObject(ObjectType.String) { StringVal = ins.StringVal };
                        break;

                    case SpokeInstructionType.Null:
                        stack[stackIndex++] = NULL;
                        break;
                    case SpokeInstructionType.AddIntInt:
                        stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal + stack[stackIndex - 1].IntVal);
                        stackIndex--;
                        break;
                    case SpokeInstructionType.AddIntFloat:
                        break;
                    case SpokeInstructionType.AddFloatInt:
                        break;
                    case SpokeInstructionType.AddFloatFloat:
                        break;
                    case SpokeInstructionType.AddFloatString:
                        stack[stackIndex - 2] = new SpokeObject(ObjectType.String) { StringVal = stack[stackIndex - 2].FloatVal + stack[stackIndex - 1].StringVal };
                        stackIndex--;
                        break;
                    case SpokeInstructionType.AddStringFloat:
                        stack[stackIndex - 2] = new SpokeObject(ObjectType.String) { StringVal = stack[stackIndex - 2].StringVal + stack[stackIndex - 1].FloatVal };
                        stackIndex--;
                        break;
                    case SpokeInstructionType.AddStringString:
                        stack[stackIndex - 2] = new SpokeObject(ObjectType.String) { StringVal = stack[stackIndex - 2].StringVal + stack[stackIndex - 1].StringVal };
                        stackIndex--;
                        break;
                    case SpokeInstructionType.SubtractIntInt:
                        stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal - stack[stackIndex - 1].IntVal);
                        stackIndex--;

                        break;
                    case SpokeInstructionType.SubtractIntFloat:
                        break;
                    case SpokeInstructionType.SubtractFloatInt:
                        break;
                    case SpokeInstructionType.SubtractFloatFloat:
                        break;
                    case SpokeInstructionType.MultiplyIntInt:

                        stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal * stack[stackIndex - 1].IntVal);
                        stackIndex--;
                        break;
                    case SpokeInstructionType.MultiplyIntFloat:
                        break;
                    case SpokeInstructionType.MultiplyFloatInt:
                        break;
                    case SpokeInstructionType.MultiplyFloatFloat:
                        break;
                    case SpokeInstructionType.DivideIntInt:

                        stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal / stack[stackIndex - 1].IntVal);
                        stackIndex--;
                        break;
                    case SpokeInstructionType.DivideIntFloat:
                        break;
                    case SpokeInstructionType.DivideFloatInt:
                        break;
                    case SpokeInstructionType.DivideFloatFloat:
                        break;

                    case SpokeInstructionType.GreaterIntInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal > stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterIntFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal > stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterFloatInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal > stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterFloatFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal > stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessIntInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal < stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessIntFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal < stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessFloatInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal < stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessFloatFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal < stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterEqualIntInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal >= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterEqualIntFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal >= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterEqualFloatInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal >= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.GreaterEqualFloatFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal >= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessEqualIntInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal <= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessEqualIntFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal <= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessEqualFloatInt:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal <= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.LessEqualFloatFloat:
                        stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal <= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.Equal:
                        stack[stackIndex - 2] = SpokeObject.Compare(stack[stackIndex - 2], stack[stackIndex - 1]) ? TRUE : FALSE;
                        stackIndex = stackIndex - 1;
                        break;
                    case SpokeInstructionType.InsertToArray:
                        break;
                    case SpokeInstructionType.RemoveToArray:
                        break;
                    case SpokeInstructionType.AddToArray:
                        lastStack = stack[--stackIndex];
                        stack[stackIndex - 1].AddArray(lastStack);
                        break;
                    case SpokeInstructionType.AddRangeToArray:
                        lastStack = stack[--stackIndex];
                        stack[stackIndex - 1].AddRangeArray(lastStack);
                        break;
                    case SpokeInstructionType.LengthOfArray:
                        break;

                    case SpokeInstructionType.ArrayElem:

                        lastStack = stack[--stackIndex];
                        stack[stackIndex - 1] = stack[stackIndex - 1].ArrayItems[lastStack.IntVal];

                        break;
                    case SpokeInstructionType.StoreArrayElem:

                        var indexs = stack[--stackIndex];
                        var ars = stack[--stackIndex];

                        ars.ArrayItems[indexs.IntVal] = stack[--stackIndex];

                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }

            #if stacktrace
            dfss.AppendLine(fm.Class.Name + " : : " + fm.MethodName + " End");
            #endif
            stackTrace.Remove(st);
            return null;
        }
		public List<SpokeClass> Run(List<Class> someClasses, List<TokenMacroPiece> tp)
		{
			allMacros_ = tp;
			List<SpokeClass> classes = new List<SpokeClass>();


			SpokeClass cl = new SpokeClass();
			classes.Add(cl);

			cl.Name = "Array";
			cl.Methods = new List<SpokeMethod>()
							 {
								 new SpokeMethod()
									 {
										 MethodFunc = (a) =>
														  {
															  a[0].ArrayItems.Add(a[1]);
															  return null;
														  },
										 MethodName = "add",
										 Class = cl,
										 returnType = new SpokeType(ObjectType.Void),
										 Parameters = new string[]{"this","v"}
									 },new SpokeMethod()
									 {
										 MethodFunc = (a) =>
														  {
															  a[0].ArrayItems.Clear();  
															  return null;
														  },
										 MethodName = "clear",
										 returnType = new SpokeType(ObjectType.Void),
										 Class = cl,
										 Parameters = new string[]{"this"}
									 }, new SpokeMethod()
									 {
										 MethodFunc = (a) => new SpokeObject(a[0].ArrayItems.Count),
										 MethodName = "length",
										 Class = cl,
										 returnType = new SpokeType(ObjectType.Int),
										 Parameters = new string[]{"this"}
									 },                                 new SpokeMethod()
									 {
										 MethodFunc = (a) =>
														  {
															  a[0].ArrayItems.RemoveAll(b => SpokeObject.Compare(b,a[1]));
															  return null;
														  },
										 MethodName = "remove",
										 Class = cl,
										 returnType = new SpokeType(ObjectType.Void),
										 Parameters = new string[]{"this","v"}
									 },new SpokeMethod()
									 {
										 MethodFunc = (a) =>
														  {
															  return a[0].ArrayItems.Last();
														  },
										 MethodName = "last",
										 Class = cl,
										 returnType = new SpokeType(ObjectType.Null),
										 Parameters = new string[]{"this"}
									 },new SpokeMethod()
									 {
										 MethodFunc = (a) =>
														  {
															  return a[0].ArrayItems.First();
														  },
										 MethodName = "first",
										 returnType = new SpokeType(ObjectType.Null),
										 Class = cl,
										 Parameters = new string[]{"this"}
									 },                                 new SpokeMethod()
									 {
										 MethodFunc = (a) =>
														  {
															  a[0].ArrayItems.Insert(a[1].IntVal, a[2]);
															  return null;
														  },
										 MethodName = "insert",
										 Class = cl,
										 returnType = new SpokeType(ObjectType.Void),
										 Parameters = new string[]{"this","v","v2"}
									 }
							 };


			foreach (var @class in someClasses)
			{
				classes.Add(cl = new SpokeClass());
				cl.Variables = @class.VariableNames.ToArray();
				cl.Name = @class.Name;
				foreach (var method in @class.Methods)
				{
					SpokeMethod me;
					cl.Methods.Add(me = new SpokeMethod());
					me.MethodName = method.Name;

					me.Parameters = new string[method.paramNames.Count + 1];
					me.Parameters[0] = "this";
					for (int index = 0; index < method.paramNames.Count; index++)
					{
						me.Parameters[index + 1] = method.paramNames[index];
					}


					me.Class = cl;

					TokenEnumerator enumerator = new TokenEnumerator(method.Lines.ToArray());
#if DEBUGs
					sb.AppendLine("Evaluating " + cl.Name + ": " + me.MethodName);
#endif
					  
					me.Lines = getLines(enumerator, 2, new evalInformation()).ToArray();



					me.HasYieldReturn = linesHave(me.Lines, ISpokeLine.YieldReturn);
					me.HasYield = linesHave(me.Lines, ISpokeLine.Yield);
					me.HasReturn = linesHave(me.Lines, ISpokeLine.Return);


				}
			}


			return classes;

		}
 public PrintExpressions(SpokeMethod[] cla2, bool showIndex)
 {
     myCla2 = cla2.ToDictionary(a => a.Class.Name + a.MethodName);
     myShowIndex = showIndex;
 }
        private SpokeType evaluateMethod(SpokeMethod fm, SpokeType parent, SpokeType[] paras)
        {
            if (fm.Evaluated)
            {
                parent.Variables = fm.VariableRefs;
                return fm.returnType;
            }
            var db = anonMethodsEntered;
            anonMethodsEntered = new Dictionary<string, bool>();
            fm.Evaluated = true;
            SpokeVariableInfo variables = new SpokeVariableInfo();
            for (int i = 0; i < fm.Parameters.Length; i++)
            {
                variables.Add(fm.Parameters[i], paras[i], null);
            }

            var sm = new SpokeMethodParse();
            sm.RunningClass = parent;
            sm.Method = fm;
            if (fm.HasYield)
            {
                sm.ForYieldArray = new SpokeType(ObjectType.Unset) { };
                sm.ReturnType = new SpokeType(ObjectType.Array) { Type = ObjectType.Array, ArrayItemType = sm.ForYieldArray };
            }
            else
            {
                sm.ReturnType = new SpokeType(ObjectType.Unset);
            }

            fm.VariableRefs = parent.Variables;

            var toCotninue = SpokeInstruction.ins;

            SpokeInstruction.Beginner();
            var de = evaluateLines(ref fm.Lines, sm, variables);
            fm.Instructions = SpokeInstruction.Ender();
            SpokeInstruction.ins = toCotninue;

            fm.NumOfVars = variables.index;

            anonMethodsEntered = db;
            return de;
        }
        public PreparseInstructions(SpokeMethod[] item1)
        {
            mets = item1;

            preparseInstructions(mets);
        }
        private void preparseInstructions(SpokeMethod[] mets)
        {
            foreach (var spokeMethod in mets)
            {
                Dictionary<string, int> labels = new Dictionary<string, int>();
                if (spokeMethod.Instructions == null)
                {
                    continue;
                }
                for (int index = 0; index < spokeMethod.Instructions.Length; index++)
                {
                    var spokeInstruction = spokeMethod.Instructions[index];
                    if (spokeInstruction.Type == SpokeInstructionType.Label)
                    {
                        labels.Add(spokeInstruction.labelGuy, index);
                    }

                }
                for (int index = 0; index < spokeMethod.Instructions.Length; index++)
                {
                    var spokeInstruction = spokeMethod.Instructions[index];

                    if (spokeInstruction.Type == SpokeInstructionType.Goto && spokeInstruction.gotoGuy != null)
                    {
                        spokeInstruction.Index = labels[spokeInstruction.gotoGuy];
                    }
                    if (spokeInstruction.Type == SpokeInstructionType.IfTrueContinueElse)
                    {
                        spokeInstruction.Index = labels[spokeInstruction.elseGuy];
                    }
                    if (spokeInstruction.Type == SpokeInstructionType.IfEqualsContinueAndPopElseGoto)
                    {
                        spokeInstruction.Index = labels[spokeInstruction.elseGuy];
                    }
                }
            }

            StringBuilder sbw = new StringBuilder();

            foreach (var spokeMethod in mets)
            {
                sbw.AppendLine("Method: " + spokeMethod.Class.Name + ":" + spokeMethod.MethodName);
                if (spokeMethod.Instructions == null)
                {
                    continue;
                }
                //sbw.AppendLine("Variables: ");
                //foreach (var spokeType in spokeMethod.VariableRefs.allVariables) {
                //    sbw.AppendLine(spokeType.Item1 + "(" + spokeType.Item2 + "): " + spokeType.Item3);
                //}
                //sbw.AppendLine();
                for (int index = 0; index < spokeMethod.Instructions.Length; index++)
                {
                    var spokeInstruction = spokeMethod.Instructions[index];

                    sbw.AppendLine(index + "\t\t\t" +
                                   spokeInstruction.ToString());
                }
            }
            File.WriteAllText("C:\\spokeins.txt", sbw.ToString());

            foreach (var spokeMethod in mets)
            {
                if (spokeMethod.Instructions != null)
                {
                    doit(0, 0, spokeMethod.Instructions);
                }
            }

            var d = indexes.GroupBy(a => a.Type).Select(a => a.Key).ToArray();
        }
Exemple #14
0
        private SpokeObject evaluateMethod(SpokeMethod fm, SpokeObject[] paras)
        {
            SpokeObject[] variables = new SpokeObject[fm.NumOfVars];

            for (int i = 0; i < fm.Parameters.Length; i++)
            {
                variables[i] = paras[i];
            }

#if stacktrace
            dfss.AppendLine(fm.Class.Name + " : : " + fm.MethodName + " Start");
#endif

            SpokeObject   lastStack;
            int           stackIndex = 0;
            SpokeObject[] stack      = new SpokeObject[3000];


            for (int index = 0; index < fm.Instructions.Length; index++)
            {
                var ins = fm.Instructions[index];
#if stacktrace
                dfss.AppendLine(stackIndex + " ::  " + ins.ToString());
#endif

                SpokeObject[] sps;

                SpokeObject bm;
                switch (ins.Type)
                {
                case SpokeInstructionType.CreateReference:
                    stack[stackIndex++] = new SpokeObject(new SpokeObject[ins.Index]);
                    break;

                case SpokeInstructionType.CreateArray:
                    stack[stackIndex++] = new SpokeObject(new List <SpokeObject>(20));
                    break;

                case SpokeInstructionType.CreateMethod:
                    stack[stackIndex++] = NULL;    //new SpokeObject(ObjectType.Method) { AnonMethod = ins.anonMethod };
                    break;

                case SpokeInstructionType.Label:
                    //   throw new NotImplementedException("");
                    break;

                case SpokeInstructionType.Goto:

                    index = ins.Index;

                    break;

                case SpokeInstructionType.Comment:


                    break;

                case SpokeInstructionType.CallMethod:
                    sps = new SpokeObject[ins.Index3];
                    for (int i = ins.Index3 - 1; i >= 0; i--)
                    {
                        sps[i] = stack[--stackIndex];
                    }
                    stack[stackIndex++] = evaluateMethod(Methods[ins.Index], sps);
                    break;

                case SpokeInstructionType.CallMethodFunc:
                    sps = new SpokeObject[ins.Index3];
                    for (int i = ins.Index3 - 1; i >= 0; i--)
                    {
                        sps[i] = stack[--stackIndex];
                    }

                    stack[stackIndex++] = Methods[ins.Index].MethodFunc(sps);
                    break;

                case SpokeInstructionType.CallInternal:

                    sps = new SpokeObject[ins.Index3];
                    for (int i = ins.Index3 - 1; i >= 0; i--)
                    {
                        sps[i] = stack[--stackIndex];
                    }
                    stack[stackIndex++] = InternalMethods[ins.Index](sps);
                    break;

                case SpokeInstructionType.BreakpointInstruction:
                    Console.WriteLine("BreakPoint");
                    break;

                case SpokeInstructionType.Return:
#if stacktrace
                    dfss.AppendLine(fm.Class.Name + " : : " + fm.MethodName + " End");
#endif
                    return(stack[--stackIndex]);

                    break;

                case SpokeInstructionType.IfTrueContinueElse:

                    if (stack[--stackIndex].BoolVal)
                    {
                        continue;
                    }

                    index = ins.Index;

                    break;

                case SpokeInstructionType.Or:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].BoolVal || stack[stackIndex - 1].BoolVal) ? TRUE : FALSE;
                    stackIndex--;
                    break;

                case SpokeInstructionType.And:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].BoolVal && stack[stackIndex - 1].BoolVal) ? TRUE : FALSE;
                    stackIndex--;
                    break;

                case SpokeInstructionType.StoreLocalInt:
                    lastStack            = stack[--stackIndex];
                    bm                   = variables[ins.Index];
                    variables[ins.Index] = new SpokeObject(ObjectType.Int)
                    {
                        IntVal = lastStack.IntVal
                    };
                    break;

                case SpokeInstructionType.StoreLocalFloat:
                    lastStack            = stack[--stackIndex];
                    bm                   = variables[ins.Index];
                    variables[ins.Index] = new SpokeObject(ObjectType.Float)
                    {
                        FloatVal = lastStack.FloatVal
                    };
                    break;

                case SpokeInstructionType.StoreLocalBool:
                    lastStack            = stack[--stackIndex];
                    bm                   = variables[ins.Index];
                    variables[ins.Index] = lastStack.BoolVal ? TRUE : FALSE;
                    break;

                case SpokeInstructionType.StoreLocalString:
                    lastStack            = stack[--stackIndex];
                    bm                   = variables[ins.Index];
                    variables[ins.Index] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = lastStack.StringVal
                    };
                    break;

                case SpokeInstructionType.StoreLocalMethod:
                case SpokeInstructionType.StoreLocalObject:
                    lastStack            = stack[--stackIndex];
                    bm                   = variables[ins.Index];
                    variables[ins.Index] = lastStack;
                    break;

                case SpokeInstructionType.StoreLocalRef:
                    lastStack     = stack[--stackIndex];
                    bm            = variables[ins.Index];
                    bm.Variables  = lastStack.Variables;
                    bm.ArrayItems = lastStack.ArrayItems;
                    bm.StringVal  = lastStack.StringVal;
                    bm.IntVal     = lastStack.IntVal;
                    bm.BoolVal    = lastStack.BoolVal;
                    bm.FloatVal   = lastStack.FloatVal;
                    break;



                case SpokeInstructionType.StoreFieldBool:
                    lastStack = stack[--stackIndex];
                    lastStack.Variables[ins.Index] = stack[--stackIndex].BoolVal ? TRUE : FALSE;

                    break;

                case SpokeInstructionType.StoreFieldInt:
                    lastStack = stack[--stackIndex];
                    lastStack.Variables[ins.Index] = new SpokeObject(ObjectType.Int)
                    {
                        IntVal = stack[--stackIndex].IntVal
                    };

                    break;

                case SpokeInstructionType.StoreFieldFloat:
                    lastStack = stack[--stackIndex];
                    lastStack.Variables[ins.Index] = new SpokeObject(ObjectType.Float)
                    {
                        FloatVal = stack[--stackIndex].FloatVal
                    };

                    break;

                case SpokeInstructionType.StoreFieldString:
                    lastStack = stack[--stackIndex];
                    lastStack.Variables[ins.Index] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = stack[--stackIndex].StringVal
                    };
                    break;

                case SpokeInstructionType.StoreFieldMethod:
                case SpokeInstructionType.StoreFieldObject:
                    lastStack = stack[--stackIndex];
                    lastStack.Variables[ins.Index] = stack[--stackIndex];

                    break;


                case SpokeInstructionType.StoreToReference:

                    lastStack = stack[--stackIndex];
                    stack[stackIndex - 1].Variables[ins.Index] = lastStack;
                    break;

                case SpokeInstructionType.GetField:

                    stack[stackIndex - 1] = stack[stackIndex - 1].Variables[ins.Index];

                    break;

                case SpokeInstructionType.GetLocal:

                    stack[stackIndex++] = variables[ins.Index];
                    break;

                case SpokeInstructionType.PopStack:
                    stackIndex--;
                    break;

                case SpokeInstructionType.Not:
                    stack[stackIndex - 1] = stack[stackIndex - 1].BoolVal ? FALSE : TRUE;
                    break;

                case SpokeInstructionType.AddStringInt:
                    stack[stackIndex - 2] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = stack[stackIndex - 2].StringVal + stack[stackIndex - 1].IntVal
                    };
                    stackIndex--;

                    break;

                case SpokeInstructionType.AddIntString:

                    stack[stackIndex - 2] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = stack[stackIndex - 2].IntVal + stack[stackIndex - 1].StringVal
                    };
                    stackIndex--;
                    break;

                case SpokeInstructionType.IntConstant:
                    stack[stackIndex++] = intCache(ins.Index);
                    break;

                case SpokeInstructionType.BoolConstant:

                    stack[stackIndex++] = ins.BoolVal ? TRUE : FALSE;
                    break;

                case SpokeInstructionType.FloatConstant:
                    stack[stackIndex++] = new SpokeObject(ObjectType.Float)
                    {
                        FloatVal = ins.FloatVal
                    };
                    break;

                case SpokeInstructionType.StringConstant:

                    stack[stackIndex++] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = ins.StringVal
                    };
                    break;

                case SpokeInstructionType.Null:
                    stack[stackIndex++] = NULL;
                    break;

                case SpokeInstructionType.AddIntInt:
                    stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal + stack[stackIndex - 1].IntVal);
                    stackIndex--;
                    break;

                case SpokeInstructionType.AddIntFloat:
                    break;

                case SpokeInstructionType.AddFloatInt:
                    break;

                case SpokeInstructionType.AddFloatFloat:
                    break;

                case SpokeInstructionType.AddFloatString:
                    stack[stackIndex - 2] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = stack[stackIndex - 2].FloatVal + stack[stackIndex - 1].StringVal
                    };
                    stackIndex--;
                    break;

                case SpokeInstructionType.AddStringFloat:
                    stack[stackIndex - 2] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = stack[stackIndex - 2].StringVal + stack[stackIndex - 1].FloatVal
                    };
                    stackIndex--;
                    break;

                case SpokeInstructionType.AddStringString:
                    stack[stackIndex - 2] = new SpokeObject(ObjectType.String)
                    {
                        StringVal = stack[stackIndex - 2].StringVal + stack[stackIndex - 1].StringVal
                    };
                    stackIndex--;
                    break;

                case SpokeInstructionType.SubtractIntInt:
                    stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal - stack[stackIndex - 1].IntVal);
                    stackIndex--;

                    break;

                case SpokeInstructionType.SubtractIntFloat:
                    break;

                case SpokeInstructionType.SubtractFloatInt:
                    break;

                case SpokeInstructionType.SubtractFloatFloat:
                    break;

                case SpokeInstructionType.MultiplyIntInt:

                    stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal * stack[stackIndex - 1].IntVal);
                    stackIndex--;
                    break;

                case SpokeInstructionType.MultiplyIntFloat:
                    break;

                case SpokeInstructionType.MultiplyFloatInt:
                    break;

                case SpokeInstructionType.MultiplyFloatFloat:
                    break;

                case SpokeInstructionType.DivideIntInt:

                    stack[stackIndex - 2] = intCache(stack[stackIndex - 2].IntVal / stack[stackIndex - 1].IntVal);
                    stackIndex--;
                    break;

                case SpokeInstructionType.DivideIntFloat:
                    break;

                case SpokeInstructionType.DivideFloatInt:
                    break;

                case SpokeInstructionType.DivideFloatFloat:
                    break;

                case SpokeInstructionType.GreaterIntInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal > stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterIntFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal > stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterFloatInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal > stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterFloatFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal > stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessIntInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal < stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessIntFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal < stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessFloatInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal < stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessFloatFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal < stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterEqualIntInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal >= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterEqualIntFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal >= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterEqualFloatInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal >= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.GreaterEqualFloatFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal >= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessEqualIntInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal <= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessEqualIntFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].IntVal <= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessEqualFloatInt:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal <= stack[stackIndex - 1].IntVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.LessEqualFloatFloat:
                    stack[stackIndex - 2] = (stack[stackIndex - 2].FloatVal <= stack[stackIndex - 1].FloatVal) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.Equal:
                    stack[stackIndex - 2] = SpokeObject.Compare(stack[stackIndex - 2], stack[stackIndex - 1]) ? TRUE : FALSE;
                    stackIndex            = stackIndex - 1;
                    break;

                case SpokeInstructionType.InsertToArray:
                    break;

                case SpokeInstructionType.RemoveToArray:
                    break;

                case SpokeInstructionType.AddToArray:
                    lastStack = stack[--stackIndex];
                    stack[stackIndex - 1].AddArray(lastStack);
                    break;

                case SpokeInstructionType.AddRangeToArray:
                    lastStack = stack[--stackIndex];
                    stack[stackIndex - 1].AddRangeArray(lastStack);
                    break;

                case SpokeInstructionType.LengthOfArray:
                    break;

                case SpokeInstructionType.ArrayElem:

                    lastStack             = stack[--stackIndex];
                    stack[stackIndex - 1] = stack[stackIndex - 1].ArrayItems[lastStack.IntVal];

                    break;

                case SpokeInstructionType.StoreArrayElem:

                    var indexs = stack[--stackIndex];
                    var ars    = stack[--stackIndex];

                    ars.ArrayItems[indexs.IntVal] = stack[--stackIndex];


                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

#if stacktrace
            dfss.AppendLine(fm.Class.Name + " : : " + fm.MethodName + " End");
#endif

            return(null);
        }