예제 #1
0
            public Continuation Perform(Continuation c)
            {
                var expansion = c.Result;

                c = c.PopResult();
                return(c.Evaluate(env, expansion));
            }
예제 #2
0
        public override Continuation Evaluate(Continuation c, Datum args)
        {
            var argArray    = args.ToArray();
            var expression  = argArray[0];
            var environment = (LexicalEnvironment)argArray[1].CastObject();

            return(c.Evaluate(environment, expression));
        }
예제 #3
0
 public override Continuation Evaluate(Continuation c, Datum args)
 {
     foreach (var ab in argBodies)
     {
         var closureEnv = ab.binding(env, args);
         if (closureEnv == null)
         {
             continue;
         }
         return(c.Evaluate(closureEnv, ab.body));
     }
     throw bindError(args);
 }
예제 #4
0
파일: Set.cs 프로젝트: 1tgr/FirstClassLisp
        public override Continuation Evaluate(Continuation c, Environment env, Datum args)
        {
            var argList = args.ToArray();

            if (argList.Length != 2)
            {
                throw c.error("Expected 2 arguments: (set! <symbol> <expression>). Got {0} instead", argList.Length);
            }
            var name       = argList[0].CastIdentifier();
            var expression = argList[1];

            c = c.PushTask(new SetName(env, name));
            return(c.Evaluate(env, expression));
        }
예제 #5
0
 public override Continuation Evaluate(Continuation c, Datum args)
 {
     foreach (var ab in argBodies)
     {
         var frameBindings = ab.binding(args);
         if (frameBindings == null)
         {
             continue;
         }
         var closureEnv = env.NewFrame(frameBindings);
         return(c.Evaluate(closureEnv, ab.body));
     }
     throw bindError(args);
 }
예제 #6
0
        public override Continuation Evaluate(Continuation c, LexicalEnvironment env, Datum args)
        {
            var argList = args.ToArray();

            if (argList.Length != 2)
            {
                throw c.error("Expected 2 arguments: (define <symbol> <expression>). Got {0} instead", argList.Length);
            }
            var name       = argList[0].CastSymbol();
            var expression = argList[1];

            c = c.PushTask(
                tc => { env.Define(name, tc.Result);
                        return(tc); },
                "define '{0}'", name);
            return(c.Evaluate(env, expression));
        }
예제 #7
0
        public override Continuation Evaluate(Continuation c, LexicalEnvironment env, Datum args)
        {
            var argList = args.ToArray();

            if (argList.Length < 1)
            {
                throw c.error("Expected at least 1 expression for begin. Got none.");
            }
            // Scope any local definitions.
            var localEnv  = env.NewFrame();
            var remaining = argList.Reverse().ToArray();

            for (var i = 0; i < remaining.Length; ++i)
            {
                if (i > 0)
                {
                    c = c.PushTask(popResult, "Discard result");
                }
                c = c.Evaluate(localEnv, remaining[i]);
            }
            return(c);
        }
예제 #8
0
        public override Continuation Evaluate(Continuation c, Environment env, Datum args)
        {
            var argList = args.ToArray();

            if (argList.Length < 1)
            {
                throw c.error("Expected at least 1 expression for begin. Got none.");
            }
            // Scope any local definitions.
            var localEnv  = new Environment(env);
            var remaining = argList.Reverse().ToArray();

            for (var i = 0; i < remaining.Length; ++i)
            {
                if (i > 0)
                {
                    c = c.PushTask(Ignore.Instance);
                }
                c = c.Evaluate(localEnv, remaining[i]);
            }
            return(c);
        }