Exemplo n.º 1
0
    public void visit(StmtNode_Assign node)
    {
        var indexOfExpr = node.Lexpr as ExprNode_IndexOf;

        if (indexOfExpr != null)
        {
            new ExprNodeVisitor_CodeEmitor(this, typeof(object), indexOfExpr.ArrayExpr);
            new ExprNodeVisitor_CodeEmitor(this, typeof(int), indexOfExpr.IndexExpr);
            new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
            ILGenerator.Emit(OpCodes.Callvirt, typeof(List <object>).GetMethod("set_Item"));
        }
        else
        {
            var idExpr = node.Lexpr as ExprNode_ID;
            Trace.Assert(idExpr != null);

            var argIdx = getArg(idExpr.Name);
            if (argIdx != -1)
            {
                new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
                if (argIdx < 256)
                {
                    ILGenerator.Emit(OpCodes.Starg_S, argIdx);
                }
                else
                {
                    ILGenerator.Emit(OpCodes.Starg, argIdx);
                }
                return;
            }
            var local = getLocal(idExpr.Name);
            if (local != null)
            {
                new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
                ILGenerator.Emit(OpCodes.Stloc, local);
                return;
            }

            ILGenerator.Emit(OpCodes.Ldsfld, Emitor.GlobalField);
            ILGenerator.Emit(OpCodes.Ldstr, idExpr.Name);
            new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
            ILGenerator.Emit(OpCodes.Callvirt, typeof(Dictionary <string, object>).GetMethod("set_Item"));
        }
    }
Exemplo n.º 2
0
    public void visit(StmtNode_Assign node)
    {
        var indexOfExpr = node.Lexpr as ExprNode_IndexOf;
        if (indexOfExpr != null) {
            new ExprNodeVisitor_CodeEmitor(this, typeof(object), indexOfExpr.ArrayExpr);
            new ExprNodeVisitor_CodeEmitor(this, typeof(int), indexOfExpr.IndexExpr);
            new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
            ILGenerator.Emit(OpCodes.Callvirt, typeof(List<object>).GetMethod("set_Item"));
        } else {
            var idExpr = node.Lexpr as ExprNode_ID;
            Trace.Assert(idExpr != null);

            var argIdx = getArg(idExpr.Name);
            if (argIdx != -1) {
                new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
                if (argIdx < 256) ILGenerator.Emit(OpCodes.Starg_S, argIdx);
                else ILGenerator.Emit(OpCodes.Starg, argIdx);
                return;
            }
            var local = getLocal(idExpr.Name);
            if (local != null) {
                new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
                ILGenerator.Emit(OpCodes.Stloc, local);
                return;
            }

            ILGenerator.Emit(OpCodes.Ldsfld, Emitor.GlobalField);
            ILGenerator.Emit(OpCodes.Ldstr, idExpr.Name);
            new ExprNodeVisitor_CodeEmitor(this, typeof(object), node.Rexpr);
            ILGenerator.Emit(OpCodes.Callvirt, typeof(Dictionary<string, object>).GetMethod("set_Item"));
        }
    }