Beispiel #1
0
        public static object ReadVectorHandler2(LispReader stream, string ch, int arg)
        {
            if (stream.ReadChar() != '(')
            {
                throw stream.MakeScannerException("Invalid #() expression");
            }
            var list = stream.ReadDelimitedList(")");
            var obj  = new Vector();

            obj.AddRange(list);
            if (arg == -1)
            {
                // default no action
            }
            else if (arg < obj.Count)
            {
                throw new LispException("Vector {0} contains more than {1} items", ToPrintString(obj), arg);
            }
            else if (arg > obj.Count)
            {
                var filler = obj.Count == 0 ? (object)null : obj[obj.Count - 1];
                while (obj.Count < arg)
                {
                    obj.Add(filler);
                }
            }
            return(obj);
        }
Beispiel #2
0
        public static object ReadIfExprHandler(LispReader stream, string ch, int arg)
        {
            Vector branch = null;
            var    term   = ReadBranch(stream, true, BranchMode.Eval, ref branch);

            while (term == Symbols.HashElif)
            {
                var haveBranch = branch != null;
                term = ReadBranch(stream, true, haveBranch ? BranchMode.False : BranchMode.Eval, ref branch);
            }
            if (term == Symbols.HashElse)
            {
                var haveBranch = branch != null;
                term = ReadBranch(stream, false, haveBranch ? BranchMode.False : BranchMode.True, ref branch);
            }
            if (term != Symbols.HashEndif)
            {
                throw stream.MakeScannerException("EOF: Missing #endif");
            }

            if (branch != null && branch.Count > 0)
            {
                return(MakeListStar(Symbols.CompileTimeBranch, branch));
            }
            else
            {
                return(VOID.Value);
            }
        }
Beispiel #3
0
        public static object ReadStructHandler(LispReader stream, string ch, int arg)
        {
            if (stream.ReadChar() != '(')
            {
                throw stream.MakeScannerException("Invalid #s() expression");
            }
            var list = stream.ReadDelimitedList(")");
            var obj  = new Prototype(AsArray(list));

            return(obj);
        }
Beispiel #4
0
        public static object ReadComplexNumberHandler(LispReader stream, string ch, int arg)
        {
            if (stream.ReadChar() != '(')
            {
                throw stream.MakeScannerException("Invalid #c expression");
            }
            var    nums  = stream.ReadDelimitedList(")");
            int    count = Length(nums);
            double real  = count >= 1 ? AsDouble(nums.Car) : 0;
            double imag  = count >= 2 ? AsDouble(nums.Cdr.Car) : 0;

            return(new Complex(real, imag));
        }
Beispiel #5
0
        public static object ReadExecuteHandler(LispReader stream, string ch, int arg)
        {
            var expr     = stream.Read();
            var readEval = GetDynamic(Symbols.ReadEval);

            if (readEval == null)
            {
                readEval = false; //stream.loading;
            }
            if (!ToBool(readEval))
            {
                throw stream.MakeScannerException("Invalid use of '#.' (prohibited by $read-eval variable)");
            }
            var value = Eval(expr);

            return(value);
        }
Beispiel #6
0
 public static object ReadUninternedSymbolHandler(LispReader stream, string ch, int arg)
 {
     throw stream.MakeScannerException("Uninterned symbols are not supported.");
 }
 public static object ReadVectorHandler2(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #() expression");
     }
     var list = stream.ReadDelimitedList(")");
     var obj = new Vector();
     obj.AddRange(list);
     if (arg == -1)
     {
         // default no action
     }
     else if (arg < obj.Count)
     {
         throw new LispException("Vector {0} contains more than {1} items", ToPrintString(obj), arg);
     }
     else if (arg > obj.Count)
     {
         var filler = obj.Count == 0 ? (object)null : obj[obj.Count - 1];
         while (obj.Count < arg)
         {
             obj.Add(filler);
         }
     }
     return obj;
 }
 public static object ReadUninternedSymbolHandler(LispReader stream, string ch, int arg)
 {
     throw stream.MakeScannerException("Uninterned symbols are not supported.");
 }
 public static object ReadStructHandler(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #s() expression");
     }
     var list = stream.ReadDelimitedList(")");
     var obj = new Prototype(AsArray(list));
     return obj;
 }
        public static object ReadIfExprHandler(LispReader stream, string ch, int arg)
        {
            Vector branch = null;
            var term = ReadBranch(stream, true, BranchMode.Eval, ref branch);
            while (term == Symbols.HashElif)
            {
                var haveBranch = branch != null;
                term = ReadBranch(stream, true, haveBranch ? BranchMode.False : BranchMode.Eval, ref branch);
            }
            if (term == Symbols.HashElse)
            {
                var haveBranch = branch != null;
                term = ReadBranch(stream, false, haveBranch ? BranchMode.False : BranchMode.True, ref branch);
            }
            if (term != Symbols.HashEndif)
            {
                throw stream.MakeScannerException("EOF: Missing #endif");
            }

            if (branch != null && branch.Count > 0)
            {
                return MakeListStar(Symbols.CompileTimeBranch, branch);
            }
            else
            {
                return VOID.Value;
            }
        }
 public static object ReadExecuteHandler(LispReader stream, string ch, int arg)
 {
     var expr = stream.Read();
     var readEval = GetDynamic(Symbols.ReadEval);
     if (readEval == null)
     {
         readEval = false; //stream.loading;
     }
     if (!ToBool(readEval))
     {
         throw stream.MakeScannerException("Invalid use of '#.' (prohibited by $read-eval variable)");
     }
     var value = Eval(expr);
     return value;
 }
 public static object ReadComplexNumberHandler(LispReader stream, string ch, int arg)
 {
     if (stream.ReadChar() != '(')
     {
         throw stream.MakeScannerException("Invalid #c expression");
     }
     var nums = stream.ReadDelimitedList(")");
     int count = Length(nums);
     double real = count >= 1 ? AsDouble(nums.Car) : 0;
     double imag = count >= 2 ? AsDouble(nums.Cdr.Car) : 0;
     return new Complex(real, imag);
 }