private void GenerateCustomLibrary() { // Visit the name scopes in the runtime. NameScopeGenerator extensionScope = null, globalScope = null; if (this.Parameters.ExtensionScopeInitializer == null) { extensionScope = new NameScopeGenerator(this, "ExtensionScope", true); this.Parameters.Runtime.ExtensionScope.Accept(extensionScope); } globalScope = new NameScopeGenerator(this, "GlobalScope", false); this.Parameters.Runtime.GlobalScope.Accept(globalScope); // Generate types from the result of the name scope visiting MethodInfo extensionScopeInitializer, globalScopeInitializer; if (this.Parameters.ExtensionScopeInitializer == null) { extensionScopeInitializer = extensionScope.GenerateNameScopeInitializerMethod(); } else { extensionScopeInitializer = this.Parameters.ExtensionScopeInitializer; } globalScopeInitializer = globalScope.GenerateNameScopeInitializerMethod(); // Generate the entry point class, the one that creates the new Smalltalk runtime. RuntimeGenerator runtime = new RuntimeGenerator(this, extensionScopeInitializer, globalScopeInitializer); runtime.GenerateCreateRuntimeMethods(); }
private void GenerateStanradLibrary() { System.Diagnostics.Debug.Assert(this.Parameters.Runtime.GlobalScope.IsEmpty); // Visit the name scopes in the runtime. NameScopeGenerator scope = new NameScopeGenerator(this, "StandardScope", true); this.Parameters.Runtime.ExtensionScope.Accept(scope); // Generate types from the result of the name scope visiting MethodInfo scopeInitializer = scope.GenerateNameScopeInitializerMethod(); // Generate the entry point class, the one that creates the new Smalltalk runtime. StandardLibraryGenerator library = new StandardLibraryGenerator(this, scopeInitializer); library.GenerateEntryMethod(); }
internal void GenerateGlobal(NameScopeGenerator scopeGenerator, ParameterExpression runtime, ParameterExpression scope, List <ParameterExpression> variables, List <Expression> createBindings, List <Expression> initializeBindings) { // The method that will add the global binding, e.g. ... NativeLoadHelper.AddClassBinding(...); MethodInfo addBindingMethod = this.GetAddBindingMethod(); // Create a temp var for each global binding object. ParameterExpression variable = Expression.Parameter(addBindingMethod.ReturnType, this.BindingName); variables.Add(variable); // Add a statement to call that method and assign it to the temp var .... ClassBinding binding27 = NativeLoadHelper.AddClassBinding(runtime, scope, "..."); createBindings.Add(Expression.Assign(variable, Expression.Call(addBindingMethod, runtime, scope, Expression.Constant(this.BindingName, typeof(String))))); // Add a statement that will create the global object. This is relevant for clases and pools. // Example ... NativeLoadHelper.CreateClass(runtime, scope, binding27, "...", SmalltalkClass.InstanceStateEnum.Native, ...); IEnumerable <Expression> expression = this.GenerateCreateGlobalObjectExpression(runtime, scopeGenerator, scope, variable); if (expression != null) { initializeBindings.AddRange(expression); } // Add optional annotations ... NativeLoadHelper.AnnotateObject(binding27, "...", "..."); this.GenerateAnnotations(initializeBindings, variable); }
protected override IEnumerable <Expression> GenerateCreateGlobalObjectExpression(ParameterExpression runtime, NameScopeGenerator scopeGenerator, ParameterExpression scope, ParameterExpression binding) { // IMPROVE: Why can't we use this.InitializerMethod directly and need to do the extra lookup? Type initializerType = scopeGenerator.PoolsInitializerType; MethodInfo initializer = TypeUtilities.Method(initializerType, this.InitializerMethod.Name, BindingFlags.Static | BindingFlags.NonPublic, typeof(SmalltalkRuntime), typeof(PoolBinding)); return(new Expression[] { Expression.Call(PoolGenerator.CreatePoolMethod, runtime, binding), Expression.Call(initializer, runtime, binding) }); }
/// <summary> /// Generate a delegate that can initialize the method dictionary for this generator. /// </summary> /// <param name="scopeGenerator"></param> /// <returns>Returns a delegate of type: cls => ScopeName_MethodInitializers.Init_ClassName_ClassMethods(cls)</returns> internal Expression <Func <SmalltalkClass, Dictionary <Symbol, CompiledMethod> > > GetMethodDictionaryInitializerDelegate(NameScopeGenerator scopeGenerator) { // IMPROVE: Why can't we use this.InitMethodDictionariesMethod directly and need to do the extra lookup? MethodInfo initializer = TypeUtilities.Method(scopeGenerator.MethodsInitializerType, this.InitMethodDictionariesMethod.Name, BindingFlags.Static | BindingFlags.NonPublic, typeof(SmalltalkClass)); // NB: This will create helper methods, but too much work to get around this ... ParameterExpression cls = Expression.Parameter(typeof(SmalltalkClass), "cls"); return(Expression.Lambda <Func <SmalltalkClass, Dictionary <Symbol, CompiledMethod> > >(Expression.Call(initializer, cls), cls)); }
/// <summary> /// Generate a statement that will create the global object. This is relevant for clases and pools. /// </summary> /// <param name="runtime">Parameter representing the SmalltalkRuntime.</param> /// <param name="scopeGenerator">Generator for the current name scope.</param> /// <param name="scope">Parameter representing the current name scope.</param> /// <param name="binding">Parameter representing the global binding.</param> /// <returns>A collection of expressions or null.</returns> protected virtual IEnumerable <Expression> GenerateCreateGlobalObjectExpression(ParameterExpression runtime, NameScopeGenerator scopeGenerator, ParameterExpression scope, ParameterExpression binding) { return(null); }
protected override IEnumerable <Expression> GenerateCreateGlobalObjectExpression(ParameterExpression runtime, NameScopeGenerator scopeGenerator, ParameterExpression scope, ParameterExpression binding) { return(new Expression[] { Expression.Call(ClassGenerator.CreateClassMethod, runtime, scope, binding, Expression.Constant(((this.Binding.Value.SuperclassBinding == null) ? null : this.Binding.Value.SuperclassBinding.Name.Value), typeof(string)), Expression.Constant(this.Binding.Value.InstanceState, typeof(IronSmalltalk.Runtime.SmalltalkClass.InstanceStateEnum)), this.CreateExpressionArray(this.Binding.Value.ClassVariableBindings), this.CreateExpressionArray(this.Binding.Value.InstanceVariableBindings), this.CreateExpressionArray(this.Binding.Value.ClassInstanceVariableBindings), this.CreateExpressionArray(this.Binding.Value.ImportedPoolBindings), this.ClassMethodGenerator.GetMethodDictionaryInitializerDelegate(scopeGenerator), this.InstanceMethodGenerator.GetMethodDictionaryInitializerDelegate(scopeGenerator)) }); }