public DebugSession (VirtualMachine vm, Socket socket)
		{
			virtualMachine = vm;
			baseStream = new NetworkStream (socket);
			requestStream = new StreamReader (baseStream);
			responseStream = new StreamWriter (baseStream);
		}
			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);
				}
			}
Exemple #3
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;
		}
Exemple #4
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));
		}
Exemple #5
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;
			}
			private IodineObject push (VirtualMachine vm, IodineObject self, IodineObject[] args)
			{
				foreach (IodineObject obj in args) {
					Stack.Push (obj);
				}
				return null;
			}
Exemple #7
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 ()));
			}
Exemple #8
0
			public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
			{
				if (args.Length <= 0) {
					vm.RaiseException (new IodineArgumentException (1));
				}
				return new IodineBytes (args [0].ToString ());
			}
		public override void Exit (VirtualMachine vm)
		{
			if (!Closed) {
				File.Close ();
				File.Dispose ();
			}
		}
Exemple #10
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;
		}
Exemple #11
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));
			}
		}
Exemple #12
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);
		}
		private IodineObject append (VirtualMachine vm, IodineObject self, IodineObject[] args)
		{
			foreach (IodineObject obj in args) {
				buffer.Append (obj.ToString (vm));
			}
			return null;
		}
Exemple #14
0
 public override bool IterMoveNext(VirtualMachine vm)
 {
     if (stackFrame.AbortExecution) {
         return false;
     }
     value = vm.InvokeMethod (baseMethod, stackFrame, self, arguments);
     return stackFrame.Yielded;
 }
Exemple #15
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 #16
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);
		}
Exemple #17
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;
			}
Exemple #18
0
 public override IodineObject GetAttribute(VirtualMachine vm, string name)
 {
     if (!initializerInvoked) {
         initializerInvoked = true;
         Initializer.Invoke (vm, new IodineObject[] { });
     }
     return base.GetAttribute (vm, name);
 }
Exemple #19
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;
			}
Exemple #20
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;
		}
Exemple #21
0
 public override bool IterMoveNext(VirtualMachine vm)
 {
     if (iterIndex >= this.end) {
         return false;
     }
     iterIndex += this.step;
     return true;
 }
		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;
		}
Exemple #23
0
 public virtual IodineObject Add(VirtualMachine vm, IodineObject left)
 {
     if (Attributes.ContainsKey ("__add__")) {
         return GetAttribute (vm, "__add__").Invoke (vm, new IodineObject[] {left});
     }
     vm.RaiseException (new IodineNotSupportedException (
         "The requested binary operator has not been implemented"));
     return null;
 }
Exemple #24
0
 private IodineObject getValue(VirtualMachine vm, IodineObject self, IodineObject[] args)
 {
     string keyName = args [0].ToString ();
     string name = args [1].ToString ();
     object val = Registry.GetValue (keyName, name, null);
     IodineObject ioval = null;
     IodineTypeConverter.Instance.ConvertFromPrimative (val, out ioval);
     return ioval;
 }
Exemple #25
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;
			}
			public override IodineObject Invoke (VirtualMachine vm, IodineObject[] args)
			{
				if (args.Length <= 0) {
					vm.RaiseException (new IodineArgumentException (1));
					return null;
				}
				IodineInteger size = args [0] as IodineInteger;
				return new IodineByteArray (new byte [size.Value]);
			}
Exemple #27
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;
 }
		public override void SetIndex (VirtualMachine vm, IodineObject key, IodineObject value)
		{
			IodineInteger index = key as IodineInteger;
			IodineInteger val = value as IodineInteger;
			if (index.Value < Array.Length)
				Array [(int)index.Value] = (byte)(val.Value & 0xFF);
			else
				vm.RaiseException (new IodineIndexException ());
		}
Exemple #29
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);
         }
     }
 }
Exemple #30
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);
 }
Exemple #31
0
 public override IodineObject Represent(VirtualMachine vm)
 {
     return(new IodineString(String.Format("b'{0}'", Encoding.ASCII.GetString(Value))));
 }
Exemple #32
0
 public override IodineObject GetIterator(VirtualMachine vm)
 {
     return(new BytesIterator(Value));
 }
Exemple #33
0
 public override IodineObject IterGetCurrent(VirtualMachine vm)
 {
     return(new IodineInteger((long)Value [iterIndex - 1]));
 }
Exemple #34
0
 public override void IterReset(VirtualMachine vm)
 {
     iterIndex = 0;
 }
Exemple #35
0
 public override IodineObject Len(VirtualMachine vm)
 {
     return(new IodineInteger(Value.Length));
 }
 public IodineObject Get(VirtualMachine vm)
 {
     return(getter(vm));
 }
 public IodineObject Set(VirtualMachine vm, IodineObject value)
 {
     setter(vm, value);
     return(null);
 }