Пример #1
0
    public FunctionExpression(Scope scope, ReadIdentifierExpression name, List<ReadIdentifierExpression> parameters, BlockStatement statement)
    {
      Scope = scope;
      Name = name;
      Parameters = parameters;
      Statement = statement;
      SourceOffset = statement.SourceOffset;

      Use(Statement);
    }
Пример #2
0
        public FunctionExpression(Scope scope, ReadIdentifierExpression name, List <ReadIdentifierExpression> parameters, BlockStatement statement)
        {
            Scope        = scope;
            Name         = name;
            Parameters   = parameters;
            Statement    = statement;
            SourceOffset = statement.SourceOffset;

            Use(Statement);
        }
Пример #3
0
    public InlinedInvocation(
      JSFunctionMetadata targetFunctionMetadata
      , Scope scope
      , BlockStatement statement
      , ReadIdentifierExpression returnValue)
      : base(returnValue)
    {
      TargetFunctionMetadata = targetFunctionMetadata;
      Scope = scope;
      Statement = statement;

      Use(Statement);
    }
Пример #4
0
    public CatchClause(Scope scope, ReadIdentifierExpression identifier, Statement statement)
    {
      Debug.Assert(scope != null, "Catch clause must have its own scope");
      Debug.Assert(identifier != null, "Catch clause identifier cannot be null");
      Debug.Assert(identifier.Symbol != null, "Catch clause identifier must have a symbol");
      Debug.Assert(scope.GetSymbol(identifier.Symbol.Name) == identifier.Symbol, "Catch clause identifier must belong to its inner scope");

      Scope = scope;
      Identifier = identifier;
      Statement = statement;
      SourceOffset = statement.SourceOffset;

      Use(Identifier);
    }
Пример #5
0
        public CatchClause(Scope scope, ReadIdentifierExpression identifier, Statement statement)
        {
            Debug.Assert(scope != null, "Catch clause must have its own scope");
            Debug.Assert(identifier != null, "Catch clause identifier cannot be null");
            Debug.Assert(identifier.Symbol != null, "Catch clause identifier must have a symbol");
            Debug.Assert(scope.GetSymbol(identifier.Symbol.Name) == identifier.Symbol, "Catch clause identifier must belong to its inner scope");

            Scope        = scope;
            Identifier   = identifier;
            Statement    = statement;
            SourceOffset = statement.SourceOffset;

            Use(Identifier);
        }
      public override void Visit(ReadIdentifierExpression node)
      {
        var symbol = node.Symbol;
        var local = _localVars.Get(symbol);
        if (symbol.SymbolType == JSSymbol.SymbolTypes.Global && local == null)
        {
          var nodeProfile = _currProfiler.GetNodeProfile(node);
          if (_currFuncMetadata.EnableInlineCache
            && nodeProfile != null
            && nodeProfile.Map != null
            && nodeProfile.PD != null
            && nodeProfile.PD.IsDataDescriptor
            && !nodeProfile.PD.IsInherited)
          {
            PushLocation(node);
            var value = _localVars.PushTemporary(Types.DValue.TypeOf);
            _ilGen.Ldloc(_globalContext);
            _ilGen.Ldc_I4(symbol.FieldId);
            _ilGen.Ldloca(value);

            _ilGen.Ldc_I4(nodeProfile.Map.UniqueId);
            _ilGen.Ldc_I4(nodeProfile.PD.Index);
            _ilGen.Call(Types.Operations.Internals.GetFieldUsingIC);
            _ilGen.Ldloca(value);
            _result.ValueType = mdr.ValueTypes.DValueRef; 
            PopLocation();
          }
          else
          {
            base.Visit(node);
          }
        }
        else
        {
          base.Visit(node);
        }
      }
Пример #7
0
      public override void Visit(ReadIdentifierExpression node)
      {
        PushLocation(node);
        var symbol = node.Symbol;

        BeginICMethod(node);
        switch (symbol.SymbolType)
        {
          case JSSymbol.SymbolTypes.Local:
          case JSSymbol.SymbolTypes.HiddenLocal:
          case JSSymbol.SymbolTypes.Arguments:
            if (symbol.IsParameter)
            {
              if (_currFuncMetadata.Scope.HasArgumentsSymbol)
              {
                _ilGen.Call(Types.Operations.ICMethods.GetArguments);
                _ilGen.Ldfld(Types.DArray.Elements);
                _ilGen.Ldc_I4(symbol.ParameterIndex);
                _ilGen.Ldelema(Types.DValue.TypeOf);
              }
              else
              {
                Ldarg_Parameter(symbol.ParameterIndex);
              }
            }
            else
            {
              _ilGen.LoadValue(GetIndex(symbol));
            }
            StackPush();
            break;
          case JSSymbol.SymbolTypes.ClosedOnLocal:
          case JSSymbol.SymbolTypes.ParentLocal:
          case JSSymbol.SymbolTypes.Global:
          case JSSymbol.SymbolTypes.Unknown:
            _ilGen.Ldarg_CallFrame();
            _ilGen.Ldc_I4(_stackModel.StackPointer);
            _ilGen.Ldc_I4(GetIndex(symbol));
            _ilGen.Ldc_I4(symbol.FieldId);
            _ilGen.Call(Types.Operations.ICMethods.ReadFromContext);

            _result.ValueType = mdr.ValueTypes.DValueRef;
            _stackModel.Push(1);
            break;
          default:
            Trace.Fail("cannot process symbol type {0} in {1}", symbol.SymbolType, _currFuncMetadata.FullName);
            break;
        }
        EndICMethod();

        PopLocation();
      }
Пример #8
0
      public override void Visit(ReadIdentifierExpression node)
      {
        PushLocation(node);
        var symbol = node.Symbol;
        var local = _localVars.Get(symbol);
        if (symbol.SymbolType == JSSymbol.SymbolTypes.Global && local.LocalType == Types.PropertyDescriptor.TypeOf)
        {
          int profIndex = _currFuncMetadata.GetProfileIndex(node);
          _ilGen.Ldloc(local);
          _ilGen.Ldloc(_profiler);
          _ilGen.Ldc_I4(profIndex);
          _ilGen.LoadRuntimeInstance();
          _ilGen.Ldfld(Types.Runtime.GlobalContext);
          _ilGen.Call(Types.DObject.GetMap);          
          _ilGen.Call(Types.Operations.Internals.UpdateMapProfile);

          var value = _localVars.PushTemporary(Types.DValue.TypeOf);
          //_ilGen.Ldloc(local);
          _ilGen.LoadRuntimeInstance();
          _ilGen.Ldfld(Types.Runtime.GlobalContext);
          _ilGen.Ldloca(value);
          _ilGen.Call(Types.PropertyDescriptor.Get_DObject_DValueRef);

          _ilGen.Ldloca(value);
          _result.ValueType = mdr.ValueTypes.DValueRef;
          PopLocation();
        }
        else
        {
          base.Visit(node);
        }
      }
Пример #9
0
 public override void Visit(ReadIdentifierExpression node)
 {
   unfinishedClone = new ReadIdentifierExpression(GetRenamedSymbolOf(node.Symbol));
   Visit((Identifier)node);
 }
Пример #10
0
 public override void Visit(ReadIdentifierExpression node) { AssignToImplicitReturn(node); }
Пример #11
0
 public override void Visit(ReadIdentifierExpression node)
 {
   Visit((Identifier)node);
 }
Пример #12
0
 public override void Visit(ReadIdentifierExpression node)
 {
   PushLocation(node);
   var symbol = node.Symbol;
   switch (symbol.SymbolType)
   {
     case JSSymbol.SymbolTypes.Unknown:
     case JSSymbol.SymbolTypes.Local:
     case JSSymbol.SymbolTypes.ClosedOnLocal:
     case JSSymbol.SymbolTypes.ParentLocal:
     case JSSymbol.SymbolTypes.Global:
     case JSSymbol.SymbolTypes.Arguments:
       if (symbol.IsParameter && _currFuncMetadata.Scope.HasArgumentsSymbol)
       {
         _ilGen.Ldloc(_arguments);
         _ilGen.Ldfld(Types.DArray.Elements);
         _ilGen.Ldc_I4(symbol.ParameterIndex);
         _ilGen.Ldelema(Types.DValue.TypeOf);
         Call(Types.Operations.Stack.LoadDValue, 0, 1);
       }
       else if (symbol.IsParameter && symbol.SymbolType != JSSymbol.SymbolTypes.ClosedOnLocal)
       {
         Ldarg_CallFrame();
         _ilGen.Ldc_I4(symbol.ParameterIndex);
         Call(Types.Operations.Stack.LoadArg, 0, 1);
       }
       else
       {
         _ilGen.Ldloc(_context);
         _ilGen.Ldc_I4(symbol.FieldId);
         //_ilGen.Ldc_I4(symbol.AncestorDistance);
         Call(Types.Operations.Stack.LoadVariable, 0, 1);
       }
       break;
     //case JSSymbol.SymbolTypes.Undefined:
     //  Call(Types.Operations.Stack.LoadUndefined, 0, 1);
     //  break;
     case JSSymbol.SymbolTypes.HiddenLocal:
       _ilGen.Ldloca(_localVars.Get(symbol));
       Call(Types.Operations.Stack.LoadDValue, 0, 1);
       break;
     default:
       Trace.Fail(new JSSourceLocation(_currFuncMetadata, node), "Cannot load symbol {0}:{1}", symbol.Name, symbol.SymbolType);
       break;
   }
   PopLocation();
 }
Пример #13
0
 public override void Visit(ReadIdentifierExpression node)
 {
   throw new NotImplementedException();
 }
Пример #14
0
 public override void Visit(ReadIdentifierExpression node)
 {
   base.Visit(node);
   Debug.Assert(node.Symbol.Readers.Contains(node), "Reader {0} is not in the reader list of symbol {0}", node.Symbol);
   Debug.Assert(node.Writer == null || node.Writer.IsUsedBy(node), "Reader {0} mismatch with writer {1}", node, node.Writer);
 }
Пример #15
0
 internal static mdr.ValueTypes GetType(ReadIdentifierExpression expression) { return (expression.Writer != null) ? GetType(expression.Writer) : expression.Symbol.ValueType; }
Пример #16
0
 public override void Visit(ReadIdentifierExpression node) { base.Visit(node); node.ValueType = GetType(node); }
Пример #17
0
 public abstract void Visit(ReadIdentifierExpression node);
Пример #18
0
      public override void Visit(ReadIdentifierExpression node)
      {
        ///In this function we have to be careful specially when we are accessing a pointer. 
        ///We cannot just load address of something since we may have a situation like (x + x++), where the value
        ///of x is changed in later expressions. therefore, we have to always be careful to load the VALUE on the stack
        PushLocation(node);
        var symbol = node.Symbol;
        
        if (symbol.SymbolType == JSSymbol.SymbolTypes.OuterDuplicate)
          symbol = symbol.ResolvedSymbol;

        var local = _localVars.Get(symbol);
        var value = _localVars.PushTemporary(Types.DValue.TypeOf);

        if (local == null)
        {

          if (symbol.IsParameter)
          {
            if (_currFuncMetadata.Scope.HasArgumentsSymbol)
            {
              _ilGen.Ldloc(_arguments);
              _ilGen.Ldfld(Types.DArray.Elements);
              _ilGen.Ldc_I4(symbol.ParameterIndex);
              _ilGen.Ldelema(Types.DValue.TypeOf);
            }
            else
            {
              Ldarg_Parameter(symbol.ParameterIndex);
            }
            _ilGen.Ldobj(Types.DValue.TypeOf);
            _ilGen.Stloc(value);
          }

          else
          {
            Debug.Assert(symbol.SymbolType == JSSymbol.SymbolTypes.Unknown, "symbol {0}:{1} must have a variable", symbol.Name, symbol.SymbolType);
            var pd = _localVars.PushTemporary(Types.PropertyDescriptor.TypeOf);
            _ilGen.Ldloc(_context);
            _ilGen.Ldc_I4(symbol.FieldId);
            _ilGen.Call(Types.DObject.GetPropertyDescriptorByFieldId);
            _ilGen.Stloc(pd);

            _ilGen.Ldloc(pd);
            _ilGen.Ldloc(_context);
            _ilGen.Ldloca(value);
            _ilGen.Call(Types.PropertyDescriptor.Get_DObject_DValueRef);

            _localVars.PopTemporary(pd);
          }

          _ilGen.Ldloca(value);
          _result.ValueType = mdr.ValueTypes.DValueRef;
        }
        else
        {
          if (local.LocalType == Types.PropertyDescriptor.TypeOf)
          {
            _ilGen.Ldloc(local);
            if (symbol.SymbolType == JSSymbol.SymbolTypes.Global)
            {
              _ilGen.LoadRuntimeInstance();
              _ilGen.Ldfld(Types.Runtime.GlobalContext);
            }
            else
            {
              _ilGen.Ldloc(_context);
            }
            _ilGen.Ldloca(value);
            _ilGen.Call(Types.PropertyDescriptor.Get_DObject_DValueRef);

            _ilGen.Ldloca(value);
            _result.ValueType = mdr.ValueTypes.DValueRef;
          }
          else if (local.LocalType == Types.DValue.TypeOf)
          {

            _ilGen.Ldloc(local);
            _ilGen.Stloc(value);

            _ilGen.Ldloca(value);
            _result.ValueType = mdr.ValueTypes.DValueRef;
          }
          else if (local.LocalType == Types.DValue.RefOf)
          {

            _ilGen.Ldloc(local);
            _ilGen.Ldobj(Types.DValue.TypeOf);
            _ilGen.Stloc(value);

            _ilGen.Ldloca(value);
            _result.ValueType = mdr.ValueTypes.DValueRef;
          }
          else
          {
            _ilGen.Ldloc(local);
            _result.ValueType = Types.ValueTypeOf(local.LocalType);
            Debug.Assert(_result.ValueType < mdr.ValueTypes.DValue, "Invalid result type {0} for reading identifier {1}", _result.ValueType, symbol.Name);
          }
        }

        PopLocation();
      }
Пример #19
0
 public override void Visit(ReadIdentifierExpression node)
 {
     Visit((Identifier)node);
 }