示例#1
0
    private void Build(DTryCatch node, Hints hints, CompilerContext ctx)
    {
        var gotcha = cw.DefineLabel();

        cw.Start(gotcha);
        Build(node.Expression, hints, ctx);

        AddLinePragma(node);
        cw.End();
        var skip = cw.DefineLabel();

        cw.Br(skip);
        cw.MarkLabel(gotcha);

        StartScope(ScopeKind.Lexical, node.Catch.Location);
        //We are inside a catch, we need preserve an exception object for
        //possible rethrows
        cw.Dup();
        var a = AddVariable();

        cw.PopVar(a);
        ctx.Errors.Push(a);

        if (node.BindVariable is not null)
        {
            AddLinePragma(node.BindVariable);

            if (node.BindVariable.Value is not "_")
            {
                var sv = AddVariable(node.BindVariable.Value, node.Catch.Location, VarFlags.Const);
                cw.PopVar(sv);
            }
            else
            {
                cw.Pop();
            }
        }

        Build(node.Catch, hints.Append(Catch), ctx);

        ctx.Errors.Pop();
        EndScope();

        cw.MarkLabel(skip);
        AddLinePragma(node);
        cw.Nop();
    }
示例#2
0
        private void Build(DTryCatch node, Hints hints, CompilerContext ctx)
        {
            var gotcha = cw.DefineLabel();

            cw.Start(gotcha);
            Build(node.Expression, hints, ctx);

            AddLinePragma(node);
            cw.End();
            var skip = cw.DefineLabel();

            cw.Br(skip);
            cw.MarkLabel(gotcha);

            StartScope(false, node.Catch.Location);

            if (node.BindVariable != null)
            {
                AddLinePragma(node.BindVariable);

                if (node.BindVariable.Value != "_")
                {
                    var sv = AddVariable(node.BindVariable.Value, node.Catch, VarFlags.Const);
                    cw.PopVar(sv);
                }
                else
                {
                    cw.Pop();
                }
            }

            Build(node.Catch, hints, ctx);
            EndScope();

            cw.MarkLabel(skip);
            AddLinePragma(node);
            cw.Nop();
        }