Example #1
0
		public BELArray SortBy(ExecutionContext ctx, Block block)
		{
			ArrayList answer = new ArrayList(Array);
			try 
			{
				answer.Sort(new CustomSorter(block, ctx));
			}
			catch (InvalidOperationException e)
			{
				throw e.InnerException;
			}

			return new BELArray(answer);
		}
Example #2
0
			public CustomSorter(Block b, ExecutionContext c)
			{
				block = b;
				ctx = c;
			}
Example #3
0
		public BELArray Collect(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				answer.Add(block.Value(ctx, parms));
			}
			return answer;
		}
Example #4
0
		public BELArray Select(ExecutionContext ctx, Block block)
		{
			BELArray answer = new BELArray();
			
			foreach (IBELObject each in Array)
			{
				ArrayList parms = new ArrayList();
				parms.Add(each);
				IBELObject objValue = block.Value(ctx, parms);
				BELBoolean test = objValue as BELBoolean;
				if (test == null)
					throw new ExecutionException("Select block must evaluate to a boolean.  Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead.");
				if (test.Value)
					answer.Add(each);
			}
			return answer;
		}
Example #5
0
 public IBELObject WhileTrue(ExecutionContext ctx, Block block)
 {
     if (ParameterCount != 0)
         throw new ArgumentException("Conditional block for WhileTrue can't accept parameters.");
     return Loop(ctx, block, true);
 }
Example #6
0
 IBELObject Loop(ExecutionContext ctx, Block block, bool halt)
 {
     while (true)
     {
         IBELObject objValue = Value(ctx);
         BELBoolean test = objValue as BELBoolean;
         if (test == null)
             throw new ExecutionException(ctx.CurrentLocation, "WhileTrue/WhileFalse block must evaluate to a boolean.  Got " + BELType.BELTypeForType(objValue.GetType()).ExternalTypeName + " instead.");
         if (test.Value == halt)
             break;
     }
     return BELString.Empty;
 }
Example #7
0
		public IBELObject IfNotNull(ExecutionContext ctx, Block block)
		{
			return Instance;
		}
Example #8
0
		public IBELObject IfNotNullElse(ExecutionContext ctx, Block notNullBlock, Block nullBlock)
		{
			return nullBlock.Value(ctx);
		}
Example #9
0
		public IBELObject IfNull(ExecutionContext ctx, Block block)
		{
			return block.Value(ctx);
		}
Example #10
0
        public BELArray SortBy(ExecutionContext ctx, Block block)
        {
            // This code formerly sorted the list by having the IComparer do the comparison.
            // This was resulting in lots of superficial comparisons, as the block was being
            // evaluated lots of extra times - for the left and the right item on every comparison.
            // Instead, I changed it to rip through the array, evaluate the block exaclty once
            // for each item, and then do the sort on just the values.
            List<BelArrayEntry> entries = new List<BelArrayEntry>();

            try
            {
                foreach (IBELObject entry in Array)
                {
                    ArrayList a1 = new ArrayList();
                    a1.Add(entry);
                    IBELObject value = block.Value(ctx, a1);

                    IComparable comparable = value as IComparable;
                    if (comparable == null)
                    {
                        throw new ExecutionException(null, "Can not compare objects of type " + BELType.ExternalTypeNameForType(value.GetType()));
                    }

                    entries.Add(new BelArrayEntry(entry, comparable));
                }

                entries.Sort(new BelArrayEntry.Comparer());

            }
            catch (InvalidOperationException e)
            {
                throw e.InnerException;
            }

            BELArray results = new BELArray();
            foreach (BelArrayEntry entry in entries)
            {
                results.Add(entry.Entry);
            }
            return results;
        }
Example #11
0
		public virtual IBELObject IfNull(ExecutionContext ctx, Block block)
		{
			return UndefinedObject.Instance;
		}
Example #12
0
 public IBELObject IfFalse(ExecutionContext ctx, Block block)
 {
     if (!Value)
         return block.Value(ctx);
     else
         return UndefinedObject.Instance;
 }
Example #13
0
 public IBELObject IfTrueIfFalse(ExecutionContext ctx, Block trueBlock, Block falseBlock)
 {
     if (Value)
         return trueBlock.Value(ctx);
     else
         return falseBlock.Value(ctx);
 }