ExitScope() public static method

public static ExitScope ( bool DoNotDestroy = false ) : void
DoNotDestroy bool
return void
Example #1
0
 public override Value Run()
 {
     Compiler.SetAsCurrentScope(Identifiers);
     base.Run();
     Compiler.ExitScope(true);
     return(this);
 }
Example #2
0
 public override Value Run()
 {
     Compiler.EnterScope();
     while (((Boolean)condition.Run()).Val)
     {
         base.Run();
     }
     Compiler.ExitScope();
     return(NoValue.Value);
 }
Example #3
0
 public override Value Evaluate()
 {
     if (Compiler.Runtime)
     {
         Reference reference = Compiler.Identify(Name);
         if (reference == NullReference.Value)
         {
             reference = Compiler.Reserve(this);
             Compiler.SetAlias(Name, reference);
         }
         if (Compiler.PendingDot)
         {
             Compiler.PendingDot = false;
             Compiler.ExitScope(true);
         }
         reference.Identifier = Name;
         return(reference);
     }
     return(NoValue.Value);
 }
Example #4
0
        public virtual Value Invoke(List Args)
        {
            Compiler.SetAsCurrentScope(Scope);
            Compiler.EnterScope();
            for (int i = 0; i < Math.Min(Args.Arr.Count, args.Count); ++i)
            {
                if (Args.Arr[i] is Reference)
                {
                    ((Reference) new Identifier(args[i].Val).Evaluate()).ChangeReference(Args.Arr[i] as Reference);
                }
                else
                {
                    ((Reference) new Identifier(args[i].Val).Evaluate()).ChangeReference(Args.Arr[i]);
                }
            }
            Value result = Run();

            Compiler.ExitScope(true);
            return(result);
        }
Example #5
0
        public virtual Value Run()
        {
            if (type == CodeBlockType.Other)
            {
                Compiler.EnterScope();
            }
            var solvingStack = new Stack <Value>();

            for (int i = 0; i < value.Count; ++i)
            {
                if (value[i] is Operator)
                {
                    var op = (Operator)value[i];
                    if (op is ContinueOperator)
                    {
                        Compiler.Fallthrough = FallThroughType.Continue;
                    }
                    else if (op is BreakOperator)
                    {
                        Compiler.Fallthrough = FallThroughType.Break;
                    }
                    else
                    {
                        if (op is ReturnOperator)
                        {
                            Compiler.Fallthrough = FallThroughType.Return;
                        }
                        Value second = NoValue.Value;
                        if (op.Type != OperatorType.PrefixUnary && op.Type != OperatorType.SufixUnary)
                        {
                            second = solvingStack.Pop();
                        }
                        Value result = op.Operate(solvingStack.Pop(), second);
                        if (result != Nothing.Value)
                        {
                            solvingStack.Push(result);
                        }
                    }
                }
                else
                {
                    solvingStack.Push(((Value)value[i]).Evaluate());
                }
                if (Compiler.Fallthrough != FallThroughType.NoFallthrough)
                {
                    if (type == CodeBlockType.Function && Compiler.Fallthrough == FallThroughType.Return)
                    {
                        Compiler.Fallthrough = FallThroughType.NoFallthrough;
                        break;
                    }
                    if (type == CodeBlockType.Loop)
                    {
                        if (Compiler.Fallthrough == FallThroughType.Continue)
                        {
                            Compiler.Fallthrough = FallThroughType.NoFallthrough;
                            i = -1;
                            solvingStack.Clear();
                            continue;
                        }
                        if (Compiler.Fallthrough == FallThroughType.Break)
                        {
                            Compiler.Fallthrough = FallThroughType.NoFallthrough;
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            Value toReturn = NoValue.Value;

            if (solvingStack.Count > 0)
            {
                toReturn = solvingStack.Peek().Evaluate();
            }
            if (toReturn is Reference)
            {
                toReturn = (toReturn as Reference).ReferencingValue;
            }

            Compiler.StoreValuesOutOfScope = true;             //Make sure the returning value is not destroyed when exiting the function's scope
            if (toReturn is Literal)
            {
                toReturn = toReturn.Clone();
            }
            Compiler.StoreValuesOutOfScope = false;

            if (type != CodeBlockType.Loop && type != CodeBlockType.Type)
            {
                Compiler.ExitScope();
            }
            return(toReturn);
        }