コード例 #1
0
ファイル: PythonFunction.cs プロジェクト: tnachen/ironruby
        internal PythonFunction(CodeContext/*!*/ context, string/*!*/ name, Delegate target, string[] argNames, object[] defaults, FunctionAttributes flags) {
            Assert.NotNull(context, name);
            Assert.NotNull(context.Scope);

            _name = name;
            _context = context;
            _argNames = argNames ?? ArrayUtils.EmptyStrings;
            _defaults = defaults ?? ArrayUtils.EmptyObjects;
            _flags = flags;
            _nparams = _argNames.Length;
            Target = target;
            _name = name;

            if ((flags & FunctionAttributes.KeywordDictionary) != 0) {
                _nparams--;
            }

            if ((flags & FunctionAttributes.ArgumentList) != 0) {
                _nparams--;
            }

            Debug.Assert(_defaults.Length <= _nparams);

            object modName;
            if (context.GlobalScope.Dict.TryGetValue(Symbols.Name, out modName)) {
                _module = modName;
            }
            
            _compat = CalculatedCachedCompat();
            _code = new FunctionCode(this);
        }
コード例 #2
0
 internal SerializedScopeStatement(string name, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, string[] freeVars, string[] names, string[] cellVars, string[] varNames) {
     _name = name;
     _filename = path;
     _flags = flags;
     this.SetLoc(span.Start, span.End);
     _parameterNames = argNames;
     if (freeVars != null) {
         foreach (string freeVar in freeVars) {
             AddFreeVariable(new PythonVariable(freeVar, VariableKind.Local, this), false);
         }
     }
     if (names != null) {
         foreach (string globalName in names) {
             AddGlobalVariable(new PythonVariable(globalName, VariableKind.Global, this));
         }
     }
     if (varNames != null) {
         foreach (string variable in varNames) {
             EnsureVariable(variable);
         }
     }
     if (cellVars != null) {
         foreach (string cellVar in cellVars) {
             AddCellVariable(new PythonVariable(cellVar, VariableKind.Local, this));
         }
     }
 }
コード例 #3
0
ファイル: FunctionCode.cs プロジェクト: m4dc4p/ironruby
 internal FunctionCode(PythonFunction f, FunctionInfo funcInfo) {
     _func = f;
     _filename = funcInfo.Path;
     object fn;
     if (_filename == null && f.Context.GlobalScope.Dict.TryGetValue(Symbols.File, out fn) && fn is string) {
         _filename = (string)fn;
     }
     _lineNo = funcInfo.LineNumber;
     _flags = funcInfo.Flags;
     _lambda = funcInfo.Code;
     _shouldInterpret = funcInfo.ShouldInterpret;
     _emitDebugSymbols = funcInfo.EmitDebugSymbols;
 }
コード例 #4
0
 private static void SetFunctionAttribute(ref FunctionAttributes field, FunctionAttributes attribute, bool isSet)
 {
     if (isSet)
     {
         // make sure that attribute bits are set to 1
         field |= attribute;
     }
     else
     {
         // make sure that attribute bits are set to 0
         field ^= field & attribute;
     }
 }
コード例 #5
0
        public override void Read()
        {
            TypeDataReader r = CreateReader();

            ReturnValueType     = r.ReadIndexedTypeLazy();
            ContainingClassType = r.ReadIndexedTypeLazy();
            ThisPointerType     = r.ReadIndexedTypeLazy();
            CallingConvention   = r.ReadEnum <CallingConvention>();
            Attributes          = r.ReadFlagsEnum <FunctionAttributes>();
            NumberOfParameters  = r.ReadUInt16();
            ArgumentListType    = r.ReadIndexedTypeLazy();
            ThisAdjustor        = r.ReadUInt32();
        }
コード例 #6
0
        internal SerializedScopeStatement(string name, string[] parameterNames, int argCount, FunctionAttributes flags, int startIndex, int endIndex, string path, string[] freeVars, string[] names, string[] cellVars, string[] varNames)
        {
            _name     = name;
            _filename = path;
            _flags    = flags;
            SetLoc(null, startIndex, endIndex);
            _parameterNames = parameterNames;

            _argCount       = argCount;
            _kwOnlyArgCount = parameterNames.Length - argCount;
            if (flags.HasFlag(FunctionAttributes.ArgumentList))
            {
                _kwOnlyArgCount--;
            }
            if (flags.HasFlag(FunctionAttributes.KeywordDictionary))
            {
                _kwOnlyArgCount--;
            }

            if (freeVars != null)
            {
                foreach (string freeVar in freeVars)
                {
                    AddFreeVariable(new PythonVariable(freeVar, VariableKind.Local, this), false);
                }
            }
            if (names != null)
            {
                foreach (string globalName in names)
                {
                    AddGlobalVariable(new PythonVariable(globalName, VariableKind.Global, this));
                }
            }
            if (varNames != null)
            {
                foreach (string variable in varNames)
                {
                    EnsureVariable(variable);
                }
            }
            if (cellVars != null)
            {
                foreach (string cellVar in cellVars)
                {
                    AddCellVariable(new PythonVariable(cellVar, VariableKind.Local, this));
                }
            }
        }
コード例 #7
0
ファイル: FunctionCode.cs プロジェクト: techarch/ironruby
        /// <summary>
        /// Constructor used to create a FunctionCode for code that's been serialized to disk.  
        /// 
        /// Code constructed this way cannot be interpreted or debugged using sys.settrace/sys.setprofile.
        /// 
        /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
        /// </summary>
        internal FunctionCode(PythonContext context, Delegate code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, string[] freeVars, string[] names, string[] cellVars, string[] varNames, int localCount) {
            _name = name;
            _span = span;
            _initialDoc = documentation;
            _argNames = argNames;
            _flags = flags;
            _span = span;
            _filename = path;
            _freevars = StringArrayToTuple(freeVars);
            _names = StringArrayToTuple(names);
            _cellvars = StringArrayToTuple(cellVars);
            _varnames = StringArrayToTuple(varNames);
            _localCount = localCount;

            _normalDelegate = code;

            // need to take this lock to ensure sys.settrace/sys.setprofile is not actively changing
            lock (_CodeCreateAndUpdateDelegateLock) {
                Target = AddRecursionCheck(context, code);
            }

            RegisterFunctionCode(context);
        }
コード例 #8
0
 internal SerializedScopeStatement(string name, string[] argNames, FunctionAttributes flags, int startIndex, int endIndex, string path, string[] freeVars, string[] names, string[] cellVars, string[] varNames)
 {
     _name     = name;
     _filename = path;
     _flags    = flags;
     SetLoc(null, startIndex, endIndex);
     _parameterNames = argNames;
     if (freeVars != null)
     {
         foreach (string freeVar in freeVars)
         {
             AddFreeVariable(new PythonVariable(freeVar, VariableKind.Local, this), false);
         }
     }
     if (names != null)
     {
         foreach (string globalName in names)
         {
             AddGlobalVariable(new PythonVariable(globalName, VariableKind.Global, this));
         }
     }
     if (varNames != null)
     {
         foreach (string variable in varNames)
         {
             EnsureVariable(variable);
         }
     }
     if (cellVars != null)
     {
         foreach (string cellVar in cellVars)
         {
             AddCellVariable(new PythonVariable(cellVar, VariableKind.Local, this));
         }
     }
 }
コード例 #9
0
 public FunctionDefinition(SymbolId name, Expression[] parameters, Expression[] defaults, FunctionAttributes flags, Statement body, string sourceFile)
     : base(body)
 {
     this.name = name;
     this.parameters = parameters;
     this.defaults = defaults;
     this.flags = flags;
     this.decorators = null;
     this.filename = sourceFile;
 }
コード例 #10
0
ファイル: FunctionCode.cs プロジェクト: techarch/ironruby
        /// <summary>
        /// Constructor to create a FunctionCode at runtime.
        /// 
        /// Code constructed this way supports both being interpreted and debugged.  When necessary the code will
        /// be re-compiled or re-interpreted for that specific purpose.
        /// 
        /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
        /// 
        /// the initial delegate provided here should NOT be the actual code.  It should always be a delegate which updates our Target lazily.
        /// </summary>
        internal FunctionCode(PythonContext context, Delegate initialDelegate, LambdaExpression code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, bool isDebuggable, bool shouldInterpret, IList<string> freeVars, IList<string> names, IList<string> cellVars, IList<string> varNames, int localCount, Dictionary<int, Dictionary<int, bool>> loopLocations, Dictionary<int, bool> handlerLocations) {
            _lambda = code;
            _name = name;
            _span = span;
            _initialDoc = documentation;
            _argNames = argNames;
            _flags = flags;
            _span = span;
            _filename = path ?? "<string>";

            _shouldInterpret = shouldInterpret;
            _freevars = SymbolListToTuple(freeVars);
            _names = SymbolListToTuple(names);
            _cellvars = SymbolListToTuple(cellVars);
            _varnames = SymbolListToTuple(varNames);
            _localCount = localCount;

            _handlerLocations = handlerLocations;
            _loopAndFinallyLocations = loopLocations;

            _debuggable = isDebuggable;

            Target = initialDelegate;
            RegisterFunctionCode(context);
        }
コード例 #11
0
 public FunctionDefinition(SymbolId name, Expression[] parameters, Expression[] defaults, FunctionAttributes flags, string sourceFile)
     : this(name, parameters, defaults, flags, null, sourceFile)
 {
 }
コード例 #12
0
 private bool GetFunctionAttribute(FunctionAttributes attribute)
 {
     return(attribute == (attribute & _functionAttributes));
 }
コード例 #13
0
ファイル: FunctionCode.cs プロジェクト: joshholmes/ironruby
        /// <summary>
        /// Constructor to create a FunctionCode at runtime.
        /// 
        /// Code constructed this way supports both being interpreted and debugged.  When necessary the code will
        /// be re-compiled or re-interpreted for that specific purpose.
        /// 
        /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
        /// 
        /// the initial delegate provided here should NOT be the actual code.  It should always be a delegate which updates our Target lazily.
        /// </summary>
        internal FunctionCode(PythonContext context, Delegate initialDelegate, LambdaExpression code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, bool isDebuggable, bool shouldInterpret, IList<SymbolId> closureVars, Dictionary<int, Dictionary<int, bool>> loopLocations, Dictionary<int, bool> handlerLocations) {
            _lambda = code;
            _name = name;
            _span = span;
            _initialDoc = documentation;
            _argNames = argNames;
            _flags = flags;
            _span = span;
            _filename = path ?? "<string>";

            _shouldInterpret = shouldInterpret;
            if (closureVars != null) {
                _closureVars = PythonTuple.MakeTuple(SymbolTable.IdsToStrings(closureVars));
            } else {
                _closureVars = PythonTuple.EMPTY;
            }
            _handlerLocations = handlerLocations;
            _loopAndFinallyLocations = loopLocations;

            _debuggable = isDebuggable;

            Target = initialDelegate;
            RegisterFunctionCode(context);
        }
コード例 #14
0
ファイル: PythonFunction.cs プロジェクト: jcteague/ironruby
 public FunctionInfo(string name, object documentation, string[] argNames, FunctionAttributes flags, int lineNumber, string path, LambdaExpression code, bool shouldInterpret) {
     Name = name;
     Documentation = documentation;
     ArgNames = argNames;
     Flags = flags;
     LineNumber = lineNumber;
     Path = path;
     Code = code;
     ShouldInterpret = shouldInterpret;
 }
コード例 #15
0
ファイル: FunctionCode.cs プロジェクト: joshholmes/ironruby
        internal FunctionCode(ScriptCode code, CompileFlags compilerFlags, string fileName)
            : this(code) {

            if ((compilerFlags & CompileFlags.CO_FUTURE_DIVISION) != 0) {
                _flags |= FunctionAttributes.FutureDivision;
            }
            _filename = fileName;
            _closureVars = PythonTuple.EMPTY;
        }
コード例 #16
0
ファイル: Parser.cs プロジェクト: FabioNascimento/DICommander
        //varargslist: (fpdef ['=' test] ',')* ('*' NAME [',' '**' NAME] | '**' NAME) | fpdef ['=' test] (',' fpdef ['=' test])* [',']
        //fpdef: NAME | '(' fplist ')'
        //fplist: fpdef (',' fpdef)* [',']
        private void ParseVarArgsList(out Expression[] parameters, out Expression[] defaults, out FunctionAttributes flags, TokenKind terminator)
        {
            // parameters not doing * or ** today
            List<Expression> al = new List<Expression>();
            List<Expression> dl = new List<Expression>();
            Dictionary<SymbolId, SymbolId> names = new Dictionary<SymbolId, SymbolId>();
            bool needDefault = false;
            flags = FunctionAttributes.None;
            while (true) {
                if (MaybeEat(terminator)) break;

                if (MaybeEat(TokenKind.Multiply)) {
                    al.Add(ParseNameExpr(names));
                    flags |= FunctionAttributes.ArgumentList;
                    if (MaybeEat(TokenKind.Comma)) {
                        Eat(TokenKind.Power);
                        al.Add(ParseNameExpr(names));
                        flags |= FunctionAttributes.KeywordDictionary;
                    }
                    Eat(terminator);
                    break;
                } else if (MaybeEat(TokenKind.Power)) {
                    al.Add(ParseNameExpr(names));
                    flags |= FunctionAttributes.KeywordDictionary;
                    Eat(terminator);
                    break;
                }

                //
                //  Parsing defparameter:
                //
                //  defparameter ::=
                //      parameter ["=" expression]

                al.Add(ParseParameter(names));
                if (MaybeEat(TokenKind.Assign)) {
                    needDefault = true;
                    dl.Add(ParseTest());
                } else if (needDefault) {
                    ReportSyntaxError("default value must be specified here");
                }
                if (!MaybeEat(TokenKind.Comma)) {
                    Eat(terminator);
                    break;
                }
            }

            parameters = al.ToArray();
            defaults = dl.ToArray();
        }
コード例 #17
0
ファイル: FunctionCode.cs プロジェクト: joshholmes/ironruby
        /// <summary>
        /// Constructor used to create a FunctionCode for code that's been serialized to disk.  
        /// 
        /// Code constructed this way cannot be interpreted or debugged using sys.settrace/sys.setprofile.
        /// 
        /// Function codes created this way do support recursion enforcement and are therefore registered in the global function code registry.
        /// </summary>
        internal FunctionCode(PythonContext context, Delegate code, string name, string documentation, string[] argNames, FunctionAttributes flags, SourceSpan span, string path, string[] closureVars) {
            _name = name;
            _span = span;
            _initialDoc = documentation;
            _argNames = argNames;
            _flags = flags;
            _span = span;
            _filename = path;
            if (_closureVars != null) {
                _closureVars = PythonTuple.MakeTuple((object[])closureVars);
            } else {
                _closureVars = PythonTuple.EMPTY;
            }

            _normalDelegate = code;

            // need to take this lock to ensure sys.settrace/sys.setprofile is not actively changing
            lock (_CodeCreateAndUpdateDelegateLock) {
                Target = AddRecursionCheck(context, code);
            }

            RegisterFunctionCode(context);
        }
コード例 #18
0
ファイル: FunctionCode.cs プロジェクト: jcteague/ironruby
 internal void SetFlags(FunctionAttributes flags) {
     _flags = flags;
 }
コード例 #19
0
ファイル: FunctionCode.cs プロジェクト: m4dc4p/ironruby
        internal FunctionCode(ScriptCode code, CompileFlags compilerFlags)
            : this(code) {

            if ((compilerFlags & CompileFlags.CO_FUTURE_DIVISION) != 0)
                _flags |= FunctionAttributes.FutureDivision;
        }
コード例 #20
0
        public FunctionX(PythonModule globals, string name, CallTargetN target, string[] argNames, object[] defaults, FunctionAttributes flags)
            : base(globals, name, target, argNames, defaults)
        {
            this.flags = flags;
            nparams = argNames.Length;

            if ((flags & FunctionAttributes.KeywordDictionary) != 0) {
                extraArgs++;
                nparams--;
                kwDictPos = nparams;
            }

            if ((flags & FunctionAttributes.ArgumentList) != 0) {
                extraArgs++;
                nparams--;
                argListPos = nparams;
            }

            Debug.Assert(defaults.Length <= nparams);
        }