当前位置: 首页>>代码示例>>C#>>正文


C# CodeGenContext.newobj方法代码示例

本文整理汇总了C#中CodeGenContext.newobj方法的典型用法代码示例。如果您正苦于以下问题:C# CodeGenContext.newobj方法的具体用法?C# CodeGenContext.newobj怎么用?C# CodeGenContext.newobj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CodeGenContext的用法示例。


在下文中一共展示了CodeGenContext.newobj方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            // hash = new Hash();
            context.newobj(Runtime.Hash.ctor);
            int hash = context.StoreInTemp("hash", Runtime.HashRef, location);

            Node entry = elements;
            while (entry != null)
            {
                bool key_created, value_created;

                ISimple key = context.PreCompute0(entry, "key", out key_created);
                entry = entry.nd_next;
                ISimple value = context.PreCompute0(entry, "value", out value_created);
                entry = entry.nd_next;

                // hash.Add(key, value);
                context.ldloc(hash);
                key.GenSimple(context);
                value.GenSimple(context);
                context.callvirt(Runtime.Hash.Add);

                context.ReleaseLocal(key, key_created);
                context.ReleaseLocal(value, value_created);
            }

            context.ldloc(hash);

            context.ReleaseLocal(hash, true);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:30,代码来源:Values.cs

示例2: GenSimple

        public void GenSimple(CodeGenContext context)
        {
            if (value is string)// T_STRING,
            {
                context.ldstr((string)(value));
                context.newobj(Runtime.String.ctor);
                return;
            }
            if (value is int)   // T_FIXNUM
            {
                context.ldc_i4((int)(value));
                context.box(PrimitiveType.Int32);
                return;
            }
            if (value is double)// T_FLOAT
            {
                context.ldc_r8((double)(value));
                context.newobj(Runtime.Float.ctor);
                return;
            }
            if (value is ID)    // T_SYMBOL
            {
                context.ldstr(((ID)value).ToString());
                context.newobj(Runtime.Symbol.ctor);
                return;
            }
            if (value is BigNum)
            {
                BigNum num = (BigNum) value;
                context.ldc_i4(num.sign);
                context.ldstr(num.ToString());
                context.ldc_i4(num.bas);
                context.newobj(Runtime.Bignum.ctor);
                return;
            }

            throw new System.NotImplementedException("VALUE " + value.GetType().ToString());
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:38,代码来源:VALUE.cs

示例3: AddScopeLocals

        internal void AddScopeLocals(CodeGenContext context)
        {
            // ------------------ Start new Context ----------------------------

            // [InteropMethod("MyClass")]
            // private class ActivationFrame: Ruby.Frame { ... }
            frame_def = context.CreateGlobalClass("_Internal", "Frame" + (N++), Runtime.FrameRef);

            Scope parentClass;
            for (parentClass = this; parentClass != null && !(parentClass is CLASS_OR_MODULE); parentClass = parentClass.parent_scope) ;

            string className = "";
            if (parentClass != null)
                className = ((CLASS_OR_MODULE)parentClass).internal_name;

            ClassDef fileClass = FileClass();
            string src = "";
            if (fileClass != null && fileClass.Name().StartsWith("SourceFile_"))
            {
                src = fileClass.Name().Substring(11);
                frame_def.AddCustomAttribute(Runtime.FrameAttribute.ctor, new Constant[] { new StringConst(src), new StringConst(className) });
            }

            foreach (string local in locals_list)
                CodeGenContext.AddField(frame_def, PERWAPI.FieldAttr.Public, ID.ToDotNetName(local), PrimitiveType.Object);

            // internal ActivationFrame(Frame caller): base(caller) { }
            CodeGenContext frame_ctor = context.CreateConstructor(frame_def, new Param(ParamAttr.Default, "caller", Runtime.FrameRef));
            frame_ctor.ldarg(0);
            frame_ctor.ldarg("caller");
            frame_ctor.call(Runtime.Frame.ctor);
            frame_ctor.ret();
            frame_ctor.Close();

            // internal string file() {
            CodeGenContext file = context.CreateMethod(frame_def, PERWAPI.MethAttr.PublicVirtual, "file", PrimitiveType.String);

            file.startMethod(this.location);
            //    return "thisfile.rb"
            file.ldstr(this.location.file);
            file.ret();
            file.Close();

            // internal override string methodName() {
            CodeGenContext methodName = context.CreateMethod(frame_def, PERWAPI.MethAttr.PublicVirtual, "methodName", PrimitiveType.String);
            methodName.startMethod(this.location);
            //    return "CurrentMethodName"
            methodName.ldstr(CurrentMethodName());
            methodName.ret();
            methodName.Close();

            CreateNestingMethod(frame_def, context);
            CreateLastClassMethod(frame_def, context);

            // ------------------ Return to Old Context ----------------------

            // ActivationFrame frame = new ActivationFrame(caller);
            context.ldarg("caller");
            context.newobj(frame_ctor.Method);
            int frame = context.StoreInTemp("frame", FrameClass, location);
            Debug.Assert(frame == 0);

            // frame.block_arg = block;
            context.ldloc(frame);
            LoadBlock0(context);
            context.stfld(Runtime.Frame.block_arg);

            if (this is BLOCK)
            {
                // frame.current_block = this;
                context.ldloc(frame);
                context.ldarg(0);
                context.stfld(Runtime.Frame.current_block);
            }
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:75,代码来源:Scoping.cs

示例4: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            MethodDef BlockN_constructor = GenerateClassForMethod(context);

            // new Ruby.Proc(recv, block, new BlockN(locals, this.locals1, this.locals2 ...), arity);            
            context.ldarg("recv");  // recv
            LoadBlock(context);

            context.ldloc(0);            // locals
            if (block_parent is BLOCK)
                foreach (FieldDef field in ((BLOCK)block_parent).frameFields)
                {
                    // this.localsN
                    context.ldarg(0);
                    context.ldfld(field);
                }

            context.newobj(BlockN_constructor);

            context.ldc_i4(arity);

            context.newobj(Runtime.Proc.ctor);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:23,代码来源:Methods.cs

示例5: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            bool start_created, finish_created;
            ISimple start = context.PreCompute(beg, "beg", out start_created);
            ISimple finish = context.PreCompute(end, "end", out finish_created);

            start.GenSimple(context);
            finish.GenSimple(context);
            context.PushTrue();
            context.newobj(Runtime.Range.ctor);

            context.ReleaseLocal(start, start_created);
            context.ReleaseLocal(finish, finish_created);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:14,代码来源:Operators.cs

示例6: GenRescue

        internal void GenRescue(CodeGenContext context, PERWAPI.CILLabel endLabel, int RescueTemp, RESCUE_CLAUSE clauses)
        {
            // catch (System.Exception e) {

            int e = context.StoreInTemp("e", Runtime.SystemExceptionRef, location);

            //if (e is Ruby.ControlException)
            PERWAPI.CILLabel else1 = context.NewLabel();
            context.ldloc(e);
            context.isinst(Runtime.ControlExceptionRef);
            context.brfalse(else1);
            //    throw e;
            context.rethrow();
            context.CodeLabel(else1);

            // Ruby.Exception exception;
            int exception = context.CreateLocal("exception", Runtime.ExceptionRef);

            //if (!(e is Ruby.RubyException))
            PERWAPI.CILLabel else2 = context.NewLabel();
            PERWAPI.CILLabel end = context.NewLabel();
            context.ldloc(e);
            context.isinst(Runtime.RubyExceptionRef);
            context.brtrue(else2);
            //    exception = new Ruby.CLRException(frame, e);
            context.ldloc(0);
            context.ldloc(e);
            context.newobj(Runtime.CLRException.ctor);
            context.stloc(exception);
            context.br(end);

            //else
            context.CodeLabel(else2);
            //     exception = (Ruby.RubyException)e.parent;
            context.ldloc(e);
            context.cast(Runtime.RubyExceptionRef);
            context.ldfld(Runtime.RubyException.parent);
            context.stloc(exception);

            context.CodeLabel(end);

            //Eval.ruby_errinfo.value = exception;
            context.ldsfld(Runtime.Eval.ruby_errinfo);
            context.ldloc(exception);
            context.stfld(Runtime.global_variable.value);

            if (clauses != null)
                clauses.GenCode(context, endLabel, RescueTemp, exception);

            context.rethrow();

            context.ReleaseLocal(e, true);
            context.ReleaseLocal(exception, true);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:54,代码来源:Exceptions.cs

示例7: GenCode0

        internal override void GenCode0(CodeGenContext context)
        {
            context.newLine(location);

            if (return_val != null)
                return_val.GenCode(context);
            else
                context.ldnull();

            if (this.parent_scope is BLOCK)
            {
                //throw new Ruby.ReturnException(return_value, this.defining_scope);
                context.ldarg(0);  // current Ruby.MethodBody
                context.ldfld(Runtime.Block.defining_scope);
                context.newobj(Runtime.ReturnException.ctor);
                context.throwOp();
            }
            else if (this.parent_scope is BEGIN)
            {
                //throw new Ruby.ReturnException(return_value, caller);
                context.ldarg("caller");
                context.newobj(Runtime.ReturnException.ctor);
                context.throwOp();
            }
            else
            {
                // return
                context.stloc(parent_scope.returnTemp);
                context.Goto(context.labels.Return);
            }
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:31,代码来源:ControlFlow.cs

示例8: GenArgList

        internal override ISimple GenArgList(CodeGenContext context, out bool created)
        {
            bool single = true;

            // ArgList arglist = new ArgList();
            context.newobj(Runtime.ArgList.ctor);
            int arglist = context.StoreInTemp("arglist", Runtime.ArgListRef, location);

            int added = 0;
            for (Node arg = parameters; arg != null; arg = arg.nd_next)
            {
                //object argument = arg;
                bool argument_created;
                ISimple argument = context.PreCompute0(arg, "arg", out argument_created);

                // arglist.Add(argument);
                context.ldloc(arglist);
                argument.GenSimple(context);
                context.callvirt(Runtime.ArgList.Add);
                added++;

                context.ReleaseLocal(argument, argument_created);
            }

            if (added != 1)
                single = false;

            if (hashlist != null)
            {
                // object hash = hashlist;
                bool hash_created;
                ISimple hash = context.PreCompute(new HASH(hashlist, hashlist.location), "hashlist", out hash_created);

                // arglist.Add(hash);
                context.ldloc(arglist);
                hash.GenSimple(context);
                context.callvirt(Runtime.ArgList.Add);
                single = false;

                context.ReleaseLocal(hash, hash_created);
            }

            if (array != null)
            {
                // object list = array;
                bool list_created;
                ISimple list = context.PreCompute(array, "array", out list_created);

                // arglist.AddArray(list, caller);
                context.ldloc(arglist);
                list.GenSimple(context);
                context.ldloc(0);
                context.callvirt(Runtime.ArgList.AddArray);
                single = false;

                context.ReleaseLocal(list, list_created);
            }

            if (block != null)
            {
                // object b = block;
                bool b_created;
                ISimple b = context.PreCompute(block, "block", Runtime.ProcRef, out b_created);

                // arglist.block = b;
                context.ldloc(arglist);
                b.GenSimple(context);
                context.stfld(Runtime.ArgList.block);

                context.ReleaseLocal(b, b_created);
            }

            if (single)
            {
                context.ldloc(arglist);
                context.PushTrue();
                context.stfld(Runtime.ArgList.single_arg);
            }

            created = true;
            return new LOCAL(arglist, location);
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:82,代码来源:Args.cs

示例9: GenCode0

 internal override void GenCode0(CodeGenContext context)
 {
     if (id is string)
         context.ldstr((string)id);
     else if (id is VALUE && ((VALUE)id).value is string)
         context.ldstr((string)((VALUE)id).value);
     else
     {
         ((Node)id).GenCode(context);
         context.ldfld(Runtime.String.value);
     }
         
     context.newobj(Runtime.Symbol.ctor);
 }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:14,代码来源:Strings.cs

示例10: CopyNormalFormals

        private void CopyNormalFormals(CodeGenContext context, Scope scope)
        {
            PERWAPI.CILLabel OKLabel = context.NewLabel();

            if (min_args > 0)
            {
                // if (args.Length < min_args)
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.get_Length);
                int length = context.StoreInTemp("length", PrimitiveType.Int32, location);
                context.ldloc(length);
                context.ldc_i4(min_args);
                context.bge(OKLabel);

                //context.Inst(Op.clt);
                //context.brfalse(OKLabel);

                // context.Branch(BranchOp.bge, OKLabel);

                // throw new ArgumentError(string.Format("wrong number of arguments ({0} for {1})", args.Length, arity).raise(caller);
                // FIXME: next line needs a String
                context.ldstr("wrong number of arguments ({0} for {1})");
                context.ldloc(length);
                context.box(PrimitiveType.Int32);
                context.ldc_i4(min_args);
                context.box(PrimitiveType.Int32);
                context.call(Runtime.SystemString.Format);
                context.newobj(Runtime.ArgumentError.ctor);
                context.ldloc(0);
                context.callvirt(Runtime.Exception.raise);
                context.throwOp();

                context.ReleaseLocal(length, true);

                // OKLabel:
                context.CodeLabel(OKLabel);
            }

            // Copy parameters to locals
            for (Node f = normal; f != null; f = f.nd_next)
            {
                string name = ID.ToDotNetName(((VAR)f).vid);

                // local.f = args.GetNext();
                context.ldloc(0);
                context.ldarg("args");
                context.callvirt(Runtime.ArgList.GetNext);
                context.stfld(scope.GetFrameField(name));
            }
        }
开发者ID:chunlea,项目名称:rubydotnetcompiler,代码行数:50,代码来源:Formals.cs


注:本文中的CodeGenContext.newobj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。