Exemplo n.º 1
0
        public Pool GetPool(Symbol name)
        {
            PoolBinding binding = this.Runtime.GlobalScope.GetPoolBinding(name);

            if (binding == null)
            {
                return(null);
            }
            return(binding.Value);
        }
Exemplo n.º 2
0
        protected override InitializerCompiler GetInitializerCompiler(NativeLiteralEncodingStrategy literalEncodingStrategy, NativeDynamicCallStrategy dynamicCallStrategy, NativeDiscreteBindingEncodingStrategy discreteBindingEncodingStrategy)
        {
            PoolBinding poolBinding = this.Compiler.Parameters.Runtime.GlobalScope.GetPoolBinding(this.Initializer.PoolName);

            if ((poolBinding == null) || (poolBinding.Value == null))
            {
                throw new Exception(String.Format("Cannot find pool named {0}", this.Initializer.PoolName)); // May be better exception type
            }
            BindingScope globalScope   = BindingScope.ForPoolInitializer(poolBinding.Value, this.Compiler.Parameters.Runtime.GlobalScope);
            BindingScope reservedScope = ReservedScope.ForPoolInitializer();

            return(this.GetInitializerCompiler(globalScope, reservedScope, literalEncodingStrategy, dynamicCallStrategy, discreteBindingEncodingStrategy));
        }
        protected override Expression <Func <object, ExecutionContext, object> > Compile(SmalltalkRuntime runtime, SmalltalkNameScope globalScope)
        {
            PoolBinding poolBinding = globalScope.GetPoolBinding(this.PoolName);

            if ((poolBinding == null) || (poolBinding.Value == null))
            {
                throw new RuntimeCodeGenerationException(String.Format("Cannot find pool named {0}", this.PoolName)); // May be better exception type
            }
            return(this.Compile(runtime,
                                BindingScope.ForPoolInitializer(poolBinding.Value, globalScope),
                                ReservedScope.ForPoolInitializer(),
                                String.Format("{0} initializerFor: {1}", this.PoolName, this.Binding.Name.Value)));
        }
Exemplo n.º 4
0
        public static void CreatePool(SmalltalkRuntime runtime, PoolBinding binding)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            binding.SetValue(new Pool(runtime, binding.Name));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get the Smalltalk shared pool with the given name.
        /// </summary>
        /// <param name="name">Shared pool name.</param>
        /// <returns>The Smalltalk shared pool with the given name or null if none found.</returns>
        public Pool GetPool(string name)
        {
            PoolBinding binding = this.GlobalScope.GetPoolBinding(name);

            if (binding != null)
            {
                return(binding.Value);
            }
            else
            {
                return(null);
            }
        }
Exemplo n.º 6
0
        public static CompiledInitializer AddPoolInitializer(SmalltalkRuntime runtime, SmalltalkNameScope scope, Type delegateType, string delegateName, string poolName, string poolItemName)
        {
            PoolBinding poolBinding = scope.GetPoolBinding(poolName);

            if ((poolBinding == null) || (poolBinding.Value == null))
            {
                throw new ArgumentException(String.Format("Pool named {0} does not exist.", poolName));
            }
            PoolVariableOrConstantBinding binding = poolBinding.Value[poolItemName];

            if (binding == null)
            {
                throw new ArgumentException(String.Format("Pool variable or constant named {0} does not exist in pool {1}.", poolItemName, poolName));
            }
            return(NativeLoadHelper.AddInitializer(scope, InitializerType.PoolVariableInitializer, binding, delegateType, delegateName));
        }
Exemplo n.º 7
0
        public CompiledInitializer CreateInitializer(InitializerDefinition definition, IDefinitionInstallerContext installer)
        {
            PoolBinding poolBinding = installer.GetPoolBinding(this.PoolName);

            if ((poolBinding == null) || (poolBinding.Value == null))
            {
                return(null);
            }
            PoolVariableOrConstantBinding binding = poolBinding.Value[this.PoolItemName];

            if (binding == null)
            {
                return(null);
            }
            return(new RuntimePoolItemInitializer(this.ParseTree, new DebugInfoService(this.SourceCodeService), binding, this.PoolName));
        }
        public static string GetMoniker(PoolBinding poolBinding, PoolVariableOrConstantBinding binding)
        {
            if (poolBinding == null)
            {
                throw new ArgumentNullException("poolBinding");
            }
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }

            return(DiscreteBindingCallSiteBinderBase.GetMoniker(
                       DiscreteBindingCallSiteBinderBase.PoolItemPrefix,
                       poolBinding.Name.Value,
                       binding.Name.Value));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Create a binding object (association) for the pool variable in the pool that owns it.
        /// </summary>
        /// <param name="installer">Context within which the binding is to be created.</param>
        /// <returns>Returns true if successful, otherwise false.</returns>
        protected internal override bool CreatePoolVariableBinding(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }
            // 1. Check if the name is not complete garbage.
            if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(this.VariableName.Value))
            {
                return(installer.ReportError(this.VariableName, InstallerErrors.PoolVarInvalidName));
            }
            // 2. Get the pool dictionary.
            PoolBinding poolBinding = installer.GetPoolBinding(this.PoolName.Value);

            // 3. Check that such a binding exists
            if (poolBinding == null)
            {
                return(installer.ReportError(this.PoolName, InstallerErrors.PoolInvalidPoolName));
            }
            if (poolBinding.Value == null)
            {
                throw new InvalidOperationException("Should have been set in PoolDefinition.CreataGlobalObject().");
            }
            // 4. Check for reserved keywords
            if (IronSmalltalk.Common.GlobalConstants.ReservedIdentifiers.Contains(this.VariableName.Value))
            {
                return(installer.ReportError(this.VariableName, InstallerErrors.PoolVarReservedName));
            }
            // 5. Check that no duplicate exists.
            Symbol varName = installer.Runtime.GetSymbol(this.VariableName.Value);
            PoolVariableOrConstantBinding existing;

            poolBinding.Value.TryGetValue(varName, out existing);
            if (existing != null)
            {
                return(installer.ReportError(this.VariableName, InstallerErrors.PoolItemNameNotUnique));
            }
            // 6. Create the binding
            poolBinding.Value.Add(new PoolVariableBinding(varName));
            return(true);
        }
        protected internal override bool ValidateInitializer(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }
            // 1. Check if the name is not complete garbage.
            if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(this.VariableName.Value))
            {
                return(installer.ReportError(this.VariableName, InstallerErrors.PoolVarInvalidName));
            }
            // 2. Get the pool dictionary.
            PoolBinding poolBinding = installer.GetPoolBinding(this.PoolName.Value);

            // 3. Check that such a binding exists
            if (poolBinding == null)
            {
                return(installer.ReportError(this.PoolName, InstallerErrors.PoolInvalidPoolName));
            }
            if (poolBinding.Value == null)
            {
                throw new InvalidOperationException("Should have been set in PoolDefinition.CreataGlobalObject().");
            }

            Symbol varName = installer.Runtime.GetSymbol(this.VariableName.Value);
            PoolVariableOrConstantBinding poolItemBinding;

            poolBinding.Value.TryGetValue(varName, out poolItemBinding);
            if (poolItemBinding == null)
            {
                return(installer.ReportError(this.VariableName, InstallerErrors.PoolVarInvalidName));
            }

            if (poolItemBinding.IsConstantBinding && poolItemBinding.HasBeenSet)
            {
                return(installer.ReportError(this.VariableName, InstallerErrors.PoolItemIsConstant));
            }

            return(this.Factory.ValidatePoolVariableInitializer(this, poolBinding.Value, installer,
                                                                new IntermediateCodeValidationErrorSink(this.MethodSourceCodeService, installer)));
        }
Exemplo n.º 11
0
        public static PoolBinding AddPoolBinding(SmalltalkRuntime runtime, SmalltalkNameScope scope, string name)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            Symbol symbol = runtime.GetSymbol(name);

            PoolBinding binding = new PoolBinding(symbol);

            scope.Pools.Add(binding);
            return(binding);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Create the pool object (and sets the value of the binding).
        /// </summary>
        /// <param name="installer">Context within which the pool is to be created.</param>
        /// <returns>Returns true if successful, otherwise false.</returns>
        protected internal override bool CreateGlobalObject(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }
            // 1. Get the binding to the global
            Symbol      name    = installer.Runtime.GetSymbol(this.Name.Value);
            PoolBinding binding = installer.GetLocalPoolBinding(name);

            // 2. Check consistency that we didn't mess up in the implementation.
            if (binding == null)
            {
                throw new InvalidOperationException("Should have found a binding, because CreateGlobalBinding() created it!");
            }
            if (binding.Value != null)
            {
                throw new InvalidOperationException("Should be an empty binding, because CreateGlobalBinding() complained if one already existed!");
            }
            // 3. Create the pool object.
            binding.SetValue(new Pool(installer.Runtime, name));
            return(true);
        }
 void IDefinitionInstallerContext.AddPoolBinding(PoolBinding binding)
 {
     this.NameScope.Pools.Add(binding);
 }
Exemplo n.º 14
0
        /// <summary>
        /// Create the class object (and sets the value of the binding).
        /// </summary>
        /// <param name="installer">Context within which the class is to be created.</param>
        /// <returns>Returns true if successful, otherwise false.</returns>
        protected internal override bool CreateGlobalObject(IDefinitionInstallerContext installer)
        {
            if (installer == null)
            {
                throw new ArgumentNullException();
            }
            // 1. Get the binding to the global
            Symbol       name    = installer.Runtime.GetSymbol(this.Name.Value);
            ClassBinding binding = installer.GetLocalClassBinding(name);

            // 2. Check consistency that we didn't mess up in the implementation.
            if (binding == null)
            {
                throw new InvalidOperationException("Should have found a binding, because CreateGlobalBinding() created it!");
            }
            if (binding.Value != null)
            {
                throw new InvalidOperationException("Should be an empty binding, because CreateGlobalBinding() complained if one already existed!");
            }

            // 3. Prepare stuff ....
            SmalltalkClass.InstanceStateEnum instanceState = this.InstanceState.Value;
            ClassBinding superclass;

            if (this.SuperclassName.Value.Length == 0)
            {
                superclass = null; // Object has no superclass
            }
            else
            {
                superclass = installer.GetClassBinding(this.SuperclassName.Value);
                if (superclass == null)
                {
                    return(installer.ReportError(this.SuperclassName, InstallerErrors.ClassInvalidSuperclass));
                }
            }

            // Create the collection of class, class-instance, instance variables and imported pools
            BindingDictionary <InstanceVariableBinding>      instVars      = new BindingDictionary <InstanceVariableBinding>(installer.Runtime);
            DiscreteBindingDictionary <ClassVariableBinding> classVars     = new DiscreteBindingDictionary <ClassVariableBinding>(installer.Runtime, this.ClassVariableNames.Count());
            BindingDictionary <ClassInstanceVariableBinding> classInstVars = new BindingDictionary <ClassInstanceVariableBinding>(installer.Runtime);
            DiscreteBindingDictionary <PoolBinding>          pools         = new DiscreteBindingDictionary <PoolBinding>(installer.Runtime);

            // Validate class variable names ...
            foreach (SourceReference <string> identifier in this.ClassVariableNames)
            {
                Symbol varName = installer.Runtime.GetSymbol(identifier.Value);
                if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassClassVariableNotIdentifier));
                }
                if (classVars.Any <ClassVariableBinding>(varBinding => varBinding.Name == varName))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassClassVariableNotUnique));
                }
                classVars.Add(new ClassVariableBinding(varName));
            }
            // Validate instance variable names ...
            foreach (SourceReference <string> identifier in this.InstanceVariableNames)
            {
                Symbol varName = installer.Runtime.GetSymbol(identifier.Value);
                if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassInstanceVariableNotIdentifier));
                }
                if (((IEnumerable <InstanceVariableBinding>)instVars).Any(varBinding => varBinding.Name == varName))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassInstanceVariableNotUnique));
                }
                if (classVars.Any <ClassVariableBinding>(varBinding => varBinding.Name == varName))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassInstanceOrClassVariableNotUnique));
                }
                instVars.Add(new InstanceVariableBinding(varName));
            }
            // Validate class instance variable names ...
            foreach (SourceReference <string> identifier in this.ClassInstanceVariableNames)
            {
                Symbol varName = installer.Runtime.GetSymbol(identifier.Value);
                if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassClassInstanceVariableNotIdentifier));
                }
                if (classInstVars.Any <ClassInstanceVariableBinding>(varBinding => varBinding.Name == varName))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassClassInstanceVariableNotUnique));
                }
                if (classVars.Any <ClassVariableBinding>(varBinding => varBinding.Name == varName))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassClassInstanceOrClassVariableNotUnique));
                }
                classInstVars.Add(new ClassInstanceVariableBinding(varName));
            }
            // Validate imported pool names ...
            foreach (SourceReference <string> identifier in this.ImportedPoolNames)
            {
                Symbol varName = installer.Runtime.GetSymbol(identifier.Value);
                if (!IronSmalltalk.Common.Utilities.ValidateIdentifier(identifier.Value))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotIdentifier));
                }
                if (pools.Any <PoolBinding>(varBinding => varBinding.Name == varName))
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotUnique));
                }
                PoolBinding pool = installer.GetPoolBinding(varName);
                if (pool == null)
                {
                    return(installer.ReportError(identifier, InstallerErrors.ClassImportedPoolNotDefined));
                }
                pools.Add(pool);
            }

            // 4. Finally, create the behavior object
            binding.SetValue(new SmalltalkClass(
                                 installer.Runtime, binding.Name, superclass, instanceState, instVars, classVars, classInstVars, pools));
            return(true);
        }
Exemplo n.º 15
0
        public static void CreateClass(SmalltalkRuntime runtime, SmalltalkNameScope scope, ClassBinding binding, string superclassName,
                                       SmalltalkClass.InstanceStateEnum instanceState, string[] classVarNames, string[] instVarNames, string[] classInstVarNames, string[] importedPools,
                                       Func <SmalltalkClass, Dictionary <Symbol, CompiledMethod> > classMethodDicInitializer, Func <SmalltalkClass, Dictionary <Symbol, CompiledMethod> > instanceMethodDicInitializer)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (scope == null)
            {
                throw new ArgumentNullException("scope");
            }
            if (binding == null)
            {
                throw new ArgumentNullException("binding");
            }
            if (classMethodDicInitializer == null)
            {
                throw new ArgumentNullException("classMethodDicInitializer");
            }
            if (instanceMethodDicInitializer == null)
            {
                throw new ArgumentNullException("instanceMethodDicInitializer");
            }
            // 3. Prepare stuff ....
            ClassBinding superclass;

            if (String.IsNullOrWhiteSpace(superclassName))
            {
                superclass = null; // Object has no superclass
            }
            else
            {
                superclass = scope.GetClassBinding(superclassName);
                if (superclass == null)
                {
                    throw new InvalidOperationException("Should have found a binding for the superclass");
                }
            }

            // Create the collection of class, class-instance, instance variables and imported pools
            BindingDictionary <InstanceVariableBinding>      instVars      = new BindingDictionary <InstanceVariableBinding>(runtime);
            DiscreteBindingDictionary <ClassVariableBinding> classVars     = new DiscreteBindingDictionary <ClassVariableBinding>(runtime, ((classVarNames == null) ? 0 : classVarNames.Length));
            BindingDictionary <ClassInstanceVariableBinding> classInstVars = new BindingDictionary <ClassInstanceVariableBinding>(runtime);
            DiscreteBindingDictionary <PoolBinding>          pools         = new DiscreteBindingDictionary <PoolBinding>(runtime);

            // Add class variable names ...
            if (classVarNames != null)
            {
                foreach (string identifier in classVarNames)
                {
                    Symbol varName = runtime.GetSymbol(identifier);
                    classVars.Add(new ClassVariableBinding(varName));
                }
            }
            // Add instance variable names ...
            if (instVarNames != null)
            {
                foreach (string identifier in instVarNames)
                {
                    Symbol varName = runtime.GetSymbol(identifier);
                    instVars.Add(new InstanceVariableBinding(varName));
                }
            }
            // Add class instance variable names ...
            if (classInstVarNames != null)
            {
                foreach (string identifier in classInstVarNames)
                {
                    Symbol varName = runtime.GetSymbol(identifier);
                    classInstVars.Add(new ClassInstanceVariableBinding(varName));
                }
            }
            // Add imported pool names ...
            if (importedPools != null)
            {
                foreach (string identifier in importedPools)
                {
                    Symbol      varName = runtime.GetSymbol(identifier);
                    PoolBinding pool    = scope.GetPoolBinding(varName);
                    if (pool == null)
                    {
                        throw new InvalidOperationException(String.Format("Should have found a binding for pool {0}", identifier));
                    }
                    pools.Add(pool);
                }
            }
            // Create method dictionaries
            MethodDictionaryInitializer clsMthInitializer  = new MethodDictionaryInitializer(classMethodDicInitializer);
            MethodDictionaryInitializer instMthInitializer = new MethodDictionaryInitializer(instanceMethodDicInitializer);
            ClassMethodDictionary       classMethods       = new ClassMethodDictionary(runtime, clsMthInitializer.Initialize);
            InstanceMethodDictionary    instanceMethods    = new InstanceMethodDictionary(runtime, instMthInitializer.Initialize);

            // 4. Finally, create the behavior object
            SmalltalkClass cls = new SmalltalkClass(runtime, binding.Name, superclass, instanceState, instVars, classVars, classInstVars, pools, instanceMethods, classMethods);

            clsMthInitializer.Class  = cls;
            instMthInitializer.Class = cls;
            binding.SetValue(cls);
        }
Exemplo n.º 16
0
 void ISmalltalkNameScopeVisitor.Visit(PoolBinding binding)
 {
     this.Generators.Add(new PoolGenerator(this.Compiler, binding));
 }
Exemplo n.º 17
0
        public static PoolConstantBinding CreatePoolConstantBinding(SmalltalkRuntime runtime, PoolBinding poolBinding, string name)
        {
            if (runtime == null)
            {
                throw new ArgumentNullException("runtime");
            }
            if (poolBinding == null)
            {
                throw new ArgumentNullException("poolBinding");
            }

            Symbol varName = runtime.GetSymbol(name);
            PoolConstantBinding binding = new PoolConstantBinding(varName);

            poolBinding.Value.Add(binding);
            return(binding);
        }
Exemplo n.º 18
0
 void IInstallerContext.AddPoolBinding(PoolBinding binding)
 {
     this.NameScope.Pools.Add(binding);
 }