@@ -10,7 +10,7 @@ internal class NativeFunctionCall : Runtime.Object
1010 public const string Divide = "/" ;
1111 public const string Multiply = "*" ;
1212 public const string Mod = "%" ;
13- public const string Negate = "~" ;
13+ public const string Negate = "_" ; // distinguish from "-" for subtraction
1414
1515 public const string Equal = "==" ;
1616 public const string Greater = ">" ;
@@ -19,6 +19,7 @@ internal class NativeFunctionCall : Runtime.Object
1919 public const string LessThanOrEquals = "<=" ;
2020 public const string NotEquals = "!=" ;
2121 public const string Not = "!" ;
22+ public const string Invert = "~" ;
2223
2324 public const string And = "&&" ;
2425 public const string Or = "||" ;
@@ -87,7 +88,7 @@ public Runtime.Object Call(List<Runtime.Object> parameters)
8788 // Special case:
8889 // - Set inverse (!set) requires knowledge of origin set, not just
8990 // the raw set dictionary.
90- if ( parameters . Count == 1 && parameters [ 0 ] is SetValue && name == "!" ) {
91+ if ( parameters . Count == 1 && parameters [ 0 ] is SetValue && name == Invert ) {
9192 var setValue = ( SetValue ) parameters [ 0 ] ;
9293 var inv = setValue . inverse ;
9394 if ( inv == null ) return new SetValue ( "UNKNOWN" , 0 ) ;
@@ -319,18 +320,20 @@ static void GenerateNativeFunctionsIfNecessary()
319320 //AddSetBinaryOp (Multiply, (x, y) => x * y);
320321 //AddSetBinaryOp (Divide, (x, y) => x / y);
321322 //AddSetBinaryOp (Mod, (x, y) => x % y); // TODO: Is this the operation we want for floats?
322- //AddSetUnaryOp (Negate, x => -x );
323+ //AddSetUnaryOp (Negate, x => x.Inverse() );
323324
324325 AddSetBinaryOp ( Equal , ( x , y ) => x . Equals ( y ) ? ( int ) 1 : ( int ) 0 ) ;
325326 AddSetBinaryOp ( Greater , ( x , y ) => x . Count > 0 && x . maxItem . Value > y . maxItem . Value ? ( int ) 1 : ( int ) 0 ) ;
326327 AddSetBinaryOp ( Less , ( x , y ) => y . Count > 0 && x . maxItem . Value < y . maxItem . Value ? ( int ) 1 : ( int ) 0 ) ;
327328 AddSetBinaryOp ( GreaterThanOrEquals , ( x , y ) => x . Count > 0 && x . maxItem . Value >= y . maxItem . Value ? ( int ) 1 : ( int ) 0 ) ;
328329 AddSetBinaryOp ( LessThanOrEquals , ( x , y ) => y . Count > 0 && x . maxItem . Value <= y . maxItem . Value ? ( int ) 1 : ( int ) 0 ) ;
329330 AddSetBinaryOp ( NotEquals , ( x , y ) => ! x . Equals ( y ) ? ( int ) 1 : ( int ) 0 ) ;
330- //AddSetUnaryOp (Not, x => !x);
331331
332- AddSetBinaryOp ( And , ( x , y ) => x . IntersectWith ( y ) ) ;
333- AddSetBinaryOp ( Or , ( x , y ) => x . UnionWith ( y ) ) ;
332+ // Placeholder to ensure that Invert gets created at all,
333+ // since this function is never actually run, and is special cased in Call
334+ AddSetUnaryOp ( Invert , x => x ) ;
335+
336+ AddSetBinaryOp ( And , ( x , y ) => x . UnionWith ( y ) ) ;
334337
335338 //AddSetBinaryOp (Max, (x, y) => Math.Max (x, y));
336339 //AddSetBinaryOp (Min, (x, y) => Math.Min (x, y));
@@ -389,6 +392,11 @@ static void AddSetBinaryOp (string name, BinaryOp<SetDictionary> op)
389392 AddOpToNativeFunc ( name , 2 , ValueType . Set , op ) ;
390393 }
391394
395+ static void AddSetUnaryOp ( string name , UnaryOp < SetDictionary > op )
396+ {
397+ AddOpToNativeFunc ( name , 1 , ValueType . Set , op ) ;
398+ }
399+
392400 static void AddFloatUnaryOp ( string name , UnaryOp < float > op )
393401 {
394402 AddOpToNativeFunc ( name , 1 , ValueType . Float , op ) ;
0 commit comments