Exemple #1
0
        private IodineObject GetBytecode(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length == 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            IodineMethod method = args [0] as IodineMethod;

            if (method == null && args [0] is IodineClosure)
            {
                method = ((IodineClosure)args [0]).Target;
            }

            if (method == null && args [0] is IodineBoundMethod)
            {
                method = ((IodineBoundMethod)args [0]).Method;
            }

            IodineList ret = new IodineList(new IodineObject[] { });

            foreach (Instruction ins in method.Bytecode.Instructions)
            {
                ret.Add(new IodineInstruction(method, ins));
            }

            return(ret);
        }
        private IodineObject Zip(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(IodineNull.Instance);
            }

            IodineList result = new IodineList(new IodineObject[0]);

            IodineObject[] iterators = new IodineObject[args.Length];
            for (int i = 0; i < args.Length; i++)
            {
                iterators [i] = args [i].GetIterator(vm);
                iterators [i].IterReset(vm);
            }

            while (true)
            {
                IodineObject[] objs = new IodineObject[iterators.Length];
                for (int i = 0; i < iterators.Length; i++)
                {
                    if (!iterators [i].IterMoveNext(vm))
                    {
                        return(result);
                    }
                    IodineObject o = iterators [i].IterGetCurrent(vm);
                    objs [i] = o;
                }
                result.Add(new IodineTuple(objs));
            }
        }
        static IodineObject Filter(VirtualMachine vm, IodineObject self, IodineObject [] args)
        {
            if (args.Length == 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            var list       = new IodineList(new IodineObject [] { });
            var collection = self.GetIterator(vm);

            IodineObject func = args [0];

            collection.IterReset(vm);

            while (collection.IterMoveNext(vm))
            {
                var o = collection.IterGetCurrent(vm);
                if (func.Invoke(vm, new IodineObject [] { o }).IsTrue())
                {
                    list.Add(o);
                }
            }
            return(list);
        }
Exemple #4
0
        IodineObject List(VirtualMachine vm, IodineObject self, IodineObject [] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            var dir = args [0] as IodineString;

            if (dir == null)
            {
                vm.RaiseException(new IodineTypeException("Str"));
                return(null);
            }

            if (!Directory.Exists(dir.Value))
            {
                vm.RaiseException(new IodineIOException("Directory does not exist"));
                return(null);
            }

            var items = new List <string> ();

            items.AddRange(Directory.GetFiles(dir.Value));
            items.AddRange(Directory.GetDirectories(dir.Value));

            var retList = new IodineList(new IodineObject [] { });

            items.ForEach(p => retList.Add(new IodineString(p)));

            return(retList);
        }
        private IodineObject Enumerate(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length == 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(IodineNull.Instance);
            }

            IodineList   list       = new IodineList(new IodineObject[] { });
            IodineObject collection = args [0].GetIterator(vm);

            collection.IterReset(vm);

            int counter = 0;

            while (collection.IterMoveNext(vm))
            {
                IodineObject o = collection.IterGetCurrent(vm);
                list.Add(new IodineTuple(new IodineObject[] {
                    new IodineInteger(counter++),
                    o
                }));
            }
            return(list);
        }
Exemple #6
0
			private IodineObject listFiles (VirtualMachine vm, IodineObject self, IodineObject[] args)
			{
				if (args.Length <= 0) {
					vm.RaiseException (new IodineArgumentException (1));
					return null;
				}

				if (!(args [0] is IodineString)) {
					vm.RaiseException (new IodineTypeException ("Str"));
					return null;
				}

				if (!Directory.Exists (args [0].ToString ())) {
					vm.RaiseException (new IodineIOException ("Directory '" + args [0].ToString () +
					"' does not exist!"));
					return null;
				}

				IodineList ret = new IodineList (new IodineObject[]{ });

				foreach (string dir in Directory.GetFiles (args[0].ToString ())) {
					ret.Add (new IodineString (dir));
				}
				return ret;
			}
Exemple #7
0
            private IodineObject Clear(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                thisObj.Objects.Clear();
                return(thisObj);
            }
Exemple #8
0
            private IodineObject Split(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                var thisObj = self as IodineString;

                if (thisObj == null)
                {
                    vm.RaiseException(new IodineFunctionInvocationException());
                    return(null);
                }

                if (args.Length < 1)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }

                var  ch = args [0] as IodineString;
                char val;

                if (ch == null)
                {
                    vm.RaiseException(new IodineTypeException("Str"));
                    return(null);
                }
                val = ch.Value [0];

                var list = new IodineList(new IodineObject[] { });

                foreach (string str in thisObj.Value.Split(val))
                {
                    list.Add(new IodineString(str));
                }
                return(list);
            }
Exemple #9
0
            private IodineObject RemoveAt(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                IodineInteger index = arguments [0] as IodineInteger;

                if (index != null)
                {
                    if (index.Value < thisObj.Objects.Count)
                    {
                        thisObj.Objects.RemoveAt((int)index.Value);
                    }
                    else
                    {
                        vm.RaiseException(new IodineKeyNotFound());
                        return(null);
                    }
                    return(thisObj);
                }
                vm.RaiseException(new IodineTypeException("Int"));
                return(null);
            }
Exemple #10
0
        private IodineObject zip(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            IodineList result = new IodineList(new IodineObject[0]);

            foreach (IodineObject obj in args)
            {
                obj.IterReset(vm);
            }
            while (true)
            {
                IodineObject[] objs = new IodineObject[args.Length];
                for (int i = 0; i < args.Length; i++)
                {
                    if (!args [i].IterMoveNext(vm))
                    {
                        return(result);
                    }
                    IodineObject o = args [i].IterGetCurrent(vm);
                    objs [i] = o;
                }
                result.Add(new IodineTuple(objs));
            }
        }
Exemple #11
0
        private IodineObject split(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            IodineString selfStr = self as IodineString;
            IodineString ch      = args [0] as IodineString;
            char         val;

            if (ch == null)
            {
                vm.RaiseException(new IodineTypeException("Str"));
                return(null);
            }
            val = ch.Value [0];

            IodineList list = new IodineList(new IodineObject[] { });

            foreach (string str in selfStr.Value.Split(val))
            {
                list.Add(new IodineString(str));
            }
            return(list);
        }
Exemple #12
0
            private IodineObject listDirectories(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                if (args.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }

                if (!(args [0] is IodineString))
                {
                    vm.RaiseException(new IodineTypeException("Str"));
                    return(null);
                }

                if (!Directory.Exists(args [0].ToString()))
                {
                    vm.RaiseException(new IodineIOException("Directory '" + args [0].ToString() +
                                                            "' does not exist!"));
                    return(null);
                }

                IodineList ret = new IodineList(new IodineObject[] { });

                foreach (string dir in Directory.GetDirectories(args[0].ToString()))
                {
                    ret.Add(new IodineString(dir));
                }
                return(ret);
            }
Exemple #13
0
 private IodineObject getProcList(VirtualMachine vm, IodineObject self, IodineObject[] args)
 {
     IodineList list = new IodineList (new IodineObject[] { });
     foreach (Process proc in Process.GetProcesses ()) {
         list.Add (new IodineProc (proc));
     }
     return list;
 }
 public override IodineObject Invoke(VirtualMachine vm, IodineObject[] args)
 {
     if (args.Length >= 1)
     {
         IodineList inputList = args [0] as IodineList;
         return(new IodineTuple(inputList.Objects.ToArray()));
     }
     return(null);
 }
Exemple #15
0
            IodineObject Splice(VirtualMachine vm, IodineObject self, IodineObject [] arguments)
            {
                var thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }

                int start = 0;
                int end   = thisObj.Objects.Count;

                var startInt = arguments [0] as IodineInteger;

                if (startInt == null)
                {
                    vm.RaiseException(new IodineTypeException("Int"));
                    return(null);
                }
                start = (int)startInt.Value;

                if (arguments.Length >= 2)
                {
                    var endInt = arguments [1] as IodineInteger;
                    if (endInt == null)
                    {
                        vm.RaiseException(new IodineTypeException("Int"));
                        return(null);
                    }
                    end = (int)endInt.Value;
                }

                if (start < 0)
                {
                    start = thisObj.Objects.Count - start;
                }
                if (end < 0)
                {
                    end = thisObj.Objects.Count - end;
                }

                var retList = new IodineList(new IodineObject [] { });

                for (int i = start; i < end; i++)
                {
                    if (i < 0 || i > thisObj.Objects.Count)
                    {
                        vm.RaiseException(new IodineIndexException());
                        return(null);
                    }
                    retList.Add(thisObj.Objects [i]);
                }

                return(retList);
            }
Exemple #16
0
 private IodineObject getInterfaces(VirtualMachine vm, IodineObject self, IodineObject[] args)
 {
     if (args.Length < 1) {
         vm.RaiseException (new IodineArgumentException (1));
         return null;
     }
     IodineObject o1 = args [0];
     IodineList list = new IodineList (o1.Interfaces.ToArray ());
     return list;
 }
Exemple #17
0
        private IodineObject getProcList(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            IodineList list = new IodineList(new IodineObject[] { });

            foreach (Process proc in Process.GetProcesses())
            {
                list.Add(new IodineProc(proc));
            }
            return(list);
        }
Exemple #18
0
        public override IodineObject Equals(VirtualMachine vm, IodineObject right)
        {
            IodineList listVal = right as IodineList;

            if (listVal == null)
            {
                vm.RaiseException(new IodineTypeException("List"));
                return(null);
            }
            return(IodineBool.Create(compare(this, listVal)));
        }
Exemple #19
0
            private IodineObject Prepend(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                thisObj.Objects.Insert(0, arguments [0]);
                return(thisObj);
            }
Exemple #20
0
        private IodineObject getInterfaces(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }
            IodineObject o1   = args [0];
            IodineList   list = new IodineList(o1.Interfaces.ToArray());

            return(list);
        }
Exemple #21
0
        public override IodineObject Add(VirtualMachine vm, IodineObject right)
        {
            var list = new IodineList(Objects.ToArray());

            right.IterReset(vm);
            while (right.IterMoveNext(vm))
            {
                var o = right.IterGetCurrent(vm);
                list.Add(o);
            }
            return(list);
        }
		private IodineList convertDataTable(DataTable table)
		{
			var resList = new IodineList (new IodineObject[]{});

			foreach (DataRow row in table.Rows) {
				var items = new IodineHashMap ();
				foreach (DataColumn col in table.Columns) {
					items.Set (new IodineString(col.ColumnName), new IodineString((row [col.ColumnName]).ToString()));
				}
				resList.Add (items);
			}
			return resList;
		}
Exemple #23
0
			public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
			{
				IodineList list = new IodineList (new IodineObject[0]);
				if (args.Length > 0) {
					foreach (IodineObject collection in args) {
						collection.IterReset (vm);
						while (collection.IterMoveNext (vm)) {
							IodineObject o = collection.IterGetCurrent (vm);
							list.Add (o);
						}
					}
				}
				return list;
			}
Exemple #24
0
 private bool compare(IodineList list1, IodineList list2)
 {
     if (list1.Objects.Count != list2.Objects.Count)
     {
         return(false);
     }
     for (int i = 0; i < list1.Objects.Count; i++)
     {
         if (list1.Objects [i].GetHashCode() != list2.Objects [i].GetHashCode())
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #25
0
        private IodineObject add(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
        {
            if (arguments.Length <= 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }
            IodineList list = self as IodineList;

            foreach (IodineObject obj in arguments)
            {
                list.Add(obj);
            }
            return(null);
        }
Exemple #26
0
            private IodineObject Add(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                foreach (IodineObject obj in arguments)
                {
                    thisObj.Add(obj);
                }
                return(thisObj);
            }
Exemple #27
0
        private IodineObject getBytecode(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            IodineMethod method = args [0] as IodineMethod;

            if (method == null && args [0] is IodineClosure) {
                method = ((IodineClosure)args [0]).Target;
            }

            IodineList ret = new IodineList (new IodineObject[] { });

            foreach (Instruction ins in method.Body) {
                ret.Add (new IodineInstruction (method, ins));
            }

            return ret;
        }
Exemple #28
0
        IodineObject GetProcList(VirtualMachine vm)
        {
            var list = new IodineList(new IodineObject [] { });

            foreach (Process proc in Process.GetProcesses())
            {
                try {
                    list.Add(new IodineProc(proc));
                } catch {
                    // Why are we doing this? Well on some platforms this loop
                    // is very slow and some processes could have exited, causing
                    // an exception to be thrown.
                    continue;
                }
            }
            return(list);
        }
Exemple #29
0
        private IodineObject getBytecode(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            IodineMethod method = args [0] as IodineMethod;

            if (method == null && args [0] is IodineClosure)
            {
                method = ((IodineClosure)args [0]).Target;
            }

            IodineList ret = new IodineList(new IodineObject[] { });

            foreach (Instruction ins in method.Body)
            {
                ret.Add(new IodineInstruction(method, ins));
            }
            return(ret);
        }
Exemple #30
0
        public override bool Equals(IodineObject obj)
        {
            IodineList listVal = obj as IodineList;

            if (listVal != null && listVal.Objects.Count == Objects.Count)
            {
                for (int i = 0; i < Objects.Count; i++)
                {
                    if (!Objects [i].Equals(listVal.Objects [i]))
                    {
                        return(false);
                    }
                }
                return(true);
            }
            return(false);
        }
Exemple #31
0
            private IodineObject RightFind(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineList thisObj = self as IodineList;

                if (args.Length == 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }

                IodineObject item = args [0];

                if (!thisObj.Objects.Any(o => o.Equals(item)))
                {
                    return(new IodineInteger(-1));
                }
                return(new IodineInteger(thisObj.Objects.FindLastIndex(o => o.Equals(item))));
            }
Exemple #32
0
            public override IodineObject Invoke(VirtualMachine vm, IodineObject[] args)
            {
                IodineList list = new IodineList(new IodineObject[0]);

                if (args.Length > 0)
                {
                    foreach (IodineObject collection in args)
                    {
                        collection.IterReset(vm);
                        while (collection.IterMoveNext(vm))
                        {
                            IodineObject o = collection.IterGetCurrent(vm);
                            list.Add(o);
                        }
                    }
                }
                return(list);
            }
Exemple #33
0
            private IodineObject AddRange(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                IodineObject collection = arguments [0].GetIterator(vm);

                collection.IterReset(vm);
                while (collection.IterMoveNext(vm))
                {
                    IodineObject o = collection.IterGetCurrent(vm);
                    thisObj.Add(o);
                }
                return(thisObj);
            }
Exemple #34
0
            private IodineObject Remove(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                IodineObject key = arguments [0];

                if (thisObj.Objects.Any(o => o.Equals(key)))
                {
                    thisObj.Objects.Remove(thisObj.Objects.First(o => o.Equals(key)));
                    return(thisObj);
                }
                vm.RaiseException(new IodineKeyNotFound());
                return(null);
            }
Exemple #35
0
            private IodineObject Contains(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
            {
                IodineList thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                IodineObject key   = arguments [0];
                bool         found = false;

                foreach (IodineObject obj in thisObj.Objects)
                {
                    found |= obj.Equals(key);
                }

                return(IodineBool.Create(found));
            }
Exemple #36
0
        private IodineObject map(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length <= 1)
            {
                vm.RaiseException(new IodineArgumentException(2));
                return(null);
            }

            IodineList   list       = new IodineList(new IodineObject[] { });
            IodineObject collection = args [0];
            IodineObject func       = args [1];

            collection.IterReset(vm);
            while (collection.IterMoveNext(vm))
            {
                IodineObject o = collection.IterGetCurrent(vm);
                list.Add(func.Invoke(vm, new IodineObject[] { o }));
            }
            return(list);
        }
Exemple #37
0
 public override IodineObject Add(VirtualMachine vm, IodineObject right)
 {
     IodineList list = new IodineList (Objects.ToArray ());
     right.IterReset (vm);
     while (right.IterMoveNext (vm)) {
         IodineObject o = right.IterGetCurrent (vm);
         list.Add (o);
     }
     return list;
 }
        private IodineObject map(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length <= 1) {
                vm.RaiseException (new IodineArgumentException (2));
                return null;
            }

            IodineList list = new IodineList (new IodineObject[]{ });
            IodineObject collection = args [0];
            IodineObject func = args [1];

            collection.IterReset (vm);
            while (collection.IterMoveNext (vm)) {
                IodineObject o = collection.IterGetCurrent (vm);
                list.Add (func.Invoke (vm, new IodineObject[] { o }));
            }
            return list;
        }
        private IodineObject zip(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1) {
                vm.RaiseException (new IodineArgumentException (1));
                return null;
            }

            IodineList result = new IodineList (new IodineObject[0]);
            foreach (IodineObject obj in args)
                obj.IterReset (vm);
            while (true) {
                IodineObject[] objs = new IodineObject[args.Length];
                for (int i = 0; i < args.Length; i++) {
                    if (!args [i].IterMoveNext (vm))
                        return result;
                    IodineObject o = args [i].IterGetCurrent (vm);
                    objs [i] = o;
                }
                result.Add (new IodineTuple (objs));
            }
        }
Exemple #40
0
		private IodineObject split (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			if (args.Length < 1) {
				vm.RaiseException (new IodineArgumentException (1));
				return null;
			}

			IodineString selfStr = self as IodineString;
			IodineString ch = args [0] as IodineString;
			char val;
			if (ch == null) {
				vm.RaiseException (new IodineTypeException ("Str"));
				return null;

			}
			val = ch.Value [0];

			IodineList list = new IodineList (new IodineObject[]{ });
			foreach (string str in selfStr.Value.Split (val)) {
				list.Add (new IodineString (str));
			}
			return list;
		}
Exemple #41
0
 private bool compare(IodineList list1, IodineList list2)
 {
     if (list1.Objects.Count != list2.Objects.Count)
         return false;
     for (int i = 0; i < list1.Objects.Count; i++) {
         if (list1.Objects [i].GetHashCode () != list2.Objects [i].GetHashCode ())
             return false;
     }
     return true;
 }
Exemple #42
0
        private IodineObject splice(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
        {
            if (arguments.Length <= 0) {
                vm.RaiseException (new IodineArgumentException (1));
                return null;
            }

            int start = 0;
            int end = Objects.Count;

            IodineInteger startInt = arguments [0] as IodineInteger;
            if (startInt == null) {
                vm.RaiseException (new IodineTypeException ("Int"));
                return null;
            }
            start = (int)startInt.Value;

            if (arguments.Length >= 2) {
                IodineInteger endInt = arguments [1] as IodineInteger;
                if (endInt == null) {
                    vm.RaiseException (new IodineTypeException ("Int"));
                    return null;
                }
                end = (int)endInt.Value;
            }

            if (start < 0)
                start = this.Objects.Count - start;
            if (end < 0)
                end = this.Objects.Count - end;

            IodineList retList = new IodineList (new IodineObject[]{ });

            for (int i = start; i < end; i++) {
                if (i < 0 || i > this.Objects.Count) {
                    vm.RaiseException (new IodineIndexException ());
                    return null;
                }
                retList.Add (Objects [i]);
            }

            return retList;
        }