Esempio n. 1
0
        protected ISExpression Continuation(Stack <IFrame> s, ISchemeVM vm)
        {
            var v = AtomHelper.SymbolFromString("v");

            return(Closure(new NuateInstruction(s, v), AtomHelper.CreateEnvironment(),
                           AtomHelper.CreateList(v)));
        }
Esempio n. 2
0
        public void TestScripts()
        {
            var path  = Path.GetDirectoryName(typeof(ScriptTests).GetTypeInfo().Assembly.Location);
            var tests = File.ReadAllText(Path.Combine(path, "tests.scm"));

            var def = AtomHelper.CreateList(
                AtomHelper.SymbolFromString("define"),
                AtomHelper.SymbolFromString("test"),
                AtomHelper.CreateList(AtomHelper.SymbolFromString("lambda"), AtomHelper.Nil, AtomHelper.CreateProcedure("test", Test, false))
                );

            Eval(def);

            var errors = "";
            var exprs  = EvalAll(tests).ToArray();

            for (var i = 0; i < exprs.Count(); i++)
            {
                var result = exprs[i];
                if (result == null)
                {
                    continue;
                }

                if (result.IsString())
                {
                    errors += result.String() + "\n";
                }
            }
            if (errors != "")
            {
                Assert.Fail(errors);
            }
        }
Esempio n. 3
0
        public override object VisitQuote([NotNull] SchemeParser.QuoteContext context)
        {
            var expr = (ISExpression)Visit(context.datum());

            return(AtomHelper.CreateCons(
                       AtomHelper.SymbolFromString("quote"),
                       AtomHelper.CreateCons(expr, AtomHelper.Nil)));
        }
Esempio n. 4
0
 public void TestLocs()
 {
     VM.E.DefineHere(AtomHelper.SymbolFromString("a"), Eval("(1 . 2)"));
     VM.E.DefineHere(AtomHelper.SymbolFromString("b"), Eval("\"test\""));
     VM.E.DefineHere(AtomHelper.SymbolFromString("c"), Eval("#(1 2)"));
     Assert.AreEqual(AtomHelper.True, Eval("(eqv? a a)"));
     Assert.AreEqual(AtomHelper.True, Eval("(eqv? b b)"));
     Assert.AreEqual(AtomHelper.True, Eval("(eqv? c c)"));
     Assert.AreEqual(AtomHelper.True, Eval("(eqv? + +)"));
     Assert.AreEqual(AtomHelper.False, Eval("(eqv? (1 . 2) (1 . 2))"));
 }
Esempio n. 5
0
 public void TestLocs()
 {
     VM.E.DefineHere(AtomHelper.SymbolFromString("a"), Eval("(1 . 2)"));
     VM.E.DefineHere(AtomHelper.SymbolFromString("a2"), Eval("(1 . 3)"));
     VM.E.DefineHere(AtomHelper.SymbolFromString("a3"), Eval("(1 . 2)"));
     VM.E.DefineHere(AtomHelper.SymbolFromString("b"), Eval("\"test\""));
     VM.E.DefineHere(AtomHelper.SymbolFromString("b2"), Eval("\"testa\""));
     VM.E.DefineHere(AtomHelper.SymbolFromString("b3"), Eval("\"test\""));
     VM.E.DefineHere(AtomHelper.SymbolFromString("c"), Eval("#(1 2)"));
     VM.E.DefineHere(AtomHelper.SymbolFromString("c2"), Eval("#(1 3)"));
     VM.E.DefineHere(AtomHelper.SymbolFromString("c3"), Eval("#(1 2)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? a a)"));
     Assert.AreEqual(AtomHelper.False, Eval("(equal? a a2)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? a a3)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? b b)"));
     Assert.AreEqual(AtomHelper.False, Eval("(equal? b b2)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? b b3)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? c c)"));
     Assert.AreEqual(AtomHelper.False, Eval("(equal? c c2)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? c c3)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? + +)"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? (1 . 2) (1 . 2))"));
     Assert.AreEqual(AtomHelper.True, Eval("(equal? \"test\" \"test\")"));
 }
Esempio n. 6
0
 public override object VisitIdentifier([NotNull] SchemeParser.IdentifierContext context)
 {
     return(AtomHelper.SymbolFromString(context.IDENTIFIER().GetText()));
 }
Esempio n. 7
0
 private static void AddPrimitive(IDictionary <SymbolAtom, ISExpression> d, string name, Func <IEnumerable <ISExpression>, ISExpression> p)
 {
     d[AtomHelper.SymbolFromString(name)] = AtomHelper.CreateProcedure(name, p, true);
 }
Esempio n. 8
0
 private static void AddFunction(IDictionary <SymbolAtom, ISExpression> d, string name, Procedure p)
 {
     d[AtomHelper.SymbolFromString(name)] = p;
 }