Beispiel #1
0
 public override ExitResult Run(NameContext context)
 {
     if (Condition.EvalBool(context))
         return Then != null ? Then.Run(context.NewChild()) : null;
     else
         return Else != null ? Else.Run(context.NewChild()) : null;
 }
Beispiel #2
0
 public override ExitResult Run(NameContext context)
 {
     var loopContext = context.NewChild();
     NameContext codeContext = null;
     var setInst = SetExpr.Eval(context);
     var instList = setInst.GetFields();
     if (instList != null)
         foreach (var inst in instList)
             if (Code != null)
             {
                 loopContext.SetField(VarName, inst);
                 if (codeContext == null)
                     codeContext = loopContext.NewChild();
                 var result = Code.Run(codeContext);
                 if (result != null)
                     switch (result.ExitMode)
                     {
                         case ExitMode.Break: break;
                         case ExitMode.Return: return result;
                         case ExitMode.Continue: continue;
                         case ExitMode.Except: return result;
                     }
             }
     return null;
 }
Beispiel #3
0
 public override ExitResult Run(NameContext context)
 {
     var result = Code.Run(context.NewChild());
     if (result != null && result.ExitMode == ExitMode.Except)
         if (Catch != null)
         {
             var catchResult = Catch.Run(context.NewChild());
             if (catchResult != null && catchResult.ExitMode != ExitMode.Normal)
                 return catchResult;
             result = null;
         }
     if (Finally != null)
     {
         var finalResult = Finally.Run(context.NewChild());
         if (finalResult != null && finalResult.ExitMode != ExitMode.Normal)
             return finalResult;
     }
     return result;
 }
Beispiel #4
0
 public ExitResult Call(NameContext context, Instance owner, Instance[] args)
 {
     if (NativeCode != null)
         return new ExitResult
         {
             ExitMode = Models.ExitMode.Normal,
             ExitValue = NativeCode(owner, args)
         };
     // nesse callContext serao guardados os parametros e o simbolo this=owner
     var callContext = context.NewChild();
     if (Params != null)
         for (var i = 0; i < Params.Length; i++)
             callContext.SetField(Params[i], args != null && i < args.Length ? args[i] : null);
     if (owner != null)
         callContext.SetField("this", owner);
     return Code.Run(callContext);
 }
Beispiel #5
0
 public override ExitResult Run(NameContext context)
 {
     NameContext codeContext = null;
     while (Condition.EvalBool(context))
         if (Code != null)
         {
             if (codeContext == null)
                 codeContext = context.NewChild();
             var result = Code.Run(codeContext);
             if (result != null)
                 switch (result.ExitMode)
                 {
                     case ExitMode.Break: break;
                     case ExitMode.Return: return result;
                     case ExitMode.Continue: continue;
                     case ExitMode.Except: return result;
                 }
         }
     return null;
 }
Beispiel #6
0
 public override ExitResult Run(NameContext context)
 {
     var switchContext = context.NewChild();
     var argInst = Arg.Eval(switchContext);
     var found = false;
     foreach (var someCase in Cases)
         if (someCase.Match(switchContext, argInst))
         {
             found = true;
             var caseResult = someCase.Run(switchContext);
             if (caseResult != null)
                 switch (caseResult.ExitMode)
                 {
                     case ExitMode.Break: return null;
                     case ExitMode.Return: return caseResult;
                     case ExitMode.Continue: return caseResult;
                     case ExitMode.Except: return caseResult;
                 }
         }
     if (!found && Default != null)
         return Default.Run(switchContext);
     return null;
 }