コード例 #1
0
ファイル: BoundTreeVisitor.cs プロジェクト: pvginkel/Jint2
 public virtual void VisitCreateFunction(BoundCreateFunction node)
 {
     DefaultVisit(node);
 }
コード例 #2
0
            public override void VisitCreateFunction(BoundCreateFunction node)
            {
                // It's the responsibility of the phase to handle functions.
                // Definite assignment also applies to closed over variables.
                // The only problem is that we don't know when the function is
                // called, so we don't know for sure when the variable is
                // definitely assigned. However, we do know it isn't before the
                // function reference is created, so we do it here.

                Perform(node.Function.Body, _branch);
            }
コード例 #3
0
ファイル: TypeMarkerPhase.cs プロジェクト: pvginkel/Jint2
 public override void VisitCreateFunction(BoundCreateFunction node)
 {
     node.Function.Body.Accept(this);
 }
コード例 #4
0
ファイル: SquelchPhase.cs プロジェクト: pvginkel/Jint2
            public override BoundNode VisitCreateFunction(BoundCreateFunction node)
            {
                // It's the responsibility of the phases to apply the actions
                // to nested functions.

                return node.Update(
                    node.Function.Update(
                        node.Function.Name,
                        node.Function.Parameters,
                        Perform(node.Function.Body),
                        node.Function.Location
                    )
                );
            }
コード例 #5
0
ファイル: CodeGenerator.cs プロジェクト: pvginkel/Jint2
        private BoundValueType EmitCreateFunction(BoundCreateFunction node)
        {
            ITypeBuilder typeBuilder = _scriptBuilder;
            if (_scope.Closure != null)
                typeBuilder = _scope.Closure.Builder;

            var location = node.Function.Location;
            string sourceCode = null;
            if (location != null)
                sourceCode = location.GetSourceCode();

            var function = DeclareFunction(node.Function, typeBuilder, sourceCode);

            _scope.EmitLoad(SpecialLocal.Runtime);

            IL.EmitConstant(node.Function.Name ?? String.Empty);

            // Create a delegate to the method. First load the instance reference.
            if (_scope.Closure == null)
                IL.Emit(OpCodes.Ldnull);
            else
                _scope.EmitLoadClosure(_scope.Closure);
            // Load the function.
            IL.Emit(OpCodes.Ldftn, function.Method);
            // Construct the delegate.
            IL.Emit(OpCodes.Newobj, _functionConstructor);

            IL.EmitConstant(node.Function.Parameters.Count);

            IL.EmitCall(_runtimeCreateFunction);

            return BoundValueType.Object;
        }