Ejemplo n.º 1
0
		private IodineObject unzip (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			var archiveName = args [0] as IodineString;
			var targetDir = args [1] as IodineString;
			ZipFile.ExtractToDirectory (archiveName.Value, targetDir.Value);
			return null;
		}
Ejemplo n.º 2
0
			public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
			{
				if (args.Length <= 0) {
					vm.RaiseException (new IodineArgumentException (1));
				}

				if (args [0] is IodineFloat) {
					IodineFloat fp = args [0] as IodineFloat;
					return new IodineInteger ((long)fp.Value);
				}

				long value;
				NumberStyles style = NumberStyles.AllowLeadingSign;

				if (args.Length > 1) {
					IodineInteger basen = args [1] as IodineInteger;
					switch (basen.Value) {
					case 16:
						style = NumberStyles.HexNumber;
						break;
					}
				}

				if (!Int64.TryParse (args [0].ToString (), style, null, out value)) {
					vm.RaiseException (new IodineTypeCastException ("Int"));
					return null;
				} else {
					return new IodineInteger (value);
				}
			}
Ejemplo n.º 3
0
		private IodineObject sha1 (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			if (args.Length <= 0) {
				vm.RaiseException (new IodineArgumentException (1));
				return null;
			}

			byte[] bytes = new byte[]{};
			byte[] hash = null;

			SHA1Managed hashstring = new SHA1Managed();

			if (args[0] is IodineString) {
				bytes = System.Text.Encoding.UTF8.GetBytes (args[0].ToString ());
				hash = hashstring.ComputeHash(bytes);
			} else if (args[0] is IodineByteArray) {
				bytes = ((IodineByteArray)args[0]).Array;
				hash = hashstring.ComputeHash(bytes);
			} else if (args[0] is IodineStream) {
				hash = hashstring.ComputeHash(((IodineStream)args[0]).File);
			} else {
				vm.RaiseException (new IodineTypeException ("Str"));
				return null;
			}

			return new IodineByteArray (hash);
		}
Ejemplo n.º 4
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;
			}
Ejemplo n.º 5
0
			private IodineObject push (VirtualMachine vm, IodineObject self, IodineObject[] args)
			{
				foreach (IodineObject obj in args) {
					Stack.Push (obj);
				}
				return null;
			}
Ejemplo n.º 6
0
 public IodineProperty(IodineObject getter, IodineObject setter, IodineObject self)
     : base(TypeDefinition)
 {
     Setter = setter;
     Getter = getter;
     this.self = self;
 }
Ejemplo n.º 7
0
			public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
			{
				if (args.Length <= 0) {
					vm.RaiseException (new IodineArgumentException (1));
				}
				return new IodineBytes (args [0].ToString ());
			}
Ejemplo n.º 8
0
			public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
			{
				if (args.Length <= 0) {
					vm.RaiseException (new IodineArgumentException (1));
				}
				return IodineBool.Create (Boolean.Parse (args [0].ToString ()));
			}
Ejemplo n.º 9
0
		private IodineObject write (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			if (Closed) { 
				vm.RaiseException (new IodineIOException ("Stream has been closed!"));
				return null;
			}

			if (!CanWrite) {
				vm.RaiseException (new IodineIOException ("Can not write to stream!"));
				return null;
			}

			foreach (IodineObject obj in args) {
				if (obj is IodineString) {
					write (obj.ToString ());
				} else if (obj is IodineBytes) {
					IodineBytes arr = obj as IodineBytes;
					File.Write (arr.Value, 0, arr.Value.Length);
				} else if (obj is IodineInteger) {
					IodineInteger intVal = obj as IodineInteger;
					write ((byte)intVal.Value);
				} else if (obj is IodineByteArray) {
					IodineByteArray arr = obj as IodineByteArray;
					File.Write (arr.Array, 0, arr.Array.Length);
				} else {
					vm.RaiseException (new IodineTypeException (""));
				}
			}
			return null;
		}
Ejemplo n.º 10
0
		private IodineObject randInt (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			if (args.Length <= 0) {
				return new IodineInteger (rgn.Next (Int32.MinValue, Int32.MaxValue));
			} else {
				int start = 0;
				int end = 0;
				if (args.Length <= 1) {
					IodineInteger integer = args [0] as IodineInteger;
					if (integer == null) {
						vm.RaiseException (new IodineTypeException ("Int"));
						return null;
					}
					end = (int)integer.Value;
				} else {
					IodineInteger startInteger = args [0] as IodineInteger;
					IodineInteger endInteger = args [1] as IodineInteger;
					if (startInteger == null || endInteger == null) {
						vm.RaiseException (new IodineTypeException ("Int"));
						return null;
					}
					start = (int)startInteger.Value;
					end = (int)endInteger.Value;
				}
				return new IodineInteger (rgn.Next (start, end));
			}
		}
Ejemplo n.º 11
0
		private IodineObject pow (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			if (args.Length <= 1) {
				vm.RaiseException (new IodineArgumentException (2));
				return null;
			}

			double a1 = 0;
			double a2 = 0;
			if (args [0] is IodineInteger) {
				a1 = (double)((IodineInteger)args [0]).Value;
			} else if (args [0] is IodineFloat) {
				a1 = ((IodineFloat)args [0]).Value;
			} else {
				vm.RaiseException (new IodineTypeException ("Float"));
				return null;
			}

			if (args [1] is IodineInteger) {
				a2 = (double)((IodineInteger)args [1]).Value;
			} else if (args [1] is IodineFloat) {
				a2 = ((IodineFloat)args [1]).Value;
			} else {
				vm.RaiseException (new IodineTypeException ("Float"));
				return null;
			}
			return new IodineFloat (Math.Pow (a1, a2));
		}
Ejemplo n.º 12
0
		private IodineObject append (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			foreach (IodineObject obj in args) {
				buffer.Append (obj.ToString (vm));
			}
			return null;
		}
Ejemplo n.º 13
0
		public override void SetAttribute (VirtualMachine vm, string name, IodineObject value)
		{
			if (!initializerInvoked) {
				initializerInvoked = true;
				Initializer.Invoke (vm, new IodineObject[] { });
			}
			base.SetAttribute (vm, name, value);
		}
Ejemplo n.º 14
0
			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;
			}
Ejemplo n.º 15
0
        public IodineGenerator(StackFrame parentFrame, IodineInstanceMethodWrapper baseMethod,
			IodineObject[] args)
            : base(TypeDef)
        {
            arguments = args;
            self = baseMethod.Self;
            this.baseMethod = baseMethod.Method;
        }
Ejemplo n.º 16
0
 public IodineObject BindAttributes(IodineObject obj)
 {
     foreach (KeyValuePair<string, IodineObject> kv in attributes) {
         if (!obj.HasAttribute (kv.Key))
             obj.SetAttribute (kv.Key, kv.Value);
     }
     return obj;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 18
0
		public override IodineObject GetIndex (VirtualMachine vm, IodineObject key)
		{
			IodineInteger index = key as IodineInteger;
			if (index.Value < Objects.Length)
				return Objects [(int)index.Value];
			vm.RaiseException (new IodineIndexException ());
			return null;
		}
Ejemplo n.º 19
0
 public override bool IterMoveNext(VirtualMachine vm)
 {
     if (stackFrame.AbortExecution) {
         return false;
     }
     value = vm.InvokeMethod (baseMethod, stackFrame, self, arguments);
     return stackFrame.Yielded;
 }
Ejemplo n.º 20
0
			private IodineObject getValue (VirtualMachine vm, IodineObject self, IodineObject[] args)
			{
				string name = args [0].ToString ();
				IodineObject ioval = null;
				object val = Key.GetValue (name);
				//IodineTypeConverter.Instance.ConvertFromPrimative (val, out ioval);
				return ioval;
			}
Ejemplo n.º 21
0
		public IodineObject executeSql(VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			var db = (IodineMySQLConnection)self;
			var statement = (IodineString)args [0];
			MySqlCommand cmd = new MySqlCommand (statement.Value, db.Connection);
			cmd.ExecuteNonQuery ();
			cmd.Dispose ();
			return null;
		}
Ejemplo n.º 22
0
		public StackFrame (IodineMethod method, StackFrame parent, IodineObject self, int localCount)
		{
			LocalCount = localCount;
			locals = new IodineObject[localCount];
			parentLocals = locals;
			Method = method;
			Self = self;
			Parent = parent;
		}
Ejemplo n.º 23
0
		public StackFrame (IodineMethod method, StackFrame parent, IodineObject self, int localCount,
		                   IodineObject[] locals) : this (method, parent, self, localCount)
		{
			parentLocals = locals;
			this.locals = new IodineObject[localCount];
			for (int i = 0; i < localCount; i++) {
				this.locals [i] = locals [i]; 
			}
		}
Ejemplo n.º 24
0
 private IodineObject sleep(VirtualMachine vm, IodineObject self, IodineObject[] args)
 {
     if (args.Length <= 0) {
         vm.RaiseException (new IodineArgumentException (1));
     }
     IodineInteger time = args [0] as IodineInteger;
     System.Threading.Thread.Sleep ((int)time.Value);
     return null;
 }
Ejemplo n.º 25
0
 public override IodineObject Equals(VirtualMachine vm, IodineObject right)
 {
     IodineBool boolVal = right as IodineBool;
     if (boolVal == null) {
         vm.RaiseException ("Right hand side expected to be Bool!");
         return null;
     }
     return IodineBool.Create (boolVal.Value == Value);
 }
Ejemplo n.º 26
0
 private static IEnumerator internalChain(VirtualMachine vm, IodineObject[] args)
 {
     foreach (IodineObject obj in args) {
         obj.IterReset (vm);
         while (obj.IterMoveNext (vm)) {
             yield return obj.IterGetCurrent (vm);
         }
     }
 }
Ejemplo n.º 27
0
 public bool TryToConvertFromPrimative(object obj, out IodineObject result)
 {
     if (obj is IConvertible) {
         result = new IodineInteger (Convert.ToInt64 (obj));
         return true;
     }
     result = null;
     return false;
 }
Ejemplo n.º 28
0
		private MySqlCommand prepareCmd(ref MySqlCommand cmd, IodineObject[] args)
		{
			cmd.Prepare ();
			for (int i = 1; i < args.Length; i++) {
				IodineMySQLParameter arg = (IodineMySQLParameter)args [i];
				cmd.Parameters.Add (new MySqlParameter(arg.ParameterName, arg.Value.ToString()));
			}
			return cmd;
		}
Ejemplo n.º 29
0
 public override IodineObject ConvertFrom(TypeRegistry registry, object obj)
 {
     object[] arr = (object[])obj;
     IodineObject[] iodineObjects = new IodineObject[arr.Length];
     for (int i = 0; i < arr.Length; i++) {
         iodineObjects [i] = registry.ConvertToIodineObject (arr [i]);
     }
     return new IodineList (iodineObjects);
 }
Ejemplo n.º 30
0
			private IodineObject setValue (VirtualMachine vm, IodineObject self, IodineObject[] args)
			{
				string name = args [0].ToString ();
				IodineObject ioval = args [1];
				object val = null;
				//IodineTypeConverter.Instance.ConvertToPrimative (ioval, out val);
				Key.SetValue (name, val);
				return null;
			}
Ejemplo n.º 31
0
 public StackFrame(
     VirtualMachine vm,
     IodineModule module,
     IodineMethod method,
     IodineObject [] arguments,
     StackFrame parent,
     IodineObject self,
     AttributeDictionary locals) : this(vm, module, method, arguments, parent, self)
 {
     this.locals = locals;
 }
Ejemplo n.º 32
0
        public override IodineObject Mul(VirtualMachine vm, IodineObject right)
        {
            long longVal;

            if (!MarshalUtil.MarshalAsInt64(right, out longVal))
            {
                vm.RaiseException(new IodineTypeException("Right hand side must be of type Int!"));
            }

            return(new IodineInteger(Value * longVal));
        }
Ejemplo n.º 33
0
        public override bool Equals(IodineObject obj)
        {
            IodineInteger intVal = obj as IodineInteger;

            if (intVal != null)
            {
                return(intVal.Value == Value);
            }

            return(false);
        }
Ejemplo n.º 34
0
        public override IodineObject ClosedRange(VirtualMachine vm, IodineObject right)
        {
            IodineInteger intVal = right as IodineInteger;

            if (intVal == null)
            {
                vm.RaiseException(new IodineTypeException("Right hand side must be of type Int!"));
                return(null);
            }
            return(new IodineRange(Value, intVal.Value + 1, 1));
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Multiplication operator (*)
 /// </summary>
 public virtual IodineObject Mul(VirtualMachine vm, IodineObject right)
 {
     if (Attributes.ContainsKey("__mul__"))
     {
         return(GetAttribute(vm, "__mul__").Invoke(vm, new IodineObject[] { right }));
     }
     vm.RaiseException(new IodineNotSupportedException(
                           "The requested binary operator has not been implemented")
                       );
     return(null);
 }
Ejemplo n.º 36
0
 public override IodineObject BindAttributes(IodineObject obj)
 {
     obj.SetAttribute("write", new BuiltinMethodCallback(Write, obj));
     obj.SetAttribute("writeln", new BuiltinMethodCallback(Writeln, obj));
     obj.SetAttribute("read", new BuiltinMethodCallback(Read, obj));
     obj.SetAttribute("readln", new BuiltinMethodCallback(Readln, obj));
     obj.SetAttribute("kill", new BuiltinMethodCallback(Kill, obj));
     obj.SetAttribute("empty", new BuiltinMethodCallback(Empty, obj));
     obj.SetAttribute("alive", new BuiltinMethodCallback(Alive, obj));
     return(base.BindAttributes(obj));
 }
Ejemplo n.º 37
0
        public override IodineObject RightShift(VirtualMachine vm, IodineObject right)
        {
            IodineInteger intVal = right as IodineInteger;

            if (intVal == null)
            {
                vm.RaiseException(new IodineTypeException("Right hand side must be of type Int!"));
                return(null);
            }
            return(new IodineInteger(Value >> (int)intVal.Value));
        }
 public virtual IodineObject BindAttributes(IodineObject obj)
 {
     foreach (KeyValuePair <string, IodineObject> kv in Attributes)
     {
         if (!obj.HasAttribute(kv.Key))
         {
             obj.SetAttribute(kv.Key, kv.Value);
         }
     }
     return(obj);
 }
Ejemplo n.º 39
0
        public override bool Equals(IodineObject obj)
        {
            BigInteger intVal;

            if (ConvertToBigInt(obj, out intVal))
            {
                return(intVal == Value);
            }

            return(false);
        }
Ejemplo n.º 40
0
        public override IodineObject RightShift(VirtualMachine vm, IodineObject right)
        {
            BigInteger intVal;

            if (!ConvertToBigInt(right, out intVal))
            {
                vm.RaiseException(new IodineTypeException("Right hand side must be of type Int!"));
                return(null);
            }
            return(new IodineBigInt(Value / BigInteger.Pow(2, (int)(uint)intVal)));
        }
Ejemplo n.º 41
0
        public override IodineObject GetIndex(VirtualMachine vm, IodineObject key)
        {
            var index = key as IodineInteger;

            if (index.Value < Objects.Length)
            {
                return(Objects [(int)index.Value]);
            }
            vm.RaiseException(new IodineIndexException());
            return(null);
        }
Ejemplo n.º 42
0
        public override IodineObject LessThanOrEqual(VirtualMachine vm, IodineObject right)
        {
            BigInteger intVal;

            if (!ConvertToBigInt(right, out intVal))
            {
                vm.RaiseException(new IodineTypeException("Right hand side must be of type Int!"));
                return(null);
            }
            return(IodineBool.Create(Value <= intVal));
        }
Ejemplo n.º 43
0
            public override IodineObject GreaterThanOrEqual(VirtualMachine vm, IodineObject right)
            {
                IodineTimeStamp op = right as IodineTimeStamp;

                if (op == null)
                {
                    vm.RaiseException(new IodineTypeException(
                                          "Right hand value expected to be of type TimeStamp"));
                    return(null);
                }
                return(IodineBool.Create(Value.CompareTo(op.Value) >= 0));
            }
Ejemplo n.º 44
0
                static IodineObject Alive(VirtualMachine vm, IodineObject self, IodineObject [] args)
                {
                    var thread = self as IodineThread;

                    if (thread == null)
                    {
                        vm.RaiseException(new IodineTypeException(TypeDefinition.Name));
                        return(null);
                    }

                    return(IodineBool.Create(thread.Value.IsAlive));
                }
Ejemplo n.º 45
0
        IodineObject Sleep(VirtualMachine vm, IodineObject self, IodineObject [] args)
        {
            if (args.Length <= 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
            }
            var time = args [0] as IodineInteger;

            Thread.Sleep((int)time.Value);

            return(null);
        }
Ejemplo n.º 46
0
        public override IodineObject NotEquals(VirtualMachine vm, IodineObject right)
        {
            double floatVal;

            if (!(TryConvertToFloat(right, out floatVal)))
            {
                vm.RaiseException(new IodineTypeException(
                                      "Right hand value expected to be of type Float"));
                return(null);
            }
            return(IodineBool.Create(Math.Abs(Value - floatVal) > double.Epsilon));
        }
Ejemplo n.º 47
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);
        }
Ejemplo n.º 48
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);
        }
Ejemplo n.º 49
0
                private IodineObject Empty(VirtualMachine vm, IodineObject self, IodineObject[] args)
                {
                    IodineSubprocess proc = self as IodineSubprocess;

                    if (proc == null)
                    {
                        vm.RaiseException(new IodineTypeException(TypeDefinition.Name));
                        return(null);
                    }

                    return(IodineBool.Create(proc.Value.StandardOutput.Peek() < 0));
                }
Ejemplo n.º 50
0
 public virtual void SetAttribute(VirtualMachine vm, string name, IodineObject value)
 {
     if (Base != null && !Attributes.ContainsKey(name))
     {
         if (Base.HasAttribute(name))
         {
             Base.SetAttribute(vm, name, value);
             return;
         }
     }
     SetAttribute(name, value);
 }
        public override bool IterMoveNext(VirtualMachine vm)
        {
            if (frame.AbortExecution)
            {
                return(false);
            }

            vm.NewFrame(frame);
            value = vm.EvalCode(Target);
            vm.EndFrame();
            return(frame.Yielded);
        }
Ejemplo n.º 52
0
            private IodineObject Upper(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                var thisObj = self as IodineString;

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

                return(new IodineString(thisObj.Value.ToUpper()));
            }
Ejemplo n.º 53
0
            private IodineObject Flush(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineStream thisObj = self as IodineStream;

                if (thisObj.Closed)
                {
                    vm.RaiseException("Stream has been closed!");
                    return(null);
                }
                thisObj.File.Flush();
                return(null);
            }
Ejemplo n.º 54
0
            IodineObject Prepend(VirtualMachine vm, IodineObject self, IodineObject [] arguments)
            {
                var thisObj = self as IodineList;

                if (arguments.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                thisObj.Objects.Insert(0, arguments [0]);
                return(thisObj);
            }
Ejemplo n.º 55
0
                private IodineObject Alive(VirtualMachine vm, IodineObject self, IodineObject[] args)
                {
                    IodineSubprocess proc = self as IodineSubprocess;

                    if (proc == null)
                    {
                        vm.RaiseException(new IodineTypeException(TypeDefinition.Name));
                        return(null);
                    }

                    return(IodineBool.Create(proc.Value.HasExited));
                }
Ejemplo n.º 56
0
 private StackFrame(
     IodineModule module,
     IodineMethod method,
     IodineObject[] arguments,
     StackFrame parent,
     IodineObject self,
     AttributeDictionary locals,
     AttributeDictionary parentLocals) : this(module, method, arguments, parent, self)
 {
     this.parentLocals = parentLocals;
     this.locals       = locals;
 }
Ejemplo n.º 57
0
                private IodineObject Read(VirtualMachine vm, IodineObject self, IodineObject[] args)
                {
                    IodineSubprocess proc = self as IodineSubprocess;

                    if (proc == null)
                    {
                        vm.RaiseException(new IodineTypeException(TypeDefinition.Name));
                        return(null);
                    }

                    return(new IodineString(proc.Value.StandardOutput.ReadToEnd()));
                }
Ejemplo n.º 58
0
        private IodineObject property(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length <= 0)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }
            IodineObject getter = args [0];
            IodineObject setter = args.Length > 1 ? args [1] : null;

            return(new IodineProperty(getter, setter, null));
        }
Ejemplo n.º 59
0
 public override void Inherit(VirtualMachine vm, IodineObject self, IodineObject[] arguments)
 {
     foreach (IodineMethod method in RequiredMethods)
     {
         if (!self.HasAttribute(method.Name))
         {
             vm.RaiseException(new IodineNotSupportedException());
             return;
         }
     }
     self.Interfaces.Add(this);
 }
Ejemplo n.º 60
0
                static IodineObject GetNextMatch(VirtualMachine vm, IodineObject self, IodineObject [] args)
                {
                    var match = self as IodineMatch;

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

                    return(new IodineMatch(match.Value.NextMatch()));
                }