Exemple #1
0
 public static CatchBlock Catch(SourceSpan span, SourceLocation header, Type type, Variable target, Statement body)
 {
     Contract.RequiresNotNull(type, "type");
     Contract.Requires(target == null || TypeUtils.CanAssign(target.Type, type), "target");
     Contract.RequiresNotNull(body, "body");
     return new CatchBlock(span, header, type, target, body);
 }
 static Expression MakeCallBack(Variable proc, Expression[] a)
 {
     var procr = Ast.ConvertHelper(Ast.Read(proc), typeof(Callable));
       MethodInfo call = GetCallable(a.Length);
       var expr = Ast.Call(procr, call, a);
       return expr;
 }
 /// <summary>
 /// Performs an assignment variable = value
 /// </summary>
 public static BoundAssignment Assign(Variable variable, Expression value)
 {
     Contract.RequiresNotNull(variable, "variable");
     Contract.RequiresNotNull(value, "value");
     Contract.Requires(TypeUtils.CanAssign(variable.Type, value.Type));
     return new BoundAssignment(variable, value);
 }
 internal WriteStatement(Variable var, Expression value) : base(AstNodeType.WriteStatement, SourceSpan.None)
 {
   _value = value;
   _variable = var;
   if (!value.IsConstant(null))
   {
     _variable.AssumedValue = _variable.AssumedValue == null ? GetReference(value) : null;
   }
 }
Exemple #5
0
        private bool _yield; // The catch block contains a yield

        #endregion Fields

        #region Constructors

        internal CatchBlock(SourceSpan span, SourceLocation header, Type /*!*/ test, Variable target, Statement /*!*/ body)
            : base(AstNodeType.CatchBlock)
        {
            _test = test;
            _var = target;
            _body = body;
            _start = span.Start;
            _header = header;
            _end = span.End;
        }
Exemple #6
0
 private VariableReference GetOrMakeRef(Variable variable) {
     Debug.Assert(variable != null);
     if (_refs == null) {
         _refs = new Dictionary<Variable, VariableReference>();
     }
     VariableReference reference;
     if (!_refs.TryGetValue(variable, out reference)) {
         _refs[variable] = reference = new VariableReference(variable);
     }
     return reference;
 }
        internal override Expression ToExpression(MethodBinderContext context, Expression[] parameters)
        {

#if FULL
            if (_tmp == null) {
                _tmp = context.GetTemporary(Type, "outParam");
            } 
#endif


          return Ast.Comma(Ast.Assign(_tmp, base.ToExpression(context, parameters)), Ast.Read(_tmp));
        }
        internal override Expression ToExpression(MethodBinderContext context, Expression[] parameters)
        {

#if FULL
            if (_isRef) {
                if (_tmp == null) {
                    _tmp = context.GetTemporary(_parameterType, "outParam");
                }
                return Ast.Read(_tmp);
            } 
#endif


          return GetDefaultValue();
        }
        internal override Expression ToExpression(MethodBinderContext context, Expression[] parameters)
        {

#if FULL
            if (_tmp == null) {
                _tmp = context.GetTemporary(_elementType, "outParam");
            } 
#endif


          // Ideally we'd pass in Ast.ReadField(parameters[Index], "Value") but due to
            // a bug in partial trust we can't access the generic field.

            // arg is boxType ? &_tmp : throw new ArgumentTypeException()
            //   IncorrectBoxType throws the exception to avoid stack imbalance issues.
            return Ast.Condition(
                Ast.TypeIs(parameters[Index], BoxType),
                Ast.Comma(
                    Ast.Assign(
                        _tmp,
                        Ast.Call(
                            typeof(BinderOps).GetMethod("GetBox").MakeGenericMethod(_elementType),
                            Ast.ConvertHelper(parameters[Index], typeof(StrongBox<>).MakeGenericType(_elementType))
                        )
                    ),
                    Ast.Read(_tmp)
                ),
                // Condition requires types of both expressions to be identical.
                // Putting the cast here is a temporary workaround until the
                // emit address and reference argument passing is finished.
                Ast.Convert(
                    Ast.Call(
                        typeof(BinderOps).GetMethod("IncorrectBoxType"),
                        Ast.Constant(BoxType),
                        Ast.ConvertHelper(parameters[Index], typeof(object))
                    ),
                    _elementType
                )
            );
        }
 internal DeleteStatement(SourceSpan span, Variable /*!*/ var)
     : base(AstNodeType.DeleteStatement, span) {
     _var = var;
 }
Exemple #11
0
        private bool TryGetIndex(Variable variable, out int index)
        {
            if (variable != null) {
                if (_indices.TryGetValue(variable, out index)) {
                    index *= 2;
                    return true;
                }
            }

            index = -1;
            return false;
        }
Exemple #12
0
 private bool TryCheckVariable(Variable variable, out bool defined)
 {
     int index;
     if (TryGetIndex(variable, out index)) {
         Debug.Assert(index < _bits.Count);
         //defined = _bits.Get(index);
         //if (!defined) {
         //    variable.UninitializedUse();
         //}
         //if (!_bits.Get(index + 1)) {
         //    // Found an unbound use of the name => need to initialize to Uninitialized.instance
         //    variable.UnassignedUse();
         //}
         defined = true;
         return true;
     } else {
         // TODO: Report unbound name - error
         defined = false;
         return false;
     }
 }
 /// <summary>
 /// Performs an assignment variable = value
 /// </summary>
 public static Statement Write(Variable variable, Variable value)
 {
     //return Statement(Assign(variable, Ast.Read(value)));
       return new WriteStatement(variable, Ast.Read(value));
 }
Exemple #14
0
        /// <summary>
        /// Create a context for keeping track of allocated temporary variables inside of TemporaryStorage.
        /// When this function is called, the variables given by paramVars will be set to the values given by paramValues;
        /// when the returned object is disposed of, the supplied paramVars and tempVars variables will be removed from temporary storage.
        /// </summary>
        internal CodeContext GetTemporaryVariableContext(CodeContext context, Variable[] paramVars, object[] paramValues) {
            Debug.Assert(paramVars.Length == paramValues.Length);

            Scope scope = CloneForTemporaries();
            context = new CodeContext(scope, context.LanguageContext, context.ModuleContext);
            
            for (int i = 0; i < paramValues.Length; i++) {
                scope.TemporaryStorage[paramVars[i]] = paramValues[i];
            }

            return context;
        }
 public AbstractValue Lookup(Variable variable) {
     Variable newVar = _variableMap[variable];
     return AbstractValue.LimitType(newVar.Type, Ast.ReadDefined(newVar));
 }
Exemple #16
0
 internal VariableReference Reference(Variable variable)
 {
     if (_references == null) {
         _references = new Dictionary<Variable, VariableReference>();
     }
     if (variable.Block == null)
     {
       return null;
     }
     VariableReference reference;
     if (!_references.TryGetValue(variable, out reference)) {
         _references[variable] = reference = new VariableReference(variable);
     }
     return reference;
 }
Exemple #17
0
 public static CatchBlock Catch(Type type, Variable target, Statement body)
 {
     return Catch(SourceSpan.None, SourceLocation.None, type, target, body);
 }
 /// <summary>
 /// Performs an assignment variable.leftField = right.rightField
 /// </summary>
 public static Statement Write(Variable variable, FieldInfo leftField, Variable right, FieldInfo rightField)
 {
     return Statement(AssignField(Read(variable), leftField, ReadField(Read(right), rightField)));
 }
 /// <summary>
 /// Performs an assignment variable = right.field
 /// </summary>
 public static Statement Write(Variable variable, Variable right, FieldInfo field)
 {
     return Statement(Assign(variable, ReadField(Read(right), field)));
 }
 /// <summary>
 /// Performs an assignment variable.field = value
 /// </summary>
 public static Statement Write(Variable variable, FieldInfo field, Variable value)
 {
     return Statement(AssignField(Read(variable), field, Read(value)));
 }
 /// <summary>
 /// Performs an assignment variable = value
 /// </summary>
 public static Statement Write(Variable variable, Expression value)
 {
     //return Statement(Assign(variable, value));
     return new WriteStatement(variable, value);
 }
 public static DeleteStatement Delete(SourceSpan span, Variable variable) {
     Contract.RequiresNotNull(variable, "variable");
     return new DeleteStatement(span, variable);
 }
Exemple #23
0
 private VariableReference Reference(Variable variable)
 {
     Debug.Assert(variable != null);
     return _stack.Peek().Reference(variable);
 }
 internal static object EvaluateAssign(CodeContext context, Variable var, object value) {
     switch (var.Kind) {
         case Variable.VariableKind.Temporary:
         case Variable.VariableKind.GeneratorTemporary:
             context.Scope.TemporaryStorage[var] = value;
             break;
         case Variable.VariableKind.Global:
             RuntimeHelpers.SetGlobalName(context, var.Name, value);
             break;
         default:
             RuntimeHelpers.SetName(context, var.Name, value);
             break;
     }
     return value;
 } 
 static bool CanAlias(Variable here, Variable there)
 {
     var sameblock = here.Block == there.Block;
     var assigned = Generator.assigns.ContainsKey(there.Name);
     return here.Type == there.Type && sameblock && !assigned && !there.Lift;
 }
 public VariableReference(Variable variable)
 {
     Debug.Assert(variable != null);
     _variable = variable;
 }
 static Expression MakePointerCall(Variable ptr, Type returntype, List<Type> paramtypes, Expression[] a)
 {
   Type sig = MakeDelegateType(returntype, paramtypes);
   var gm = FFIDelegate.MakeGenericMethod(sig);
   var expr = Ast.Call(gm, MakeConvertTo(Ast.Read(ptr), typeof(IntPtr)));
   return Ast.Call(expr, sig.GetMethod("Invoke"), a);
 }
Exemple #28
0
 public void Define(Variable variable)
 {
     int index;
     if (TryGetIndex(variable, out index)) {
         _bits.Set(index, true);      // is assigned
         _bits.Set(index + 1, true);  // cannot be unassigned
     }
 }
Exemple #29
0
 public void Delete(Variable variable)
 {
     int index;
     if (TryGetIndex(variable, out index)) {
         _bits.Set(index, false);     // is not initialized
         _bits.Set(index + 1, true);  // is assigned (to Uninitialized.instance)
     }
 }
 internal BoundAssignment(Variable /*!*/ variable, Expression /*!*/ value)
     : base(AstNodeType.BoundAssignment)
 {
     _variable = variable;
     _value = value;
     if (value.IsConstant(null))
     {
     #warning See if this is problematic, gets invoked by pfds tests
       //Debugger.Break();
     }
     _variable.AssumedValue = _variable.AssumedValue == null ? GetReference(value) : null;
 }