Exemple #1
0
 public static object Call(CodeContext/*!*/ context, TypeGroup/*!*/ self, params object[] args) {
     return PythonCalls.Call(
         context,
         DynamicHelpers.GetPythonTypeFromType(self.NonGenericType),
         args ?? ArrayUtils.EmptyObjects
     );
 }
Exemple #2
0
 /// <summary>
 /// Convenience function for users to call directly
 /// </summary>
 public object GetValue(CodeContext context, object instance) {
     object value;
     if (TryGetValue(context, instance, DynamicHelpers.GetPythonType(instance), out value)) {
         return value;
     }
     throw new InvalidOperationException("cannot get field");
 }
 public static CodeContext CreateCodeContext(Type[] extensionTypes)
 {
     DefaultLanguageContext dlc = new DefaultLanguageContext();
     CodeContext cc = new CodeContext(new Scope(), dlc, new ModuleContext(null));
     dlc._binder = new DefaultActionBinder(cc, extensionTypes);
     return cc;
 }
Exemple #4
0
 internal TraceBackFrame(CodeContext context, TotemDictionary globals, object locals, FunctionCode code)
 {
     _globals = globals;
     _locals = locals;
     _code = code;
     _context = context;
 }
 public PythonTypeChangedEventArgs(CodeContext context, SymbolId changed, ChangeType type, object previous, object newValue) {
     _context = context;
     _changed = changed;
     _type = type;
     _previous = previous;
     _newValue = newValue;
 }
 static InvariantContext()
 {
     Instance = new InvariantContext();
     ModuleContext moduleContext = new ModuleContext(null);
     moduleContext.ShowCls = true;
     CodeContext = new CodeContext(new Scope(null), Instance, moduleContext);
 }
 public DynamicStackFrame(CodeContext context, MethodBase method, string funcName, string filename, int line) {
     _context = context;
     _funcName = funcName;
     _filename = filename;
     _lineNo = line;
     _method = method;
 }
Exemple #8
0
 protected static object CheckCodeContext(CodeContext cc)
 {
   if (cc != null && cc.Scope.Parent.Parent == null)
   {
     return null;
   }
   return cc;
 }
Exemple #9
0
 public static object Call(CodeContext/*!*/ context, TypeGroup/*!*/ self, [ParamDictionary]PythonDictionary kwArgs, params object[] args) {
     return PythonCalls.CallWithKeywordArgs(
         context, 
         DynamicHelpers.GetPythonTypeFromType(self.NonGenericType),
         args ?? ArrayUtils.EmptyObjects,
         kwArgs ?? new PythonDictionary()
     );
 }
 internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
     if (instance != null || owner == TypeCache.Null) {
         CheckSelf(context, instance);
         value = UncheckedGetAttribute(instance);
         return true;
     }
     value = this;
     return true;
 }
 public override object Build(CodeContext context, object[] args, object[] parameters, object ret)
 {
     if (_returnArgs.Count == 1) {
         return GetValue(args, ret, _returnArgs[0]);
     } else {
         object[] retValues = new object[_returnArgs.Count];
         int rIndex = 0;
         foreach (int index in _returnArgs) {
             retValues[rIndex++] = GetValue(args, ret, index);
         }
         return _binder.GetByRefArray(retValues);
     }
 }
        internal static void Initialize(IronSchemeLanguageProvider ironSchemeLanguageProvider)
        {
            lp = ironSchemeLanguageProvider;
              se = lp.GetEngine() as IronSchemeScriptEngine;

              scriptmodule = ScriptDomainManager.CurrentManager.Host.DefaultModule as ScriptModule;

              ModuleContext mc = new ModuleContext(scriptmodule);

              mc.CompilerContext = new CompilerContext(SourceUnit.CreateSnippet(se, ""));

              cc = new CodeContext(scriptmodule.Scope, se.GetLanguageContext(), mc);

              binder = new IronScheme.Actions.IronSchemeActionBinder(cc);

              Generator.initme = true;
        }
 public static void AddGenerators(CodeContext cc, Assembly assembly)
 {
   foreach (Type t in assembly.GetExportedTypes())
   {
     if (Attribute.IsDefined(t, typeof(GeneratorAttribute)))
     {
       IGenerator g = Activator.CreateInstance(t) as IGenerator;
       
       foreach (GeneratorAttribute ga in t.GetCustomAttributes(typeof(GeneratorAttribute), false))
       {
         string name = ga.Name;
         object s = SymbolTable.StringToObject(name);
         cc.Scope.SetName((SymbolId)s, g);
       }
     }
   }
 }
        internal override bool TrySetValue(CodeContext context, object instance, PythonType owner, object value) {
            if (Setter.Length == 0) {
                return false;
            }

            if (instance == null) {
                foreach (MethodInfo mi in Setter) {
                    if(mi.IsStatic && DeclaringType != owner.UnderlyingSystemType) {
                        return false;
                    } else if (mi.IsProtected()) {
                        throw PythonOps.TypeErrorForProtectedMember(owner.UnderlyingSystemType, _info.Name);
                    }
                }
            } else if (instance != null) {
                foreach (MethodInfo mi in Setter) {
                    if (mi.IsStatic) {
                        return false;
                    }
                }
            }

            return CallSetter(context, PythonContext.GetContext(context).GetGenericCallSiteStorage(), instance, ArrayUtils.EmptyObjects, value);
        }
        internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) {
            PerfTrack.NoteEvent(PerfTrack.Categories.Properties, this);

            value = CallGetter(context, owner, PythonContext.GetContext(context).GetGenericCallSiteStorage0(), instance);
            return true;
        }
 public string/*!*/ __repr__(CodeContext/*!*/ context) {
     return string.Format("<property# {0} on {1}>",
         __name__,
         DynamicHelpers.GetPythonTypeFromType(DeclaringType).Name);
 }
 public void __set__(CodeContext context, object instance, object value) {
     // TODO: Throw?  currently we have a test that verifies we never throw when this is called directly.
     TrySetValue(context, instance, DynamicHelpers.GetPythonType(instance), value);
 }
 public void SetValue(CodeContext context, object instance, object value) {
     if (!TrySetValue(context, instance, DynamicHelpers.GetPythonType(instance), value)) {
         throw new InvalidOperationException("cannot set property");
     }
 }
 public DefaultActionBinder(CodeContext context, Type[] extensionTypes)
     : base(context)
 {
     this._extensionTypes = extensionTypes;
 }
        public IList<object> GetCustomMemberNames(CodeContext context) {
            List<object> ret;
            if (!context.ModuleContext.ShowCls) {
                ret = new List<object>();
                foreach (KeyValuePair<object, object> kvp in Scope.GetAllItems(context.LanguageContext)) {                    
                    if(kvp.Value != Uninitialized.Instance) {
                        if (kvp.Key is SymbolId) {
                            ret.Add(SymbolTable.IdToString((SymbolId)kvp.Key));
                        } else {
                            ret.Add(kvp.Key);
                        }
                    }
                }
            } else {
                ret = new List<object>(Scope.GetAllKeys(context.LanguageContext));
            }            

            return ret;
        }
        private object CallGetter(CodeContext context, PythonType owner, SiteLocalStorage<CallSite<Func<CallSite, CodeContext, object, object>>> storage, object instance) {
            if (NeedToReturnProperty(instance, Getter)) {
                return this;
            }

            if (Getter.Length == 0) {
                throw new MissingMemberException("unreadable property");
            }

            if (owner == null) {
                owner = DynamicHelpers.GetPythonType(instance);
            }

            // this matches the logic in the default binder when it does a property get.  We 
            // need to duplicate it here to be consistent for all gets.
            MethodInfo[] members = Getter;

            Type type = owner.UnderlyingSystemType;
            if (Getter.Length > 1) {
                // if we were given multiple members pick the member closest to the type...                
                Type bestMemberDeclaringType = Getter[0].DeclaringType;
                MethodInfo bestMember = Getter[0];

                for (int i = 1; i < Getter.Length; i++) {
                    MethodInfo mt = Getter[i];
                    if (!IsApplicableForType(type, mt)) {
                        continue;
                    }

                    if (Getter[i].DeclaringType.IsSubclassOf(bestMemberDeclaringType) ||
                        !IsApplicableForType(type, bestMember)) {
                        bestMember = Getter[i];
                        bestMemberDeclaringType = Getter[i].DeclaringType;
                    }
                }
                members = new MethodInfo[] { bestMember };
            }

            BuiltinFunction target = PythonTypeOps.GetBuiltinFunction(type, __name__, members);

            return target.Call0(context, storage, instance);
        }
 public void SetVariable(CodeContext context, SymbolId name, object value)
 {
     _manager.SetVariable(context, name, value);
 }
 public object GetVariable(CodeContext context, SymbolId name)
 {
     return _manager.GetVariable(context, name);
 }
Exemple #24
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 object GetCustomMember(CodeContext context, string name) {
     object value;
     if (Scope.TryGetName(context.LanguageContext, SymbolTable.StringToId(name), out value)) {
         if (value != Uninitialized.Instance) {
             return value;
         }
     }
     return null;
 }
 internal override bool TryDeleteValue(CodeContext context, object instance, PythonType owner) {
     __delete__(instance);
     return true;
 }
        public bool DeleteMember(CodeContext context, string name) {
            if (Scope.TryRemoveName(context.LanguageContext, SymbolTable.StringToId(name))) {
                OnModuleChange(new ModuleChangeEventArgs(SymbolTable.StringToId(name), ModuleChangeType.Delete));

                return true;
            } 

            return false;
        }
 internal override bool IsSetDescriptor(CodeContext context, PythonType owner) {
     return Setter.Length != 0;
 }
    protected override IList<object> Ops_GetAttrNames(CodeContext context, object obj)
    {
      Callable c = context.Scope.LookupName(SymbolTable.StringToId("int-env-syms")) as Callable;
      Cons ids = c.Call() as Cons;

      List<object> names = new List<object>(ids);

      names.Sort(delegate(object o, object p) { return o.ToString().CompareTo(p.ToString()); });

      return names;
    }
        private List<Scope> GenerateScriptScopes()
        {
            List<Scope> scopes = new List<Scope>(_scriptCodes.Length);
            ScriptModule sm = ScriptDomainManager.CurrentManager.Host.DefaultModule as ScriptModule;
            for (int i = 0; i < _scriptCodes.Length; i++) {
                ScriptCode scriptCode = _scriptCodes[i];

                // Force creation of names used in other script codes into all optimized dictionaries
                ScopeAllocator allocator = _allocators[scriptCode.LanguageContext];
                IAttributesCollection iac = CreateLanguageDictionary(scriptCode.LanguageContext, allocator);
                Scope scope = new Scope(sm.Scope, iac);

                // module context is filled later:
                CodeContext codeContext = new CodeContext(scope, scriptCode.LanguageContext);

                IModuleDictionaryInitialization ici = iac as IModuleDictionaryInitialization;
                if (ici != null) {
                    ici.InitializeModuleDictionary(codeContext);
                }

                scopes.Add(scope);
                _codeContexts.Add(codeContext);
            }
            return scopes;
        }