예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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));
        }
예제 #4
0
        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);
        }