コード例 #1
0
ファイル: ListContext.cs プロジェクト: Sadalmalik/bombardo
        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);
        }
コード例 #2
0
ファイル: BombardoUtils.cs プロジェクト: Sadalmalik/bombardo
        public static Atom ToAtom <T>(T t)
        {
            Type type = typeof(T);

            if (type == typeof(bool))
            {
                return(new Atom(AtomType.Bool, t));
            }
            if (type == typeof(string))
            {
                return(new Atom(AtomType.String, t));
            }
            if (UNumber.IsNumber(t))
            {
                return(new Atom(AtomType.Number, t));
            }
            if (type == typeof(Atom))
            {
                return(t as Atom);
            }
            if (type == typeof(List <Atom>))
            {
                return(ListToAtom(t as List <Atom>));
            }
            return(new Atom(AtomType.Native, t));
        }
コード例 #3
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);
        }
コード例 #4
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);
        }
コード例 #5
0
        public static Atom Rsh(Atom args, Context context)
        {
            CheckAllNumbers(args);
            object res = ((Atom)args?.value).value;

            for (Atom iter = args.next; iter != null; iter = iter.next)
            {
                res = UNumber.Rsh(res, ((Atom)iter.value).value);
            }
            return(new Atom(AtomType.Number, res));
        }
コード例 #6
0
        public static Atom Tanh(Atom args, Context context)
        {
            Atom atom = (Atom)args?.value;

            if (atom.type != AtomType.Number)
            {
                throw new ArgumentException("Argument must be number!");
            }

            return(new Atom(AtomType.Number, UNumber.Tanh(atom.value)));
        }
コード例 #7
0
 public static Atom Eq(Atom args, Context context)
 {
     CheckAllNumbers(args);
     for (Atom iter = args; iter != null && iter.next != null; iter = iter.next)
     {
         if (!(bool)UNumber.Eq(
                 ((Atom)iter.value).value,
                 ((Atom)iter.next?.value).value))
         {
             return(Atom.FALSE);
         }
     }
     return(Atom.TRUE);
 }
コード例 #8
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);
        }