Ejemplo n.º 1
0
        public object Eval(string expression)
        {
            var readFromString = _toplevelEnv[Symbol.Intern("read-from-string")];
            var eval           = _toplevelEnv[Symbol.Intern("eval")];

            return(Apply(eval, Apply(readFromString, expression)));
        }
Ejemplo n.º 2
0
        public void DefineFunction(string name, Func <object, object, object, object, object> fun)
        {
            var symName = Symbol.Intern(name);

            ToplevelDefine(symName, fun);
        }
Ejemplo n.º 3
0
 public object Load(string fileName)
 {
     return(Apply(_toplevelEnv[Symbol.Intern("load")], fileName));
 }
Ejemplo n.º 4
0
        static Template ReadTemplate(BinaryReader br)
        {
            var version = br.ReadInt32();

            Debug.Assert(version == 3);
            var numberOfLiterals     = br.ReadInt32();
            var numberOfInstructions = br.ReadInt32();
            var literals             = new object[numberOfLiterals];
            var instructions         = new Instruction[numberOfInstructions];

            for (int x = 0; x < numberOfLiterals; x++)
            {
                byte type = br.ReadByte();
                switch (type)
                {
                // Symbol
                case 1:
                    literals[x] = Symbol.Intern(ReadString(br));
                    break;

                // String
                case 2:
                    literals[x] = ReadString(br);
                    break;

                // Number
                case 3: {
                    var str = ReadString(br);
                    literals[x] = double.Parse(str);
                    break;
                }

                // Boolean
                case 4:
                    literals[x] = br.ReadByte() == 0 ? false : true;
                    break;

                // Null
                case 5:
                    literals[x] = null;
                    break;

                // Char
                case 6:
                    literals[x] = (char)br.ReadUInt16();
                    break;

                // Template
                case 10:
                    literals[x] = ReadTemplate(br);
                    break;
                }
            }

            for (var x = 0; x < numberOfInstructions; x++)
            {
                instructions[x] = new Instruction(br.ReadUInt32());
            }

            var template = new Template(literals, instructions);

            return(template);
        }
Ejemplo n.º 5
0
 public void ToplevelDefine(string name, object value)
 {
     ToplevelDefine(Symbol.Intern(name), value);
 }
Ejemplo n.º 6
0
 public object ToplevelLookup(string name)
 {
     return(ToplevelLookup(Symbol.Intern(name)));
 }
Ejemplo n.º 7
0
 static object StringToSymbol(object str)
 {
     return(Symbol.Intern((string)str));
 }