Пример #1
0
        public void Eval_IdentifiersAndKeywordsCoexistIndependently()
        {
            _env.Bind(ClSymbol.And, Value.One);
            var expr = BuiltIn.ListOf(ClSymbol.And, ClBool.True, Value.Foo);

            Assert.That(ClSymbol.And.Reduce(_ctx).Value, Is.EqualTo(Value.One));
            Assert.That(expr.Reduce(_ctx).Value, Is.EqualTo(Value.Foo));
        }
Пример #2
0
        public void EvalApplication_ThrowInvalidFunctionCall_WhenCarIsNotCallable()
        {
            _env.Bind(Var.Fn, Value.One);
            var expr         = BuiltIn.ListOf(Var.Fn, Value.One);
            var errorMessage = $"{nameof(ClInt)} is neither callable nor special from";

            Assert.That(() => expr.Reduce(_ctx),
                        Throws.Exception.TypeOf <SyntaxError>().With.Message.EqualTo(errorMessage));
        }
        public void EvalDefinition_CreateSharedReference()
        {
            _env.Bind(Var.Bar, Value.Bar);
            var expr = BuiltIn.ListOf(ClSymbol.Define, Var.Foo, Var.Bar);

            Ignore(expr.Reduce(_ctx));

            Assert.That(Object.ReferenceEquals(_env.Lookup(Var.Foo), _env.Lookup(Var.Bar)), Is.True);
        }
Пример #4
0
        public async Task Run()
        {
            using (var socket = await _env.Bind(_port)) {
                while (!_env.Token.IsCancellationRequested)
                {
                    var conn = await socket.Accept();

                    HandleAsync(conn);
                }
            }
        }
Пример #5
0
        async Task EventLoop()
        {
            try {
                using (var socket = await _env.Bind(_port)) {
                    while (!_env.Token.IsCancellationRequested)
                    {
                        var conn = await socket.Accept();

                        HandleRequest(conn);
                    }
                }
            } catch (TaskCanceledException) {
                return;
            }
        }
        public void EvalAssignment_SharedReference()
        {
            _env.Bind(Var.Foo, Value.Foo);
            _env.Bind(Var.Bar, Value.Bar);
            var expr = BuiltIn.ListOf(ClSymbol.Set, Var.Foo, Var.Bar);

            var ctx = expr.Reduce(_ctx);

            Assert.That(Object.ReferenceEquals(ctx.Env.Lookup(Var.Foo), _env.Lookup(Var.Bar)), Is.True);
        }
Пример #7
0
 public static Task <ISocket> Bind(this IEnv env, ushort port)
 {
     return(env.Bind(port, Timeout.InfiniteTimeSpan));
 }