Esempio n. 1
0
        static TypeBindings()
        {
            TypeBinding boolean = new TypeBinding(PRIMITIVE_BOOLEAN_NAME);
            TypeBinding str = new TypeBinding(PRIMITIVE_STRING_NAME);
            TypeBinding integer = new TypeBinding(PRIMITIVE_INTEGER_NAME);

            boolean.AddOperators(new Dictionary<string, TypeBinding> () {
                {Operators.EQUALITY, boolean},
                {Operators.NOT, boolean},
                {Operators.AND, boolean}
            });

            str.AddOperators(new Dictionary<string, TypeBinding> () {
                {Operators.ADDITION, str},
                {Operators.EQUALITY, boolean}
            });

            integer.AddOperators(new Dictionary<string, TypeBinding> () {
                {Operators.ADDITION, integer},
                {Operators.SUBSTRACTION, integer},
                {Operators.MULTIPLICATION, integer},
                {Operators.DIVISION, integer},
                {Operators.LESS, boolean},
                {Operators.EQUALITY, boolean}
            });
            AddTypeBinding(boolean);
            AddTypeBinding(str);
            AddTypeBinding(integer);
        }
Esempio n. 2
0
 public void AddOperator(string oper, TypeBinding targetType)
 {
     this.transitions.Add(oper, targetType);
 }
Esempio n. 3
0
 public static object GetDefaultValue(TypeBinding binding)
 {
     TypeModel model;
     if (!models.TryGetValue (binding, out model)) {
         throw new InvalidOperationException("No implementation for typebinding " + binding.ToString ());
     }
     return model.DefaultValue;
 }
Esempio n. 4
0
 public static void AddTypeBinding(TypeBinding binding)
 {
     types.Add(binding.Name, binding);
 }
Esempio n. 5
0
 public static object EvaluateUnaryOperator(TypeBinding type, string oper, object operand)
 {
     TypeModel model;
     Func<object,object> unOp;
     if (!models.TryGetValue (type, out model)) {
         throw new InvalidOperationException("No implementation for typebinding " + type.ToString ());
     }
     if (!model.UnaryOperatorImplementations.TryGetValue (oper, out unOp)) {
         throw new InvalidOperationException("Type model for type binding " + type.ToString() + " does not implement operator " + oper);
     }
     return unOp(operand);
 }