Exemple #1
0
        public static Atom GetElement(Atom args, Context context)
        {
            Atom arg0 = (Atom)args?.value;
            Atom arg1 = (Atom)args?.next?.value;

            if (arg0.type != AtomType.Number ||
                UNumber.NumberType(arg0.value) > UNumber.SINT)
            {
                throw new ArgumentException("First argument must be integer number!");
            }

            if (arg1.type != AtomType.Pair)
            {
                throw new ArgumentException("Second argument must be list!");
            }

            Atom res = arg1.ListSkip((int)arg0.value);

            if (res == null)
            {
                throw new ArgumentException(string.Format("List too short for argument {0}!", arg0.value));
            }

            return(res);
        }
Exemple #2
0
        public static Atom PredDouble(Atom args, Context context)
        {
            Atom atom = (Atom)args?.value;

            if (atom.type == AtomType.Number &&
                UNumber.NumberType(atom.value) == UNumber.DOUBLE)
            {
                return(Atom.TRUE);
            }
            return(Atom.FALSE);
        }
Exemple #3
0
        public static Atom PredSShort(Atom args, Context context)
        {
            Atom atom = (Atom)args?.value;

            if (atom.type == AtomType.Number &&
                UNumber.NumberType(atom.value) == UNumber.SSHORT)
            {
                return(Atom.TRUE);
            }
            return(Atom.FALSE);
        }
Exemple #4
0
        private static Atom Write(Atom args, Context context)
        {
            Atom stream = args?.atom;

            if (stream.type != AtomType.Native)
            {
                throw new ArgumentException("Argument must be stream!");
            }

            StreamWriter writer = stream?.value as StreamWriter;

            if (writer == null)
            {
                throw new ArgumentException("Argument must be stream!");
            }

            Atom value = args?.next?.atom;

            if (value == null)
            {
                throw new ArgumentException("Second argument can't be null!");
            }

            switch (value.type)
            {
            case AtomType.Number:
                var type = UNumber.NumberType(value?.value);
                switch (type)
                {
                case UNumber.UINT_8: writer.Write(Convert.ToByte(value.value)); break;

                case UNumber.SINT_8: writer.Write(Convert.ToSByte(value.value)); break;

                case UNumber.UINT16: writer.Write(Convert.ToUInt16(value.value)); break;

                case UNumber.SINT16: writer.Write(Convert.ToInt16(value.value)); break;

                case UNumber._CHAR_: writer.Write(Convert.ToChar(value.value)); break;

                case UNumber.UINT32: writer.Write(Convert.ToUInt32(value.value)); break;

                case UNumber.SINT32: writer.Write(Convert.ToInt32(value.value)); break;

                case UNumber.UINT64: writer.Write(Convert.ToUInt64(value.value)); break;

                case UNumber.SINT64: writer.Write(Convert.ToInt64(value.value)); break;

                case UNumber.FLO32: writer.Write(Convert.ToSingle(value.value)); break;

                case UNumber.FLO64: writer.Write(Convert.ToDouble(value.value)); break;

                default:
                    writer.Write(value?.value);
                    break;
                }
                break;

            default:
                writer.Write(value?.value);
                break;
            }

            return(null);
        }