コード例 #1
0
ファイル: Type.cs プロジェクト: Phoshi/Gram
 public Type(IValue parent, IValue predicate, string predicateDescription)
 {
     this.RawTypeOf            = parent.Get <IType>().RawTypeOf;
     this.parentValue          = parent.Get <IType>();
     this.Predicate            = predicate;
     this.predicateDescription = predicateDescription;
 }
コード例 #2
0
        public IValue BinaryOperator(IValue operand1, string op, IValue operand2)
        {
            switch (op)
            {
            case "+": {
                var list = new List <IValue>(operand1.Get <IEnumerable <IValue> >());
                list.Add(operand2);
                return(ValueFactory.make(list));
            }

            case "==": {
                var list      = new List <IValue>(operand1.Get <IEnumerable <IValue> >());
                var otherList = new List <IValue>(operand2.Get <IEnumerable <IValue> >());
                if (list.Count() != otherList.Count())
                {
                    return(ValueFactory.make(false));
                }
                if (list.Count == 0)
                {
                    return(ValueFactory.make(true));
                }
                var results = list.Zip(otherList, (item, otherItem) => item.Operator("==", otherItem));
                return(ValueFactory.make(results.All(r => r.Get <int>() == 1)));
            }

            case "()": {
                return(new Value.Value(new ListType(operand1, operand1.ToString()), operand2));
            }
            }

            throw new InvalidOperationException();
        }
コード例 #3
0
ファイル: BindingAssigner.cs プロジェクト: Phoshi/Gram
        public override Tree <Binding> VisitBinding_multiple(gramParser.Binding_multipleContext context)
        {
            var bindings = context.binding().Zip(value.Get <IEnumerable <IValue> >(), (binding, subValue) => new BindingAssigner(interpreter, subValue).Visit(binding));
            var tree     = new Tree <Binding>();

            foreach (var binding in bindings)
            {
                tree.Add(binding);
            }

            return(tree);
        }
コード例 #4
0
        public virtual void AddTag(string tag, IValue v)
        {
            if (tags == null)
            {
                tags = new Dictionary <string, IValue>(1);
            }
            //Generics.newHashMap(1);
            // Adds v as a tag into a list of tags...
            IList <IValue> tagList = null;

            if (tags.Contains(tag))
            {
                IValue oldValue = tags[tag];
                if (Expressions.TypeList.Equals(oldValue.GetType()))
                {
                    tagList = ErasureUtils.UncheckedCast(oldValue.Get());
                }
                else
                {
                    // Put the oldValue into a new array
                    tagList = new List <IValue>();
                    tagList.Add(oldValue);
                    tags[tag] = Expressions.CreateValue(Expressions.TypeList, tagList);
                }
            }
            else
            {
                tagList   = new List <IValue>();
                tags[tag] = Expressions.CreateValue(Expressions.TypeList, tagList);
            }
            tagList.Add(v);
        }
コード例 #5
0
 public IValue Operator(string op, IValue operand)
 {
     if (op == "()")
     {
         var parameterChecker = new TypeChecker(parameterType);
         if (!parameterChecker.Check(operand))
         {
             throw new TypeException("Function parameter is invalid");
         }
         var result        = ValueBehaviourFactory.GetBehaviour(this, operand).BinaryOperator(this, op, operand);
         var resultChecker = new TypeChecker(returnType);
         if (!resultChecker.Check(result))
         {
             throw new TypeException("Function result is invalid");
         }
         IType type;
         if (returnType.Type.Check(ValueType.TYPE))
         {
             type = returnType.Get <IType>();
         }
         else if (returnType.Type.Check(ValueType.LIST))
         {
             type = new ListType(returnType, returnType.ToString());
         }
         else
         {
             throw new TypeException("Function return value invalid!");
         }
         return(new Binding(result.ToString(), type, result).Value);
     }
     return(ValueBehaviourFactory.GetBehaviour(this, operand).BinaryOperator(this, op, operand));
 }
コード例 #6
0
ファイル: STE.cs プロジェクト: PowerOfDark/TeamTest
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");
            var r    = new Random(id);

            using (var sw = new StreamWriter(path, false))
            {
                var x  = X.Get(r);
                var y  = Y.Get(r);
                var px = 2 * x + AddX.Get(r);
                var py = 2 * y + AddY.Get(r);

                sw.WriteLine($"{px} {py}");
                sw.WriteLine($"{x} {y}");

                var chance = Chance.Get(r);

                for (var i = 0; i < x; i++)
                {
                    for (var j = 0; j < y; j++)
                    {
                        sw.Write(r.Next(0, chance) == 0 ? '#' : '.');
                    }
                    sw.WriteLine();
                }
            }
            return(path);
        }
コード例 #7
0
ファイル: KOL.cs プロジェクト: PowerOfDark/TeamTest
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");

            using (var sw = new StreamWriter(path, false))
            {
                var r = new Random(id);
                var n = N.Get(r);
                var m = M.Get(r);

                sw.WriteLine($"{n} {m}");
                for (int i = 0; i < n; i++)
                {
                    sw.Write($"{(char)(r.Next('a', 'z' + 1))}");
                }
                sw.WriteLine("");
                for (int i = 0; i < m; i++)
                {
                    var b = r.Next(1, n + 1);
                    var a = r.Next(1, b + 1);
                    sw.WriteLine($"{a} {b}");
                }
            }
            return(path);
        }
コード例 #8
0
ファイル: POD.cs プロジェクト: PowerOfDark/TeamTest
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");
            var r    = new Random(id);

            using (var sw = new StreamWriter(path, false))
            {
                var q = Q.Get(r);
                sw.WriteLine($"{Q.Get(r)}");
                for (int i = 0; i < q; i++)
                {
                    sw.WriteLine($"{N.Get(r)}");
                }
            }
            return(path);
        }
コード例 #9
0
 public Value(IType type, IValue val)
 {
     if (!type.Check(val))
     {
         throw new TypeException("Attempted to create value with mismatched type!");
     }
     Type  = type;
     value = val.Get <object>();
 }
コード例 #10
0
        public void Binding()
        {
            IDisposable binding = new ValueBinding <int>(left, right);

            left.Set(1);

            Assert.Equal(1, right.Get());

            right.Set(2);

            Assert.Equal(2, left.Get());

            binding.Dispose();

            left.Set(3);

            Assert.Equal(2, right.Get());
        }
コード例 #11
0
ファイル: FuncBehaviour.cs プロジェクト: Phoshi/Gram
        public IValue BinaryOperator(IValue operand1, string op, IValue operand2)
        {
            switch (op)
            {
            case "()": return(operand1.Get <Func <IValue, IValue> >()(operand2));
            }

            throw new InvalidOperationException();
        }
コード例 #12
0
 public ListType(IValue types, String description)
 {
     if (!types.Type.Check(ValueType.LIST))
     {
         throw new TypeException("List type must be actually a list!");
     }
     this.predicate    = ValueFactory.make(makeListTypeChecker(types.Get <IEnumerable <IValue> >()));
     this.friendlyName = description;
     this.creationList = types;
 }
コード例 #13
0
ファイル: TypeChecker.cs プロジェクト: Phoshi/Gram
 public bool Check(IValue value)
 {
     if (typeTree.Type.Check(ValueType.TYPE) && typeTree.Get <IType>().Check(ValueType.ANY))
     {
         return(true);
     }
     if (value.Type.Check(ValueType.TYPE) && value.Get <IType>().Check(ValueType.ANY))
     {
         return(true);
     }
     if (!value.Type.Check(ValueType.LIST) || !typeTree.Type.Check(ValueType.LIST))
     {
         if (compareAsType)
         {
             var type = typeTree.Type.Check(ValueType.LIST)
                 ? ValueFactory.make(new ListType(typeTree, typeTree.ToString()))
                 : typeTree;
             if (value.Type.Check(ValueType.LIST))
             {
                 return(typeTree.Get <IType>().Check(new ListType(value, value.ToString())));
             }
             return(type.Get <IType>().Check(value.Get <IType>()));
         }
         if (typeTree.Type.Check(ValueType.LIST))
         {
             return(new ListType(typeTree, typeTree.ToString()).Check(value));
         }
         return(typeTree.Get <IType>().Check(value));
     }
     else
     {
         if (typeTree.Get <IEnumerable <IValue> >().Count() != value.Get <IEnumerable <IValue> >().Count())
         {
             return(false);
         }
         if (typeTree.Get <IEnumerable <IValue> >().Count() == 0)
         {
             return(true);
         }
         return(typeTree.Get <IEnumerable <IValue> >().Zip(value.Get <IEnumerable <IValue> >(), (bindChildren, val) => new TypeChecker(bindChildren, compareAsType).Check(val)).Aggregate((one, two) => one && two));
     }
 }
コード例 #14
0
 public virtual IValue BinaryOperator(IValue operand1, string op, IValue operand2)
 {
     switch (op)
     {
     case "+": {
         var list = new List <IValue>(operand1.Get <IEnumerable <IValue> >());
         list.Add(operand2);
         return(ValueFactory.make(list));
     }
     }
     throw new InvalidOperationException();
 }
コード例 #15
0
        public void ToValue()
        {
            ISource <int> source = new Source <int>(1);

            IValue <int> value = source.ToValue();

            Assert.Equal(1, value.Get());

            value.Set(2);

            Assert.Equal(2, source.Value);
        }
コード例 #16
0
        public IValue UnaryOperator(IValue operand1, string op)
        {
            switch (op)
            {
            case "!":
                return(ValueFactory.make(operand1 != ValueFactory.make(true)));

            case "-":
                return(ValueFactory.make(-operand1.Get <int>()));
            }

            throw new InvalidOperationException();
        }
コード例 #17
0
        public void GetValue_ValueFactory()
        {
            bool calledFirst  = false;
            bool calledSecond = false;

            IValue <int> firstValue  = container.GetValue <int>("I", () => { calledFirst = true; return(new Value <int>(1)); });
            IValue <int> secondValue = container.GetValue <int>("I", () => { calledFirst = true; return(new Value <int>(1)); });

            Assert.Equal(1, firstValue.Get());
            Assert.True(calledFirst);
            Assert.False(calledSecond);
            Assert.Same(firstValue, secondValue);
        }
コード例 #18
0
ファイル: GRA.cs プロジェクト: PowerOfDark/TeamTest
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");

            using (var sw = new StreamWriter(path, false))
            {
                var r = new Random(id);
                var k = K.Get(r);
                var n = N.Get(r);

                sw.WriteLine($"{n} {k}");
            }
            return(path);
        }
        public virtual int DetermineRelFlags(ICoreMap annotation, TimeExpression te)
        {
            int  flags    = 0;
            bool flagsSet = false;

            if (te.value.GetTags() != null)
            {
                IValue v = te.value.GetTags().GetTag("resolveTo");
                if (v != null && v.Get() is Number)
                {
                    flags    = ((Number)v.Get());
                    flagsSet = true;
                }
            }
            if (!flagsSet)
            {
                if (te.GetTemporal() is SUTime.PartialTime)
                {
                    flags = SUTime.ResolveToClosest;
                }
            }
            return(flags);
        }
コード例 #20
0
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");

            using (var sw = new StreamWriter(path, false))
            {
                var r = new Random(id);
                var n = N.Get(r);
                for (int i = 0; i < n; i++)
                {
                    sw.Write($"{(char)(r.Next('A', 'Z' + 1))}");
                }
            }
            return(path);
        }
コード例 #21
0
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");
            var r    = new Random(id);

            using (var sw = new StreamWriter(path, false))
            {
                var          n     = N.Get(r);
                var          m     = M.Get(r);
                const string chars = "ATGC";
                sw.WriteLine(Enumerable.Repeat(chars, n).Select(s => s[r.Next(s.Length)]).ToArray());
                sw.WriteLine(Enumerable.Repeat(chars, m).Select(s => s[r.Next(s.Length)]).ToArray());
            }
            return(path);
        }
コード例 #22
0
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");

            using (var sw = new StreamWriter(path, false))
            {
                var r = new Random(id);
                var n = N.Get(r);
                sw.WriteLine($"{n}");
                for (int i = 0; i < n; i++)
                {
                    sw.Write("{0} ", r.Next(0, 2000000001) - 1000000000);
                }
            }
            return(path);
        }
コード例 #23
0
ファイル: ListToIntBehaviour.cs プロジェクト: Phoshi/Gram
 public override IValue BinaryOperator(IValue operand1, string op, IValue operand2)
 {
     if (op == "[]")
     {
         var index = operand2.Get <int>();
         var list  = operand1.Get <IEnumerable <IValue> >();
         if (index >= 0)
         {
             return(list.Skip(index).First());
         }
         else
         {
             return(list.Reverse().Skip(-index - 1).First());
         }
     }
     return(base.BinaryOperator(operand1, op, operand2));
 }
コード例 #24
0
        public void GetValue_Factory()
        {
            bool calledFirst  = false;
            bool calledSecond = false;

            IValue <int> firstValue  = container.GetValue <int>("I", () => { calledFirst = true; return(1); });
            IValue <int> secondValue = container.GetValue <int>("I", () => { calledSecond = true; return(1); });

            // Value not yet fetched, so factory hasn't been called.
            Assert.False(calledFirst);
            Assert.False(calledSecond);

            Assert.Equal(1, firstValue.Get());
            Assert.True(calledFirst);
            Assert.False(calledSecond);
            Assert.Same(firstValue, secondValue);
        }
 public override IValue Apply(Env env, IList <IValue> @in)
 {
     if (@in.Count > 1)
     {
         SUTime.TemporalOp op     = (SUTime.TemporalOp)@in[0].Get();
         bool     allTemporalArgs = true;
         object[] args            = new object[@in.Count - 1];
         for (int i = 0; i < args.Length; i++)
         {
             IValue v = @in[i + 1];
             if (v != null)
             {
                 args[i] = v.Get();
                 if (args[i] is MatchedExpression)
                 {
                     IValue v2 = ((MatchedExpression)args[i]).GetValue();
                     args[i] = (v2 != null) ? v2.Get() : null;
                 }
                 if (args[i] != null && !(args[i] is SUTime.Temporal))
                 {
                     allTemporalArgs = false;
                 }
             }
         }
         if (allTemporalArgs)
         {
             SUTime.Temporal[] temporalArgs = new SUTime.Temporal[args.Length];
             for (int i_1 = 0; i_1 < args.Length; i_1++)
             {
                 temporalArgs[i_1] = (SUTime.Temporal)args[i_1];
             }
             return(new Expressions.PrimitiveValue(null, op.Apply(temporalArgs)));
         }
         else
         {
             return(new Expressions.PrimitiveValue(null, op.Apply(args)));
         }
     }
     else
     {
         throw new ArgumentException("Invalid number of arguments to " + this.name);
     }
 }
コード例 #26
0
        public static IList <T> RemoveNullValues <T>(IList <T> chunks)
            where T : MatchedExpression
        {
            IList <T> okayChunks = new List <T>(chunks.Count);

            foreach (T chunk in chunks)
            {
                IValue v = chunk.value;
                if (v == null || v.Get() == null)
                {
                }
                else
                {
                    //skip
                    okayChunks.Add(chunk);
                }
            }
            return(okayChunks);
        }
コード例 #27
0
        public string GenerateTest(int id, string directory)
        {
            var path = Path.Combine(directory, $"{JobName}{id}.in");
            var r    = new Random(id);

            using (var sw = new StreamWriter(path, false))
            {
                var n = N.Get(r);
                var t = T.Get(r);

                sw.WriteLine($"{n} {t}");
                for (int i = 0; i < n; i++)
                {
                    sw.Write($"{D.Get(r)} ");
                }
                sw.WriteLine();
                sw.WriteLine($"{X.Get(r)} {Y.Get(r)}");
            }
            return(path);
        }
        public Task Send(Notification n)
        {
            var subs = _subs.Get().Where(x => x.Topic.Equals(n.Topic, StringComparison.InvariantCultureIgnoreCase))
                       .ToDictionary(x => x.GroupId.ToWebSafeBase64(), x => x.OutletGroup, StringComparer.InvariantCultureIgnoreCase);
            var users = subs.Keys;

            var subscribedUsers = _userOutlets.Get().Where(x => users.Contains(x.Key, StringComparer.InvariantCultureIgnoreCase));

            foreach (var user in subscribedUsers)
            {
                user.Value.ForEach(o =>
                {
                    if (o.OutletGroup.Equals(subs[user.Key], StringComparison.InvariantCultureIgnoreCase))
                    {
                        Send(user.Key, n, o);
                    }
                });
            }
            return(Task.CompletedTask);
        }
コード例 #29
0
        public IValue BinaryOperator(IValue operand1, string op, IValue operand2)
        {
            switch (op)
            {
            case "+":   return(ValueFactory.make(operand1.Get <int>() + operand2.Get <int>()));

            case "-":   return(ValueFactory.make(operand1.Get <int>() - operand2.Get <int>()));

            case "/":   return(ValueFactory.make(operand1.Get <int>() / operand2.Get <int>()));

            case "*":   return(ValueFactory.make(operand1.Get <int>() * operand2.Get <int>()));

            case "%":   return(ValueFactory.make(operand1.Get <int>() % operand2.Get <int>()));

            case "==":  return(ValueFactory.make(operand1.Get <int>() == operand2.Get <int>()));

            case ">":   return(ValueFactory.make(operand1.Get <int>() > operand2.Get <int>()));

            case "<":   return(ValueFactory.make(operand1.Get <int>() < operand2.Get <int>()));
            }

            throw new InvalidOperationException();
        }
コード例 #30
0
ファイル: Type.cs プロジェクト: Phoshi/Gram
 public Type(IValue parent)
 {
     this.parentValue = parent.Get <IType>();
     Predicate        = NoOpPredicate;
 }