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


C# Kernel.PushScope方法代码示例

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


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

示例1: Compile

        public override void Compile(Kernel k)
        {
            k.CurrentScope.PushMemory(k);

            Scope ifScope = k.PushScope();
            ifScope.Name = "if" + ifScope.Parent.RequestLabelId();

            string trueLabel = "sl_if_" + k.GetScopeName();
            string falseLabel = "sl_fe_" + k.GetScopeName();
            string endLabel = "sl_fh_" + k.GetScopeName();

            this.Check.Compile(k);

            k.Emit(Opcode.GOTOF, '"' + trueLabel + '"').SetDebug(File, Line, Column, DebugType.Branch, "");
            k.Emit(Opcode.GOTO, '"' + falseLabel + '"');

            k.Emit(Opcode.LABEL, trueLabel);

            k.CurrentScope.PushMemory(k);

            Scope trueScope = k.PushScope();
            trueScope.Name = "true";

            if (this.BranchTrue != null)
                this.BranchTrue.Compile(k);

            k.PopScope();

            k.CurrentScope.PopMemory(k);

            if(this.BranchFalse == null)
            {
                k.Emit(Opcode.LABEL, falseLabel).Comment = "no else block, used as end label";
            }
            else if(this.BranchFalse != null)
            {
                k.Emit(Opcode.GOTO, '"' + endLabel + '"');

                k.Emit(Opcode.LABEL, falseLabel);

                k.CurrentScope.PushMemory(k);

                Scope falseScope = k.PushScope();
                falseScope.Name = "false";

                this.BranchFalse.Compile(k);

                k.PopScope();

                k.CurrentScope.PopMemory(k);

                k.Emit(Opcode.LABEL, endLabel).Comment = "end if";
            }

            k.PopScope();

            k.CurrentScope.PopMemory(k);
        }
开发者ID:redxdev,项目名称:shogun-old,代码行数:58,代码来源:IfNode.cs

示例2: Compile

        public override void Compile(Kernel k)
        {
            k.CurrentScope.PushMemory(k);

            Scope scope = k.PushScope();
            scope.Name = "for" + scope.Parent.RequestLabelId();

            if (this.Init != null)
                this.Init.Compile(k);

            string forLabel = "sl_fl_" + k.GetScopeName();
            string endLabel = "sl_flh_" + k.GetScopeName();

            Symbol breakSymbol = new Symbol()
                {
                    Name = "+break",
                    AsmName = endLabel
                };
            k.RegisterSymbol(breakSymbol);

            k.Emit(Opcode.LABEL, forLabel).Comment = "for loop";
            k.Emit(Opcode.NOOP).SetDebug(File, Line, Column, DebugType.ForLoop, "");

            this.Check.Compile(k);

            k.Emit(Opcode.NOT);
            k.Emit(Opcode.GOTOF, '"' + endLabel + '"');

            scope.PushMemory(k);

            Scope innerScope = k.PushScope();
            innerScope.Name = "in";

            if (this.Body != null)
                this.Body.Compile(k);

            k.EmitPush(innerScope.MemorySpace.ToString() + "u");
            k.Emit(Opcode.DEALLOC);

            k.PopScope();
            scope.PopMemory(k);

            if (this.Increment != null)
                this.Increment.Compile(k);

            k.Emit(Opcode.GOTO, '"' + forLabel + '"');
            k.Emit(Opcode.LABEL, endLabel).Comment = "end for";

            k.PopScope();

            k.CurrentScope.PopMemory(k);
        }
开发者ID:redxdev,项目名称:shogun-old,代码行数:52,代码来源:ForLoopNode.cs

示例3: Compile

        public override void Compile(Kernel k)
        {
            Symbol symbol = new Symbol()
                {
                    Name = this.Function,
                    SMode = Symbol.Mode.Intern,
                    SType = Symbol.Type.Function,
                    Args = (uint)this.Arguments.Count
                };

            k.RegisterSymbol(symbol);

            Scope scope = k.PushScope();
            scope.Name = this.Function;
            scope.MemorySpace += (uint)this.Arguments.Count + 1;

            symbol.AsmName = string.Format("sl_f_{0}", k.GetScopeName());

            switch(k.CurrentImportMode)
            {
                case ImportMode.Library:
                    k.PopScope();
                    symbol.SMode = Symbol.Mode.Library;
                    symbol.Id = k.CurrentScope.RequestId();
                    k.CurrentScope.MemorySpace++;
                    k.AddImport(symbol);
                    return;

                case ImportMode.Export:
                    k.AddExport(symbol);
                    break;
            }

            k.Emit(Opcode.LABEL, symbol.AsmName).Comment = "function " + this.Function; // function label
            k.Emit(Opcode.NOOP).SetDebug(File, Line, Column, DebugType.Function, this.Function);

            k.EmitPush(scope.MemorySpace.ToString() + "u").Comment = "allocate function parameter memory"; // allocate memory space for arguments and return location
            k.Emit(Opcode.ALLOC);

            Symbol returnSymbol = new Symbol()
                {
                    Name = "+return",
                    SMode = Symbol.Mode.Intern,
                    SType = Symbol.Type.Variable,
                    Id = k.CurrentScope.RequestId()
                };
            k.RegisterSymbol(returnSymbol);

            k.EmitPush(returnSymbol.Id.ToString() + "u").Comment = "store return location"; // store the return location
            k.Emit(Opcode.STLO);

            foreach(string arg in this.Arguments)
            {
                Symbol argSymbol = new Symbol()
                    {
                        Name = arg,
                        SMode = Symbol.Mode.Intern,
                        SType = Symbol.Type.Variable,
                        Id = k.CurrentScope.RequestId()
                    };
                k.RegisterSymbol(argSymbol);

                k.EmitPush(argSymbol.Id.ToString() + "u").Comment = "store argument " + arg; // store the argument
                k.Emit(Opcode.STLO);
            }

            k.Emit(Opcode.NOOP).Comment = "function body";

            if (this.Body != null)
                this.Body.Compile(k);

            new ReturnNode(-1, -1).Compile(k);

            k.PopScope();

            k.Emit(Opcode.NOOP).Comment = "end of function";
        }
开发者ID:redxdev,项目名称:shogun-old,代码行数:77,代码来源:InternalFunctionNode.cs


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