예제 #1
0
    internal override void GenCode(CompileContext compileContext)
    {
        int RealChildCount = this.ChildCount;

        if ((RealChildCount != 0) && (((baseNode)base.Children[RealChildCount - 1]).ChildCount == 0))
        {
            RealChildCount--;
        }
        compileContext.gen.Emit(OpCodes.Ldc_I4, RealChildCount);
        compileContext.gen.Emit(OpCodes.Newarr, typeof(JSValue));
        for (int i = 0; i < RealChildCount; i++)
        {
            compileContext.gen.Emit(OpCodes.Dup);
            compileContext.gen.Emit(OpCodes.Ldc_I4, i);
            baseNode n = (baseNode)base.Children[i];
            if (n.ChildCount == 0)
            {
                compileContext.gen.EmitCallV(CompileContext.mi_JSUndefined_Instance);
            }
            else
            {
                ((ExpressionNode)n.Children[0]).GenCode(compileContext);
            }
            compileContext.gen.Emit(OpCodes.Stelem_Ref);
        }
        compileContext.gen.Emit(OpCodes.Newobj, CompileContext.JSArray_ctor);
    }
예제 #2
0
    internal void GenFinallyForward(CompileContext compileContext, Label dest, baseNode destNode, bool bNeedLeave)
    {
        int n = this.PostFinallyLabels.Count;

        this.PostFinallyLabels.Add(new PostFinallyLabel()
        {
            destNode = destNode, lbl = dest, switchlabel = compileContext.gen.DefineLabel()
        });
        compileContext.gen.Emit(OpCodes.Ldc_I4, n);
        compileContext.gen.Emit(OpCodes.Stloc, this.FinallyFwdDest);
        compileContext.gen.Emit(bNeedLeave ? OpCodes.Leave : OpCodes.Br, this.FinEnd);
    }
예제 #3
0
    protected void GenInterStatementBreak(CompileContext compileContext, Label lbl, baseNode destNode)
    {
        tryStatementNode FinallyNode;
        bool             bNeedLeave = this.NeedLeave(destNode, out FinallyNode);

        if (FinallyNode != null)
        {
            FinallyNode.GenFinallyForward(compileContext, lbl, destNode, bNeedLeave);
        }
        else
        {
            compileContext.gen.Emit(bNeedLeave ? OpCodes.Leave : OpCodes.Br, lbl);
        }
    }
예제 #4
0
    internal override void GenStatementCode(CompileContext compileContext, bool bGenDebug)
    {
        Stack <baseNode> st = new Stack <baseNode>();

        st.Push(this);
        while (st.Count > 0)
        {
            baseNode t = st.Pop();
            for (int i = t.ChildCount - 1; i >= 0; i--)
            {
                baseNode c = (baseNode)t.Children[i];
                if (!(c is TopStatementList))
                {
                    st.Push(c);
                }
            }
            if (t is VarDeclStatement)
            {
                ((VarDeclStatement)t).GenCreate(compileContext);
            }
        }
        if (this.ChildCount != 0)
        {
            foreach (StatementNode n in base.Children)
            {
                if (n is functionDeclarationNode)
                {
                    ((functionDeclarationNode)n).GenCode(compileContext);
                }
            }
            foreach (StatementNode n in base.Children)
            {
                if (!(n is functionDeclarationNode))
                {
                    n.GenCode(compileContext);
                }
            }
        }
    }
예제 #5
0
    protected bool NeedLeave(baseNode destNode, out tryStatementNode FinallyNode)
    {
        FinallyNode = null;
        bool need = false;

        for (baseNode n = base.parent as baseNode; !(n is TopStatementList); n = n.parent as baseNode)
        {
            if (n.TryCatchLevels > 0)
            {
                need = true;
            }
            if (n is tryStatementNode)
            {
                FinallyNode = (tryStatementNode)n;
                return(need);
            }
            if (n == destNode)
            {
                return(need);
            }
        }
        return(need);
    }
예제 #6
0
    // $ANTLR start "arguments"
    // JavaScript.g:228:1: arguments : '(' ( ( LT )* assignmentExpression ( ( LT )* ',' ( LT )* assignmentExpression )* )? ( LT )* ')' ;
    public JavaScriptParser.arguments_return arguments() // throws RecognitionException [1]
    {   
        JavaScriptParser.arguments_return retval = new JavaScriptParser.arguments_return();
        retval.Start = input.LT(1);

        object root_0 = null;

        IToken char_literal257 = null;
        IToken LT258 = null;
        IToken LT260 = null;
        IToken char_literal261 = null;
        IToken LT262 = null;
        IToken LT264 = null;
        IToken char_literal265 = null;
        JavaScriptParser.assignmentExpression_return assignmentExpression259 = default(JavaScriptParser.assignmentExpression_return);

        JavaScriptParser.assignmentExpression_return assignmentExpression263 = default(JavaScriptParser.assignmentExpression_return);


        object char_literal257_tree=null;
        object LT258_tree=null;
        object LT260_tree=null;
        object char_literal261_tree=null;
        object LT262_tree=null;
        object LT264_tree=null;
        object char_literal265_tree=null;

        try 
    	{
            // JavaScript.g:229:2: ( '(' ( ( LT )* assignmentExpression ( ( LT )* ',' ( LT )* assignmentExpression )* )? ( LT )* ')' )
            // JavaScript.g:229:4: '(' ( ( LT )* assignmentExpression ( ( LT )* ',' ( LT )* assignmentExpression )* )? ( LT )* ')'
            {
            	root_0 = (object)adaptor.GetNilNode();

            	char_literal257=(IToken)Match(input,42,FOLLOW_42_in_arguments2001); if (state.failed) return retval;
            	if ( state.backtracking == 0 )
            	{char_literal257_tree = new baseNode(char_literal257) ;
            		root_0 = (object)adaptor.BecomeRoot(char_literal257_tree, root_0);
            	}
            	// JavaScript.g:229:19: ( ( LT )* assignmentExpression ( ( LT )* ',' ( LT )* assignmentExpression )* )?
            	int alt140 = 2;
            	alt140 = dfa140.Predict(input);
            	switch (alt140) 
            	{
            	    case 1 :
            	        // JavaScript.g:229:20: ( LT )* assignmentExpression ( ( LT )* ',' ( LT )* assignmentExpression )*
            	        {
            	        	// JavaScript.g:229:22: ( LT )*
            	        	do 
            	        	{
            	        	    int alt136 = 2;
            	        	    int LA136_0 = input.LA(1);

            	        	    if ( (LA136_0 == LT) )
            	        	    {
            	        	        alt136 = 1;
            	        	    }


            	        	    switch (alt136) 
            	        		{
            	        			case 1 :
            	        			    // JavaScript.g:229:22: LT
            	        			    {
            	        			    	LT258=(IToken)Match(input,LT,FOLLOW_LT_in_arguments2008); if (state.failed) return retval;

            	        			    }
            	        			    break;

            	        			default:
            	        			    goto loop136;
            	        	    }
            	        	} while (true);

            	        	loop136:
            	        		;	// Stops C# compiler whining that label 'loop136' has no statements

            	        	PushFollow(FOLLOW_assignmentExpression_in_arguments2012);
            	        	assignmentExpression259 = assignmentExpression();
            	        	state.followingStackPointer--;
            	        	if (state.failed) return retval;
            	        	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, assignmentExpression259.Tree);
            	        	// JavaScript.g:229:46: ( ( LT )* ',' ( LT )* assignmentExpression )*
            	        	do 
            	        	{
            	        	    int alt139 = 2;
            	        	    alt139 = dfa139.Predict(input);
            	        	    switch (alt139) 
            	        		{
            	        			case 1 :
            	        			    // JavaScript.g:229:47: ( LT )* ',' ( LT )* assignmentExpression
            	        			    {
            	        			    	// JavaScript.g:229:49: ( LT )*
            	        			    	do 
            	        			    	{
            	        			    	    int alt137 = 2;
            	        			    	    int LA137_0 = input.LA(1);

            	        			    	    if ( (LA137_0 == LT) )
            	        			    	    {
            	        			    	        alt137 = 1;
            	        			    	    }


            	        			    	    switch (alt137) 
            	        			    		{
            	        			    			case 1 :
            	        			    			    // JavaScript.g:229:49: LT
            	        			    			    {
            	        			    			    	LT260=(IToken)Match(input,LT,FOLLOW_LT_in_arguments2015); if (state.failed) return retval;

            	        			    			    }
            	        			    			    break;

            	        			    			default:
            	        			    			    goto loop137;
            	        			    	    }
            	        			    	} while (true);

            	        			    	loop137:
            	        			    		;	// Stops C# compiler whining that label 'loop137' has no statements

            	        			    	char_literal261=(IToken)Match(input,43,FOLLOW_43_in_arguments2019); if (state.failed) return retval;
            	        			    	// JavaScript.g:229:59: ( LT )*
            	        			    	do 
            	        			    	{
            	        			    	    int alt138 = 2;
            	        			    	    int LA138_0 = input.LA(1);

            	        			    	    if ( (LA138_0 == LT) )
            	        			    	    {
            	        			    	        alt138 = 1;
            	        			    	    }


            	        			    	    switch (alt138) 
            	        			    		{
            	        			    			case 1 :
            	        			    			    // JavaScript.g:229:59: LT
            	        			    			    {
            	        			    			    	LT262=(IToken)Match(input,LT,FOLLOW_LT_in_arguments2022); if (state.failed) return retval;

            	        			    			    }
            	        			    			    break;

            	        			    			default:
            	        			    			    goto loop138;
            	        			    	    }
            	        			    	} while (true);

            	        			    	loop138:
            	        			    		;	// Stops C# compiler whining that label 'loop138' has no statements

            	        			    	PushFollow(FOLLOW_assignmentExpression_in_arguments2026);
            	        			    	assignmentExpression263 = assignmentExpression();
            	        			    	state.followingStackPointer--;
            	        			    	if (state.failed) return retval;
            	        			    	if ( state.backtracking == 0 ) adaptor.AddChild(root_0, assignmentExpression263.Tree);

            	        			    }
            	        			    break;

            	        			default:
            	        			    goto loop139;
            	        	    }
            	        	} while (true);

            	        	loop139:
            	        		;	// Stops C# compiler whining that label 'loop139' has no statements


            	        }
            	        break;

            	}

            	// JavaScript.g:229:89: ( LT )*
            	do 
            	{
            	    int alt141 = 2;
            	    int LA141_0 = input.LA(1);

            	    if ( (LA141_0 == LT) )
            	    {
            	        alt141 = 1;
            	    }


            	    switch (alt141) 
            		{
            			case 1 :
            			    // JavaScript.g:229:89: LT
            			    {
            			    	LT264=(IToken)Match(input,LT,FOLLOW_LT_in_arguments2032); if (state.failed) return retval;

            			    }
            			    break;

            			default:
            			    goto loop141;
            	    }
            	} while (true);

            	loop141:
            		;	// Stops C# compiler whining that label 'loop141' has no statements

            	char_literal265=(IToken)Match(input,44,FOLLOW_44_in_arguments2036); if (state.failed) return retval;

            }

            retval.Stop = input.LT(-1);

            if ( (state.backtracking==0) )
            {	retval.Tree = (object)adaptor.RulePostProcessing(root_0);
            	adaptor.SetTokenBoundaries(retval.Tree, (IToken) retval.Start, (IToken) retval.Stop);}
        }
        catch (RecognitionException re) 
    	{
            ReportError(re);
            Recover(input,re);
    	// Conversion of the second argument necessary, but harmless
    	retval.Tree = (object)adaptor.ErrorNode(input, (IToken) retval.Start, input.LT(-1), re);

        }
        finally 
    	{
        }
        return retval;
    }
예제 #7
0
 internal void GenFinallyForward(CompileContext compileContext, Label dest, baseNode destNode, bool bNeedLeave)
 {
     int n = this.PostFinallyLabels.Count;
     this.PostFinallyLabels.Add(new PostFinallyLabel() { destNode = destNode, lbl = dest, switchlabel = compileContext.gen.DefineLabel() });
     compileContext.gen.Emit(OpCodes.Ldc_I4, n);
     compileContext.gen.Emit(OpCodes.Stloc, this.FinallyFwdDest);
     compileContext.gen.Emit(bNeedLeave ? OpCodes.Leave : OpCodes.Br, this.FinEnd);
 }
예제 #8
0
 protected bool NeedLeave(baseNode destNode, out tryStatementNode FinallyNode)
 {
     FinallyNode = null;
     bool need = false;
     for (baseNode n = base.parent as baseNode; !(n is TopStatementList); n = n.parent as baseNode)
     {
         if (n.TryCatchLevels > 0)
         {
             need = true;
         }
         if (n is tryStatementNode)
         {
             FinallyNode = (tryStatementNode) n;
             return need;
         }
         if (n == destNode)
         {
             return need;
         }
     }
     return need;
 }
예제 #9
0
 protected void GenInterStatementBreak(CompileContext compileContext, Label lbl, baseNode destNode)
 {
     tryStatementNode FinallyNode;
     bool bNeedLeave = this.NeedLeave(destNode, out FinallyNode);
     if (FinallyNode != null)
     {
         FinallyNode.GenFinallyForward(compileContext, lbl, destNode, bNeedLeave);
     }
     else
     {
         compileContext.gen.Emit(bNeedLeave ? OpCodes.Leave : OpCodes.Br, lbl);
     }
 }
예제 #10
0
    void CreatingAndSavingGrid()
    {
        string filename          = "grid.save";
        string saveDirectoryName = "saves";
        string saveDirectoryPath = Path.Combine(Application.persistentDataPath, saveDirectoryName);
        string filePath          = Path.Combine(saveDirectoryPath, filename);
        string saveData          = "saved grid for the level";



        if (!Directory.Exists(Path.Combine(saveDirectoryPath)))
        {
            Directory.CreateDirectory(saveDirectoryPath);
        }

        Node[][] grid       = gridManager.GetGridNodes();
        string[] tempString = new string[grid[0].Length];


        for (int i = 0; i < grid[0].Length; i++)
        {
            for (int j = 0; j < grid.Length; j++)
            {
                towerNode = grid[i][j].gameObject.GetComponent <GameNode>();
                gameBase  = grid[i][j].gameObject.GetComponent <baseNode>();

                if (gameBase != null)
                {
                    if (!gameBase.IsEmpty && grid[i][j].IsVisitable)
                    {
                        Debug.Log("p");
                        tempString[i] += "p";
                    }

                    if (!gameBase.IsEnemyBaseEmpty && grid[i][j].IsVisitable)
                    {
                        Debug.Log("e");
                        tempString[i] += "e";
                    }
                }

                if (!towerNode.IsEmpty && grid[i][j].IsVisitable)
                {
                    Debug.Log("t");

                    if (towerNode.getTower().GetData().baseStats.TorretNumber.Equals(1))
                    {
                        tempString[i] += "1";
                    }
                    if (towerNode.getTower().GetData().baseStats.TorretNumber.Equals(2))
                    {
                        tempString[i] += "2";
                    }
                    if (towerNode.getTower().GetData().baseStats.TorretNumber.Equals(3))
                    {
                        tempString[i] += "3";
                    }
                }
                else if (grid[i][j].IsVisitable && towerNode.IsEmpty && gameBase == null)
                {
                    Debug.Log("o");

                    tempString[i] += "o";
                }
                else if (!grid[i][j].IsVisitable && towerNode.IsEmpty && gameBase == null)
                {
                    Debug.Log("x");

                    tempString[i] += "x";
                }
            }
        }

        Debug.Log("Save was saved in: " + filePath + saveData);
        File.WriteAllLines(filePath, tempString);
    }