Ejemplo n.º 1
0
 public IodineMatch(Match val)
     : base(MatchTypeDef)
 {
     Value = val;
     SetAttribute("value", new IodineString(val.Value));
     SetAttribute("success", IodineBool.Create(val.Success));
 }
Ejemplo n.º 2
0
                IodineObject IsMatch(VirtualMachine vm, IodineObject self, IodineObject [] args)
                {
                    if (args.Length <= 0)
                    {
                        vm.RaiseException(new IodineArgumentException(1));
                        return(null);
                    }

                    var regexObj = self as IodineRegex;

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

                    var expr = args [0] as IodineString;

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

                    return(IodineBool.Create(regexObj.Value.IsMatch(expr.ToString())));
                }
Ejemplo n.º 3
0
        private IodineObject unpackObj(VirtualMachine vm, BinaryReader br, char type, int arg)
        {
            switch (type)
            {
            case '?':
            {
                return(IodineBool.Create(br.ReadBoolean()));
            }

            case 'b':
            {
                return(new IodineInteger(br.ReadSByte()));
            }

            case 'B':
            {
                return(new IodineInteger(br.ReadByte()));
            }

            case 'h':
            {
                return(new IodineInteger(br.ReadInt16()));
            }

            case 'H':
            {
                return(new IodineInteger(br.ReadUInt16()));
            }

            case 'l':
            case 'i':
            {
                return(new IodineInteger(br.ReadInt32()));
            }

            case 'I':
            case 'L':
            {
                return(new IodineInteger(br.ReadUInt32()));
            }

            case 'q':
            {
                return(new IodineInteger(br.ReadInt64()));
            }

            case 'Q':
            {
                return(new IodineInteger((long)br.ReadUInt64()));
            }

            case 'p':
            case 's':
            {
                return(new IodineString(Encoding.ASCII.GetString(br.ReadBytes(arg))));
            }
            }
            return(null);
        }
Ejemplo n.º 4
0
 public virtual IodineObject Equals(VirtualMachine vm, IodineObject right)
 {
     if (Attributes.ContainsKey("__equals__"))
     {
         return(GetAttribute(vm, "__equals__").Invoke(vm, new IodineObject[] { right }));
     }
     return(IodineBool.Create(this == right));
 }
Ejemplo n.º 5
0
 public virtual IodineObject NotEquals(VirtualMachine vm, IodineObject left)
 {
     if (Attributes.ContainsKey("__notequals__"))
     {
         return(GetAttribute(vm, "__notequals__").Invoke(vm, new IodineObject[] { left }));
     }
     return(IodineBool.Create(this != left));
 }
Ejemplo n.º 6
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.º 7
0
 public IodineMatch(Match val)
     : base(MatchTypeDef)
 {
     Value = val;
     SetAttribute("value", new IodineString(val.Value));
     SetAttribute("success", IodineBool.Create(val.Success));
     SetAttribute("getNextMatch", new InternalMethodCallback(getNextMatch, this));
 }
Ejemplo n.º 8
0
 private IodineObject endsWith(VirtualMachine vm, IodineObject self, IodineObject[] args)
 {
     if (args.Length < 1)
     {
         vm.RaiseException(new IodineArgumentException(1));
         return(null);
     }
     return(IodineBool.Create(Value.EndsWith(args [0].ToString())));
 }
Ejemplo n.º 9
0
        private IodineObject Call(VirtualMachine vm, IodineObject self, IodineObject[] args)
        {
            if (args.Length < 1)
            {
                vm.RaiseException(new IodineArgumentException(1));
                return(null);
            }

            IodineString program = args [0] as IodineString;

            string arguments = "";
            bool   useShell  = false;

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

            if (args.Length > 1)
            {
                IodineString argObj = args [1] as IodineString;

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

                arguments = argObj.Value;
            }

            if (args.Length > 2)
            {
                IodineBool useShellObj = args [1] as IodineBool;

                if (useShellObj == null)
                {
                    vm.RaiseException(new IodineTypeException("Bool"));
                    return(null);
                }

                useShell = useShellObj.Value;
            }

            ProcessStartInfo info = new ProcessStartInfo();

            info.FileName        = program.Value;
            info.Arguments       = arguments;
            info.UseShellExecute = useShell;

            Process proc = Process.Start(info);

            proc.WaitForExit();

            return(new IodineInteger(proc.ExitCode));
        }
Ejemplo n.º 10
0
 public override IodineObject PerformUnaryOperation(VirtualMachine vm, UnaryOperation op)
 {
     switch (op)
     {
     case UnaryOperation.BoolNot:
         return(IodineBool.Create(!Value));
     }
     return(null);
 }
Ejemplo n.º 11
0
 private IodineObject contains(VirtualMachine vm, IodineObject self, IodineObject[] args)
 {
     if (args.Length <= 0)
     {
         vm.RaiseException(new IodineArgumentException(1));
         return(null);
     }
     return(IodineBool.Create(Dict.ContainsKey(args [0].GetHashCode())));
 }
Ejemplo n.º 12
0
        public override IodineObject GreaterThanOrEqual(VirtualMachine vm, IodineObject right)
        {
            BigInteger intVal;

            if (!ConvertToBigInt(right, out intVal))
            {
                vm.RaiseException(new IodineTypeException("Right hand side must be of type Int!"));
            }
            return(IodineBool.Create(Value >= intVal));
        }
Ejemplo n.º 13
0
        public override IodineObject NotEquals(VirtualMachine vm, IodineObject right)
        {
            var str = right as IodineString;

            if (str == null)
            {
                return(base.NotEquals(vm, right));
            }
            return(IodineBool.Create(str.Value != Value));
        }
Ejemplo n.º 14
0
        public override IodineObject NotEquals(VirtualMachine vm, IodineObject right)
        {
            IodineBytes str = right as IodineBytes;

            if (str == null)
            {
                return(base.NotEquals(vm, right));
            }
            return(IodineBool.Create(!Enumerable.SequenceEqual <byte> (str.Value, Value)));
        }
Ejemplo n.º 15
0
        public override IodineObject GreaterThanOrEqual(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(IodineBool.Create(Value >= intVal.Value));
        }
Ejemplo n.º 16
0
            private IodineObject StartsWith(VirtualMachine vm, IodineObject self, IodineObject[] args)
            {
                IodineString thisObj = self as IodineString;

                if (args.Length < 1)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                return(IodineBool.Create(thisObj.Value.StartsWith(args [0].ToString())));
            }
Ejemplo n.º 17
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)));
        }
Ejemplo n.º 18
0
        public override IodineObject Equals(VirtualMachine vm, IodineObject right)
        {
            IodineHashMap hash = right as IodineHashMap;

            if (hash == null)
            {
                vm.RaiseException(new IodineTypeException("HashMap"));
                return(null);
            }
            return(IodineBool.Create(compareTo(hash)));
        }
Ejemplo n.º 19
0
        public override bool Equals(IodineObject obj)
        {
            IodineBool boolVal = obj as IodineBool;

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

            return(false);
        }
Ejemplo n.º 20
0
        public override IodineObject NotEquals(VirtualMachine vm, IodineObject right)
        {
            var 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.º 21
0
            IodineObject Contains(VirtualMachine vm, IodineObject self, IodineObject [] args)
            {
                var thisObj = self as IodineDictionary;

                if (args.Length <= 0)
                {
                    vm.RaiseException(new IodineArgumentException(1));
                    return(null);
                }
                return(IodineBool.Create(thisObj.dict.ContainsKey(args [0])));
            }
Ejemplo n.º 22
0
        public override IodineObject Equals(VirtualMachine vm, IodineObject right)
        {
            var hash = right as IodineDictionary;

            if (hash == null)
            {
                vm.RaiseException(new IodineTypeException("HashMap"));
                return(null);
            }
            return(IodineBool.Create(Equals(hash)));
        }
Ejemplo n.º 23
0
                IodineObject Empty(VirtualMachine vm, IodineObject self, IodineObject [] args)
                {
                    var thisObj = self as IodineSubprocess;

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

                    return(IodineBool.Create(thisObj.Value.StandardOutput.Peek() < 0));
                }
Ejemplo n.º 24
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.º 25
0
                private static IodineObject Locked(VirtualMachine vm, IodineObject self, IodineObject[] args)
                {
                    IodineLock spinlock = self as IodineLock;

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

                    return(IodineBool.Create(spinlock.IsLocked()));
                }
Ejemplo n.º 26
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.º 27
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.º 28
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.º 29
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.º 30
0
        public override IodineObject LessThanOrEqual(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(Value <= floatVal));
        }