示例#1
0
文件: Program.cs 项目: reshadi2/mcjs
 public override bool Replace(Node oldValue, Node newValue)
 {
   return
     Replace(Expression, oldValue, newValue, n => Expression = n)
     ||
     base.Replace(oldValue, newValue);
 }
示例#2
0
文件: Program.cs 项目: reshadi2/mcjs
    public Program(FunctionExpression expression)
    {
      Expression = expression;
      SourceOffset = expression.SourceOffset;

      Use(Expression);
    }
    public FunctionDeclarationStatement(FunctionExpression expression, WriteIdentifierExpression implementation)
    {
      Expression = expression;
      Implementation = implementation;
      SourceOffset = expression.SourceOffset;

      //We don't need to Use the functionExpression, the real user of it is the implementation
      //Use(Expression);
      Debug.Assert(implementation.Value == expression && expression.User == implementation, "Invalid IR");

      Use(Implementation);
    }
        public FunctionDeclarationStatement(FunctionExpression expression, WriteIdentifierExpression implementation)
        {
            Expression     = expression;
            Implementation = implementation;
            SourceOffset   = expression.SourceOffset;

            //We don't need to Use the functionExpression, the real user of it is the implementation
            //Use(Expression);
            Debug.Assert(implementation.Value == expression && expression.User == implementation, "Invalid IR");

            Use(Implementation);
        }
示例#5
0
        public FunctionExpression MakeFunctionExpression(Scope scope, IIdentifier name, IIdentifierList parameters,
                                                         IStatement statement, Scope newScope)
        {
            var namedParams = parameters as List <ReadIdentifierExpression>;

            Debug.Assert(namedParams.Count == 0 || newScope.IsFunction, "parameters must be declared in a function scope");
            for (var i = 0; i < namedParams.Count; ++i)
            {
                var symbol = namedParams[i].Symbol;
                Debug.Assert(newScope.GetSymbol(symbol.Name) == symbol && symbol.ContainerScope == newScope, "Invalid situation, parameter symbol is not in the newScope");
                symbol.SymbolType     = JSSymbol.SymbolTypes.Local; //already know symbol.ContainerScope.IsFunction, so no need for hoisting
                symbol.ParameterIndex = i;
            }

            var funcName = name as ReadIdentifierExpression;

            if (newScope.IsFunctionDeclaration)
            {
                Debug.Assert(funcName != null, "the function declaration must have a name");
                Debug.Assert(scope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == scope, "Name of function declaration must exist in the outer scope");
                DeclareHoistedLocal(funcName.Symbol); //This is defined now in its scope!
            }
            else if (newScope.IsProgram)
            {
                Debug.Assert(funcName == null, "program scope cannot have a name!");
            }
            else
            {
                Debug.Assert(newScope.IsFunction == true, "The FunctionExpression scope is not properly marked");
                if (funcName != null)
                {
                    Debug.Assert(newScope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == newScope, "Name of function expression must exist in its own scope");
                    funcName.Symbol.SymbolType = JSSymbol.SymbolTypes.Local; //This is defined now in its scope, & we already know funcName.Symbol.ContainerScope.IsFunction, so no need for hoisting
                }
            }

            var func = new FunctionExpression(newScope, funcName, namedParams, (BlockStatement)statement);

            var metadata = new JSFunctionMetadata(func);

            func.Metadata = metadata;
            if (scope != null)
            {
                scope.AddSubFunction(metadata);
            }

            return(func);
        }
示例#6
0
 public override void Visit(FunctionExpression node) { base.Visit(node); node.ValueType = GetType(node); }
示例#7
0
 internal static mdr.ValueTypes GetType(FunctionExpression expression) { return mdr.ValueTypes.Function; }
      public override void Visit(FunctionExpression node)
      {
        PushLocation(node);

        BeginICMethod(node);
        Ldarg_CallFrame();
        _ilGen.Ldc_I4(_stackModel.StackPointer);
        _ilGen.Ldc_I4(node.Metadata.FuncDefinitionIndex);
        _ilGen.Call(Types.Operations.ICMethods.CreateFunction);
        EndICMethod();

        _result.ValueType = mdr.ValueTypes.Function;
        _stackModel.Push(1);

        PopLocation();
      }
示例#9
0
 public override void Visit(FunctionExpression expression)
 {
   Trace.Fail("Invalid situation, should not be here");
 }
示例#10
0
    public FunctionExpression MakeFunctionExpression(Scope scope, IIdentifier name, IIdentifierList parameters,
                                                     IStatement statement, Scope newScope)
    {
      var namedParams = parameters as List<ReadIdentifierExpression>;
      Debug.Assert(namedParams.Count == 0 || newScope.IsFunction, "parameters must be declared in a function scope");
      for (var i = 0; i < namedParams.Count; ++i)
      {
        var symbol = namedParams[i].Symbol;
        Debug.Assert(newScope.GetSymbol(symbol.Name) == symbol && symbol.ContainerScope == newScope, "Invalid situation, parameter symbol is not in the newScope");
        symbol.SymbolType = JSSymbol.SymbolTypes.Local; //already know symbol.ContainerScope.IsFunction, so no need for hoisting
        symbol.ParameterIndex = i;
      }

      var funcName = name as ReadIdentifierExpression;
      if (newScope.IsFunctionDeclaration)
      {
        Debug.Assert(funcName != null, "the function declaration must have a name");
        Debug.Assert(scope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == scope, "Name of function declaration must exist in the outer scope");
        DeclareHoistedLocal(funcName.Symbol); //This is defined now in its scope!
      }
      else if (newScope.IsProgram)
      {
        Debug.Assert(funcName == null, "program scope cannot have a name!");
      }
      else
      {
        Debug.Assert(newScope.IsFunction == true, "The FunctionExpression scope is not properly marked");
        if (funcName != null)
        {
          Debug.Assert(newScope.GetSymbol(funcName.Symbol.Name) == funcName.Symbol && funcName.Symbol.ContainerScope == newScope, "Name of function expression must exist in its own scope");
          funcName.Symbol.SymbolType = JSSymbol.SymbolTypes.Local; //This is defined now in its scope, & we already know funcName.Symbol.ContainerScope.IsFunction, so no need for hoisting
        }
      }

      var func = new FunctionExpression(newScope, funcName, namedParams, (BlockStatement)statement);

      var metadata = new JSFunctionMetadata(func);
      func.Metadata = metadata;
      if (scope != null) scope.AddSubFunction(metadata);

      return func;
    }
示例#11
0
 private IProgram MakeProgram(FunctionExpression func)
 {
   func.Metadata.Scope.IsProgram = true;
   var n = new Program(func);
   return n;
 }
示例#12
0
 public abstract void Visit(FunctionExpression node);
示例#13
0
      public override void Visit(FunctionExpression node)
      {
        PushLocation(node);
        var impIndex = node.Metadata.FuncDefinitionIndex;
        Ldarg_CallFrame();
        _ilGen.Ldc_I4(impIndex);
        _ilGen.Ldloc(_context);
        Call(Types.Operations.Stack.CreateFunction, 0, 1);

        PopLocation();
      }
示例#14
0
 public override void Visit(FunctionExpression node) { AssignToImplicitReturn(node); }
示例#15
0
 public override void Visit(FunctionExpression node) { Visit((Expression)node); }
示例#16
0
 public override void Visit(FunctionExpression node)
 {
     Visit((Expression)node);
 }
示例#17
0
      public override void Visit(FunctionExpression node)
      {
        PushLocation(node);

        var impIndex = node.Metadata.FuncDefinitionIndex;
        Ldarg_CallFrame();
        _ilGen.Ldfld(Types.CallFrame.Function);
        _ilGen.Call(Types.DFunction.GetMetadata);
        _ilGen.Castclass(Types.JSFunctionMetadata.TypeOf);
        _ilGen.Ldc_I4(impIndex);
        _ilGen.Call(Types.JSFunctionMetadata.GetSubFunction);
        _ilGen.Ldloc(_context);
        _ilGen.Newobj(Types.DFunction.CONSTRUCTOR_DFunctionMetadata_DObject);
        _result.ValueType = mdr.ValueTypes.Function;

        PopLocation();
      }
示例#18
0
 public JSFunctionMetadata(FunctionExpression functionIR, JSFunctionMetadata parent = null)
   : base()
 {
   Execute = FirstExecute;
   SubFunctions = new List<JSFunctionMetadata>();
   FunctionIR = functionIR;
   FunctionIR.Scope.SetContainer(this);
   ParentFunction = parent;
   GuardProfileSize = 0;
   MapProfileSize = 0;
   CallProfileSize = 0;
 }