private static EvaluationResult IsFalse(Context context, ModuleLiteral env, EvaluationStackFrame args) { var condition = Args.AsBool(args, 0); var message = Args.AsStringOptional(args, 1); Assert.False(condition, message); return(EvaluationResult.Undefined); }
private static EvaluationResult Assert(Context context, ModuleLiteral env, EvaluationStackFrame args) { bool predicate = Args.AsBool(args, 0); string message = Args.AsStringOptional(args, 1) ?? string.Empty; if (!predicate) { throw new ContractAssertException(message); } return(EvaluationResult.Undefined); }
private EvaluationResult AddIf(Context context, ModuleLiteral env, EvaluationStackFrame args) { var condition = Args.AsBool(args, 0); if (!condition) { // Return empty Array var entry = context.TopStack; return(EvaluationResult.Create(ArrayLiteral.CreateWithoutCopy(new EvaluationResult[0], entry.InvocationLocation, entry.Path))); } var items = Args.AsArrayLiteral(args, 1); return(EvaluationResult.Create(items)); }
private EvaluationResult AddIfLazy(Context context, ModuleLiteral env, EvaluationStackFrame args) { var condition = Args.AsBool(args, 0); if (!condition) { // Return empty Array var entry = context.TopStack; return(EvaluationResult.Create(ArrayLiteral.CreateWithoutCopy(new EvaluationResult[0], entry.InvocationLocation, entry.Path))); } // Call the function passed in and return that result var closure = Args.AsClosure(args, 1); var result = context.InvokeClosure(closure, closure.Frame); if (result.IsErrorValue) { return(EvaluationResult.Error); } return(result); }