/// <summary> /// Create a new SuperSendCallSiteBinder. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> /// <param name="selector">Selector of the message being sent.</param> /// <param name="superScope">The name of the class ABOVE which to start the method lookup.</param> public SuperSendCallSiteBinder(SmalltalkRuntime runtime, Symbol selector, Symbol superScope) : base(runtime, selector) { if (superScope == null) throw new ArgumentNullException("superScope"); this.SuperScope = superScope; }
//public MethodDictionary Message; //public MethodDictionary Array; //public MethodDictionary Float; //public MethodDictionary Symbol; //public MethodDictionary Decimal; //public MethodDictionary Error; internal NativeTypeClassMap(SmalltalkRuntime runtime) { if (runtime == null) throw new ArgumentNullException(); this.Runtime = runtime; this.TypeClassMap = new ConcurrentDictionary<Type, SmalltalkClass>(); }
/// <summary> /// Create a new MessageSendCallSiteBinderBase. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> /// <param name="selector">Selector of the message being sent.</param> public MessageSendCallSiteBinderBase(SmalltalkRuntime runtime, Symbol selector) : base(runtime) { if (selector == null) throw new ArgumentNullException("selector"); this.Selector = selector; }
/// <summary> /// Create a new MessageSendCallSiteBinder. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> /// <param name="selector">Selector of the message being sent.</param> /// <param name="nativeName">Name of the method that the target is asked to bind.</param> /// <param name="argumentCount">Number of method arguments.</param> public MessageSendCallSiteBinder(SmalltalkRuntime runtime, Symbol selector, string nativeName, int argumentCount) : base(runtime, selector) { if (argumentCount < 0) throw new ArgumentOutOfRangeException("argumentCount"); this.NativeName = nativeName; this.ArgumentCount = argumentCount; }
public ExecutionContext(SmalltalkRuntime runtime) { if (runtime == null) { throw new ArgumentNullException("runtime"); } this.Runtime = runtime; }
/// <summary> /// Create a new method dictionary. /// </summary> /// <param name="runtime">Smalltalk runtime that the methods in the dictionary belong to.</param> protected MethodDictionary(SmalltalkRuntime runtime) { if (runtime == null) { throw new ArgumentNullException("runtime"); } this._Runtime = runtime; this._contents = new Dictionary <Symbol, CompiledMethod>(); }
//public MethodDictionary Message; //public MethodDictionary Array; //public MethodDictionary Float; //public MethodDictionary Symbol; //public MethodDictionary Decimal; //public MethodDictionary Error; internal NativeTypeClassMap(SmalltalkRuntime runtime) { if (runtime == null) { throw new ArgumentNullException(); } this.Runtime = runtime; this.TypeClassMap = new ConcurrentDictionary <Type, SmalltalkClass>(); }
/// <summary> /// Create a new pool with the given name within the given Smalltalk context. /// </summary> /// <param name="runtime">Smalltalk runtime that the pool belongs to.</param> /// <param name="name">Name of the pool.</param> public Pool(SmalltalkRuntime runtime, Symbol name) : base(runtime) { if (name == null) { throw new ArgumentNullException(); } this.Name = name; }
public BindingDictionary(SmalltalkRuntime runtime, int initialCapacity) { if (runtime == null) { throw new ArgumentNullException("runtime"); } this.Runtime = runtime; this._Contents = new Dictionary <Symbol, TItem>(initialCapacity); }
private static string Compile(NativeCompilerParameters parameters, bool installMetaAnnotations, IEnumerable <string> sourceFiles) { List <PathFileInInformation> fileIns = new List <PathFileInInformation>(); foreach (string sourceFile in sourceFiles) { SymbolDocumentInfo symbolDocument = null; if (parameters.EmitDebugSymbols) { symbolDocument = Expression.SymbolDocument(sourceFile, GlobalConstants.LanguageGuid, GlobalConstants.VendorGuid); } PathFileInInformation fileIn = new PathFileInInformation(sourceFile, System.Text.Encoding.UTF8, new FileInErrorSink(sourceFile), symbolDocument); fileIns.Add(fileIn); } if (fileIns.Count == 0) { return(null); } SmalltalkRuntime runtime; if (parameters.ExtensionScopeInitializer == null) { runtime = new SmalltalkRuntime(); } else { runtime = NativeLoadHelper.CreateRuntime(false, (rt, scope) => { parameters.ExtensionScopeInitializer.Invoke(null, new object[] { rt, scope }); }, (rt, scope) => { /* Nothing here */ }); } FileInService compilerService = new FileInService(runtime, installMetaAnnotations, fis => parameters.IsBaseLibrary ? new InternalInstallerContext(fis.Runtime) : new InterchangeInstallerContext(fis.Runtime)); InterchangeInstallerContext installer = compilerService.Read(fileIns); foreach (var fileIn in fileIns) { if (((FileInErrorSink)fileIn.ErrorSink).HadError) { return(null); // Some of the source file had errors, do not attempt the rest - it's meaningless } } installer.ErrorSink = new InstallErrorSink(); installer.InstallMetaAnnotations = compilerService.InstallMetaAnnotations; if (!installer.Install()) { return(null); } parameters.Runtime = runtime; return(NativeCompiler.NativeCompiler.GenerateNativeAssembly(parameters)); }
public static CompiledInitializer AddGlobalInitializer(SmalltalkRuntime runtime, SmalltalkNameScope scope, Type delegateType, string delegateName, string globalName) { GlobalVariableOrConstantBinding binding = scope.GetGlobalVariableOrConstantBinding(globalName); if (binding == null) { throw new ArgumentException(String.Format("Global variable or constant named {0} does not exist.", globalName)); } return(NativeLoadHelper.AddInitializer(scope, InitializerType.GlobalInitializer, binding, delegateType, delegateName)); }
public static CompiledInitializer AddClassInitializer(SmalltalkRuntime runtime, SmalltalkNameScope scope, Type delegateType, string delegateName, string className) { ClassBinding binding = scope.GetClassBinding(className); if (binding == null) { throw new ArgumentException(String.Format("Class named {0} does not exist.", className)); } return(NativeLoadHelper.AddInitializer(scope, InitializerType.ClassInitializer, binding, delegateType, delegateName)); }
protected Expression <Func <object, ExecutionContext, object> > Compile(SmalltalkRuntime runtime, BindingScope globalScope, BindingScope reservedScope, string initializerName) { CompilerOptions options = new CompilerOptions(); options.DebugInfoService = this.GetDebugInfoService(); InitializerCompiler compiler = new InitializerCompiler(runtime, options, globalScope, reservedScope); return(compiler.CompileInitializer(this.ParseTree, initializerName)); }
protected internal override void Execute(SmalltalkRuntime runtime) { Pool pool = runtime.GetPool(this.PoolName.Value); PoolVariableOrConstantBinding poolItemBinding = pool[this.VariableName.Value]; var compilationResult = this.IntermediateCode.CompilePoolItemInitializer(runtime, pool); var code = compilationResult.ExecutableCode.Compile(); var value = code(runtime, null); poolItemBinding.SetValue(value); }
public DefinitionInstallerContext(SmalltalkRuntime runtime) { if (runtime == null) { throw new ArgumentNullException("runtime"); } this.Runtime = runtime; this.InstallMetaAnnotations = false; }
/// <summary> /// Create and initialize an empty symbol table. /// </summary> public SymbolTable(SmalltalkRuntime runtime) { if (runtime == null) throw new ArgumentNullException(); this.Runtime = runtime; // We expect very low concurrency on writing ... we use Environment.ProcessorCount // Pre-allocate 4000 objects ... we expect some symbols. // Use StringComparer.InvariantCulture ... because symbols are case-sensitive etc. this._contents = new ConcurrentDictionary<string, WeakReference>( Environment.ProcessorCount, 4000, StringComparer.InvariantCulture); }
public SmalltalkNameScope(SmalltalkRuntime runtime, SmalltalkNameScope outerScope) { if (runtime == null) throw new ArgumentNullException("runtime"); this.Runtime = runtime; this.Classes = new DiscreteBindingDictionary<ClassBinding>(runtime, 50); this.GlobalConstants = new DiscreteBindingDictionary<GlobalConstantBinding>(runtime, 20); this.GlobalVariables = new DiscreteBindingDictionary<GlobalVariableBinding>(runtime, 20); this.Pools = new DiscreteBindingDictionary<PoolBinding>(runtime, 20); this.ProtectedNames = new List<Symbol>(); this.OuterScope = outerScope; }
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)); }
/// <summary> /// Create and initialize an empty symbol table. /// </summary> public SymbolTable(SmalltalkRuntime runtime) { if (runtime == null) { throw new ArgumentNullException(); } this.Runtime = runtime; // We expect very low concurrency on writing ... we use Environment.ProcessorCount // Pre-allocate 4000 objects ... we expect some symbols. // Use StringComparer.InvariantCulture ... because symbols are case-sensitive etc. this._Contents = new ConcurrentDictionary <string, WeakReference>( Environment.ProcessorCount, 4000, StringComparer.InvariantCulture); }
/// <summary> /// Internal! This is used by the Installer to create new classes. /// </summary> /// <param name="runtime">Smalltalk runtime this class is part of.</param> /// <param name="name">Name of the class.</param> /// <param name="superclass">Optional binding to the class' superclass.</param> /// <param name="instanceState">State of the class' instances (named, object-indexable, byte-indexable).</param> /// <param name="instanceVariables">Instance variables bindings. Those are initially not initialized.</param> /// <param name="classVariables">Class variable binding.</param> /// <param name="classInstanceVariables">Class-instance variables bindings. Those are initially not initialized.</param> /// <param name="importedPools">Collection of pools that are imported by the class.</param> /// <param name="instanceMethods">Collection with the methods defining the instance behaviors.</param> /// <param name="classMethods">Collection with the methods defining the class behaviors.</param> public SmalltalkClass(SmalltalkRuntime runtime, Symbol name, ClassBinding superclass, InstanceStateEnum instanceState, BindingDictionary <InstanceVariableBinding> instanceVariables, DiscreteBindingDictionary <ClassVariableBinding> classVariables, BindingDictionary <ClassInstanceVariableBinding> classInstanceVariables, DiscreteBindingDictionary <PoolBinding> importedPools, InstanceMethodDictionary instanceMethods, ClassMethodDictionary classMethods) { if (runtime == null) { throw new ArgumentNullException("runtime"); } if ((name == null) || (name.Value.Length == 0)) { throw new ArgumentNullException("name"); } if (!SmalltalkClass.ValidateIdentifiers <InstanceVariableBinding>(instanceVariables)) { throw new ArgumentException("Invalid or duplicate instance variable name found", "instanceVariables"); } if (!SmalltalkClass.ValidateIdentifiers <ClassVariableBinding>(classVariables)) { throw new ArgumentException("Invalid or duplicate class variable name found", "classVariables"); } if (!SmalltalkClass.ValidateIdentifiers <ClassInstanceVariableBinding>(classInstanceVariables)) { throw new ArgumentException("Invalid or duplicate class instance variable name found", "classInstanceVariables"); } if (!SmalltalkClass.ValidateIdentifiers <PoolBinding>(importedPools)) { throw new ArgumentException("Invalid or duplicate imported pool name found", "importedPools"); } if (!SmalltalkClass.CheckDuplicates <InstanceVariableBinding, ClassVariableBinding>(instanceVariables, classVariables)) { throw new ArgumentException("Duplicate instance or class variable name. Instance and class variable names must be unique."); } if (!SmalltalkClass.CheckDuplicates <ClassInstanceVariableBinding, ClassVariableBinding>(classInstanceVariables, classVariables)) { throw new ArgumentException("Duplicate class-instance or class variable name. Class-instance and class variable names must be unique."); } this.Runtime = runtime; this.ClassInstanceVariableBindings = classInstanceVariables ?? new BindingDictionary <ClassInstanceVariableBinding>(this.Runtime, 1); this.ClassBehavior = classMethods ?? new ClassMethodDictionary(this.Runtime); this.ClassVariableBindings = classVariables ?? new DiscreteBindingDictionary <ClassVariableBinding>(this.Runtime, 1); this.ImportedPoolBindings = importedPools ?? new DiscreteBindingDictionary <PoolBinding>(this.Runtime, 1); this.InstanceBehavior = instanceMethods ?? new InstanceMethodDictionary(this.Runtime); this.InstanceState = instanceState; this.InstanceVariableBindings = instanceVariables ?? new BindingDictionary <InstanceVariableBinding>(this.Runtime, 1); this.Name = name; this.SuperclassBinding = superclass; // Null is OK .... Object has null this.InstanceSize = 0; this.ClassInstanceSize = 0; this.ClassInstanceVariables = new object[0]; }
/// <summary> /// /// </summary> /// <param name="runtime">Smalltalk runtime responsible for running the code.</param> /// <param name="compilerOptions">Options that control the workings of the compiler.</param> /// <param name="globalScope">Binding lookup scope with global identifiers, e.g. globals, class variables, instance variables etc.</param> /// <param name="reservedScope">Binding lookup scope with reserved identifiers, e.g. "true", "false", "nil" etc.</param> public InitializerCompiler(SmalltalkRuntime runtime, CompilerOptions compilerOptions, BindingScope globalScope, BindingScope reservedScope) : base(runtime, compilerOptions) { if (globalScope == null) { throw new ArgumentNullException("globalScope"); } if (reservedScope == null) { throw new ArgumentNullException("reservedScope"); } this.GlobalScope = globalScope; this.ReservedScope = reservedScope; }
/// <summary> /// Create a new method dictionary that's lazy initializable. /// </summary> /// <param name="runtime">Smalltalk runtime that the methods in the dictionary belong to.</param> /// <param name="lazyInitializer">Callback function for lazy initializing of the contents of the method dictionary.</param> /// <remarks /// >In rare multi-threaded conditions the lazyInitializer function may be called more than once. /// Only one of the results will be stored, and the rest discarded! Therefore, the initializer /// function should be robust without side-effects if run more than once. /// </remarks> protected MethodDictionary(SmalltalkRuntime runtime, Func <SmalltalkRuntime, Dictionary <Symbol, CompiledMethod> > lazyInitializer) { if (runtime == null) { throw new ArgumentNullException("runtime"); } if (lazyInitializer == null) { throw new ArgumentNullException("lazyInitializer"); } this._Runtime = runtime; this._LazyInitializer = lazyInitializer; this._contents = null; }
public SmalltalkNameScope(SmalltalkRuntime runtime, SmalltalkNameScope outerScope) { if (runtime == null) { throw new ArgumentNullException("runtime"); } this.Runtime = runtime; this.Classes = new DiscreteBindingDictionary <ClassBinding>(runtime, 50); this.GlobalConstants = new DiscreteBindingDictionary <GlobalConstantBinding>(runtime, 20); this.GlobalVariables = new DiscreteBindingDictionary <GlobalVariableBinding>(runtime, 20); this.Pools = new DiscreteBindingDictionary <PoolBinding>(runtime, 20); this.Initializers = new InitializerList(); this.ProtectedNames = new List <Symbol>(); this.OuterScope = outerScope; }
public CompilerService(SmalltalkRuntime runtime) { if (runtime == null) throw new ArgumentNullException("runtime"); this.Runtime = runtime; this.VersionServicesMap = new Dictionary<string, InterchangeVersionService>(); this.VersionServicesMap.Add("1.0", new InterchangeVersionService10()); this.VersionServicesMap.Add("IronSmalltalk 1.0", new InterchangeVersionServiceIST10()); #if DEBUG this.InstallMetaAnnotations = true; #else this.InstallMetaAnnotations = false; #endif }
public static CallSiteBinderCache GetCache(SmalltalkRuntime runtime) { if (runtime == null) throw new ArgumentNullException(); object cache; runtime.ServicesCache.TryGetValue(typeof(CallSiteBinderCache), out cache); CallSiteBinderCache binderCache = cache as CallSiteBinderCache; if (binderCache == null) { binderCache = new CallSiteBinderCache(); runtime.ServicesCache[typeof(CallSiteBinderCache)] = binderCache; } return binderCache; }
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)); }
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); }
/// <summary> /// /// </summary> /// <param name="runtime">Smalltalk runtime responsible for running the code.</param> /// <param name="compilerOptions">Options that control the workings of the compiler.</param> protected ExpressionCompiler(SmalltalkRuntime runtime, CompilerOptions compilerOptions) { if (runtime == null) { throw new ArgumentNullException("runtime"); } if (compilerOptions == null) { compilerOptions = new CompilerOptions(); // Default options } this.Runtime = runtime; this.CompilerOptions = compilerOptions; this.DebugInfoService = compilerOptions.DebugInfoService; // Optional, null is OK this.LiteralEncodingStrategy = compilerOptions.LiteralEncodingStrategy ?? new LiteralEncodingStrategy(); this.DynamicCallStrategy = compilerOptions.DynamicCallStrategy ?? new DynamicCallStrategy(); this.DiscreteBindingEncodingStrategy = compilerOptions.DiscreteBindingEncodingStrategy ?? new DiscreteBindingEncodingStrategy(); }
/// <summary> /// Create a new SmalltalkScriptCode. /// </summary> /// <param name="code">Initializer code representing the code to be execution.</param> /// <param name="runtime">The IronSmalltalk Runtime this source is bound to.</param> /// <param name="sourceUnit">SourceUnit that resulted in the generated code.</param> public SmalltalkScriptCode(CompiledInitializer code, SmalltalkRuntime runtime, SourceUnit sourceUnit) : base(sourceUnit) { if (code == null) { throw new ArgumentNullException("code"); } if (runtime == null) { throw new ArgumentNullException("runtime"); } if (sourceUnit == null) { throw new ArgumentNullException("sourceUnit"); } this.Code = code; this.Runtime = runtime; }
public FileInService(SmalltalkRuntime runtime) { if (runtime == null) { throw new ArgumentNullException("runtime"); } // TODO : Move constants out of code into a the InterchangeFormatConstants class this.Runtime = runtime; this.VersionServicesMap = new Dictionary <string, InterchangeVersionService>(); this.VersionServicesMap.Add("1.0", new InterchangeVersionService10()); this.VersionServicesMap.Add("IronSmalltalk 1.0", new InterchangeVersionServiceIST10()); #if DEBUG this.InstallMetaAnnotations = true; #else this.InstallMetaAnnotations = false; #endif }
public static ClassBinding AddClassBinding(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); ClassBinding binding = new ClassBinding(symbol); scope.Classes.Add(binding); return(binding); }
public static void AddProtectedName(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); if (!scope.ProtectedNames.Contains(symbol)) { scope.ProtectedNames.Add(symbol); } }
protected internal override void Execute(SmalltalkRuntime runtime) { GlobalVariableOrConstantBinding globalBinding = runtime.GlobalScope.GetGlobalVariableOrConstantBinding(this.GlobalName.Value); if (globalBinding != null) { var compilationResult = this.IntermediateCode.CompileGlobalInitializer(runtime); var code = compilationResult.ExecutableCode.Compile(); var value = code(runtime, null); globalBinding.SetValue(value); return; } SmalltalkClass cls = runtime.GetClass(this.GlobalName.Value); if (cls != null) { var compilationResult = this.IntermediateCode.CompileClassInitializer(runtime, cls); var code = compilationResult.ExecutableCode.Compile(); code(runtime, cls); return; } throw new InvalidOperationException(); // Should not get here }
public static SmalltalkRuntime CreateRuntime(bool initialize, Action <SmalltalkRuntime, SmalltalkNameScope> extensionScopeInitializer, Action <SmalltalkRuntime, SmalltalkNameScope> globalScopeInitializer) { if (extensionScopeInitializer == null) { throw new ArgumentNullException("extensionScopeInitializer"); } if (globalScopeInitializer == null) { throw new ArgumentNullException("globalScopeInitializer"); } SmalltalkRuntime runtime = new SmalltalkRuntime(); ExecutionContext executionContext = new ExecutionContext(runtime); // Extension scope SmalltalkNameScope scope = runtime.ExtensionScope.Copy(); extensionScopeInitializer(runtime, scope); runtime.SetExtensionScope(scope); runtime.SetGlobalScope(runtime.GlobalScope.Copy(scope)); NativeLoadHelper.RecompileClasses(scope); if (initialize) { scope.ExecuteInitializers(executionContext); } // Global scope scope = runtime.GlobalScope.Copy(); globalScopeInitializer(runtime, scope); runtime.SetGlobalScope(scope); NativeLoadHelper.RecompileClasses(scope); if (initialize) { scope.ExecuteInitializers(executionContext); } return(runtime); }
public override InitializerCompilationResult CompilePoolItemInitializer(SmalltalkRuntime runtime, Pool pool) { return this.CompilePoolItemInitializer(runtime, pool, runtime.GlobalScope); }
public override InitializerCompilationResult CompileClassInitializer(SmalltalkRuntime runtime, SmalltalkClass cls) { return this.CompileClassInitializer(runtime, cls, runtime.GlobalScope); }
private InitializerCompilationResult CompileProgramInitializer(SmalltalkRuntime runtime, SmalltalkNameScope globalNameScope) { return this.Compile(runtime, BindingScope.ForProgramInitializer(globalNameScope), ReservedScope.ForProgramInitializer()); }
/// <summary> /// This core method determines the class of an object. /// </summary> /// <param name="runtime">Required: SmalltalkRuntime containing the Smalltalk classes.</param> /// <param name="receiver">Optional: Object whos class is to be determined.</param> /// <param name="self">Required: Expression for the receiver.</param> /// <param name="arguments">Required: Currently not used.</param> /// <param name="restrictions">Restrictions for the given receiver.</param> /// <returns>The SmalltalkClass for the given receiver. This always returns an object (unless the given SmalltalkRuntime is inconsistent).</returns> public static SmalltalkClass GetClassAndRestrictions(SmalltalkRuntime runtime, object receiver, DynamicMetaObject self, DynamicMetaObject[] arguments, out BindingRestrictions restrictions) { SmalltalkClass cls; // Special case handling of null, so it acts like first-class-object. if (receiver == null) { cls = runtime.NativeTypeClassMap.UndefinedObject; // If not explicitely mapped to a ST Class, fallback to the generic .Net mapping class. if (cls == null) cls = runtime.NativeTypeClassMap.Native; if (cls == null) cls = runtime.NativeTypeClassMap.Object; restrictions = BindingRestrictions.GetInstanceRestriction(self.Expression, null); } // Smalltalk objects ... almost every objects ends up here. else if (receiver is SmalltalkObject) { SmalltalkObject obj = (SmalltalkObject)receiver; cls = obj.Class; if (cls.Runtime == runtime) { FieldInfo field = typeof(SmalltalkObject).GetField("Class", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public); if (field == null) throw new InvalidOperationException(); restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(SmalltalkObject)); restrictions = restrictions.Merge(BindingRestrictions.GetExpressionRestriction( Expression.ReferenceEqual(Expression.Field(Expression.Convert(self.Expression, typeof(SmalltalkObject)), field), Expression.Constant(cls)))); } else { // A smalltalk object, but from different runtime cls = null; // Let block below handle this. restrictions = null; } } else if (receiver is Symbol) { Symbol symbol = (Symbol)receiver; SymbolTable manager = symbol.Manager; if (manager.Runtime == runtime) { cls = runtime.NativeTypeClassMap.Symbol; FieldInfo field = typeof(Symbol).GetField("Manager", BindingFlags.GetField | BindingFlags.Instance | BindingFlags.Public); if (field == null) throw new InvalidOperationException(); restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(Symbol)); restrictions = restrictions.Merge(BindingRestrictions.GetExpressionRestriction( Expression.ReferenceEqual(Expression.Field(Expression.Convert(self.Expression, typeof(Symbol)), field), Expression.Constant(manager)))); } else { // A smalltalk object, but from different runtime cls = null; // Let block below handle this. restrictions = null; } } else if (receiver is Pool) { Pool pool = (Pool)receiver; if (pool.Runtime == runtime) { cls = runtime.NativeTypeClassMap.Pool; PropertyInfo prop = typeof(Pool).GetProperty("Runtime", BindingFlags.FlattenHierarchy | BindingFlags.Public | BindingFlags.GetProperty, null, typeof(SmalltalkRuntime), new Type[0], null); if (prop == null) throw new InvalidOperationException(); restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(Pool)); restrictions = restrictions.Merge(BindingRestrictions.GetExpressionRestriction( Expression.ReferenceEqual(Expression.Property(Expression.Convert(self.Expression, typeof(Pool)), prop), Expression.Constant(runtime)))); } else { // A smalltalk object, but from different runtime cls = null; // Let block below handle this. restrictions = null; } } // Common FCL type mapping (bool, int, string, etc) to first-class-object. else if (receiver is bool) { Expression restrictionTest; if ((bool)receiver) { cls = runtime.NativeTypeClassMap.True; restrictionTest = Expression.IsTrue(Expression.Convert(self.Expression, typeof(bool))); } else { cls = runtime.NativeTypeClassMap.False; restrictionTest = Expression.IsFalse(Expression.Convert(self.Expression, typeof(bool))); } restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(bool)) .Merge(BindingRestrictions.GetExpressionRestriction(restrictionTest)); } else if (receiver is int) { cls = runtime.NativeTypeClassMap.SmallInteger; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(int)); } else if (receiver is string) { cls = runtime.NativeTypeClassMap.String; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(string)); } else if (receiver is char) { cls = runtime.NativeTypeClassMap.Character; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(char)); } else if (receiver is double) { cls = runtime.NativeTypeClassMap.Float; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(double)); } else if (receiver is decimal) { cls = runtime.NativeTypeClassMap.SmallDecimal; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(decimal)); } else if (receiver is System.Numerics.BigInteger) { cls = runtime.NativeTypeClassMap.BigInteger; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(System.Numerics.BigInteger)); } else if (receiver is IronSmalltalk.Common.BigDecimal) { cls = runtime.NativeTypeClassMap.BigDecimal; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(IronSmalltalk.Common.BigDecimal)); } // Special case for Smalltalk classes, because we want the class behavior ... else if (receiver is SmalltalkClass) { cls = (SmalltalkClass)receiver; if (cls.Runtime == runtime) { cls = runtime.NativeTypeClassMap.Class; if (cls == null) cls = runtime.NativeTypeClassMap.Object; if (cls == null) restrictions = null; else // NB: Restriction below are no good for For class behavior. restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(SmalltalkClass)); } else { // A smalltalk object, but from different runtime cls = null; // Let block below handle this. restrictions = null; } } // Some .Net type that's neither IronSmalltalk object nor any on the known (hardcoded) types. else { cls = null; // Let block below handle this. restrictions = null; } // In case of any of the known (hardcoded) types has no registered Smalltalk class, // fallback to the generic .Net type to Smalltalk class mapping. if (cls != null) { return cls; } else { Type type = receiver.GetType(); cls = runtime.NativeTypeClassMap.GetSmalltalkClass(type); // If not explicitely mapped to a ST Class, fallback to the generic .Net mapping class. if (cls == null) cls = runtime.NativeTypeClassMap.Native; if (restrictions == null) restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, type); return cls; } }
/// <summary> /// Create a new ObjectClassCallSiteBinder. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> public ObjectClassCallSiteBinder(SmalltalkRuntime runtime) : base(runtime) { }
/// <summary> /// Create a new SmalltalkDynamicMetaObjectBinder. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> public SmalltalkDynamicMetaObjectBinder(SmalltalkRuntime runtime) { if (runtime == null) throw new ArgumentNullException("runtime"); this.Runtime = runtime; }
public InstallerContext(SmalltalkRuntime runtime) { if (runtime == null) throw new ArgumentNullException("runtime"); this.Runtime = runtime; this.InstallMetaAnnotations = false; }
/// <summary> /// Internal! This is used by the Installer to create new classes. /// </summary> /// <param name="runtime">Smalltalk runtime this class is part of.</param> /// <param name="name">Name of the class.</param> /// <param name="superclass">Optional binding to the class' superclass.</param> /// <param name="instanceState">State of the class' instances (named, object-indexable, byte-indexable).</param> /// <param name="instanceVariables">Instance variables bindings. Those are initially not initialized.</param> /// <param name="classVariables">Class variable binding.</param> /// <param name="classInstanceVariables">Class-instance variables bindings. Those are initially not initialized.</param> /// <param name="importedPools">Collection of pools that are imported by the class.</param> public SmalltalkClass(SmalltalkRuntime runtime, Symbol name, ClassBinding superclass, InstanceStateEnum instanceState, BindingDictionary <InstanceVariableBinding> instanceVariables, DiscreteBindingDictionary <ClassVariableBinding> classVariables, BindingDictionary <ClassInstanceVariableBinding> classInstanceVariables, DiscreteBindingDictionary <PoolBinding> importedPools) : this(runtime, name, superclass, instanceState, instanceVariables, classVariables, classInstanceVariables, importedPools, null, null) { }
/// <summary> /// Create a new DoesNotUnderstandCallSiteBinder. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> public DoesNotUnderstandCallSiteBinder(SmalltalkRuntime runtime) : base(runtime) { }
/// <summary> /// Create a new ConstantSendCallSiteBinder. /// </summary> /// <param name="runtime">SmalltalkRuntine that this binder belongs to.</param> /// <param name="selector">Selector of the message being sent.</param> /// <param name="nativeName">Name of the method that the target is asked to bind.</param> /// <param name="argumentCount">Number of method arguments.</param> public ConstantSendCallSiteBinder(SmalltalkRuntime runtime, Symbol selector, string nativeName, int argumentCount) : base(runtime, selector, nativeName, argumentCount) { }
/// <summary> /// /// </summary> /// <param name="runtime">Smalltalk runtime responsible for running the code.</param> /// <param name="compilerOptions">Options that control the workings of the compiler.</param> public ClassMethodCompiler(SmalltalkRuntime runtime, CompilerOptions compilerOptions) : base(runtime, compilerOptions) { }
public InternalInstallerContext(SmalltalkRuntime runtime) : base(runtime) { }
public DiscreteBindingDictionary(SmalltalkRuntime runtime) : this(runtime, 100) { }
public override InitializerCompilationResult CompileProgramInitializer(SmalltalkRuntime runtime) { return this.CompileProgramInitializer(runtime, runtime.GlobalScope); }
public InternalCompilerService(SmalltalkRuntime runtime) : base(runtime) { }
protected internal override void Execute(SmalltalkRuntime runtime) { var compilationResult = this.IntermediateCode.CompileProgramInitializer(runtime); var code = compilationResult.ExecutableCode.Compile(); code(runtime, null); }
private InitializerCompilationResult Compile(SmalltalkRuntime runtime, BindingScope globalScope, BindingScope reservedScope) { InitializerVisitor visitor = new InitializerVisitor(runtime, globalScope, reservedScope); var code = this.ParseTree.Accept(visitor); return new InitializerCompilationResult(code, visitor.BindingRestrictions); }
private void button1_Click(object sender, EventArgs e) { ErrorSink errorSink = new ErrorSink(this); var paths = this.textSourceFiles.Text.Split('\n').Concat(this.openFileDialog.FileNames); paths = paths.Select(s => s.Trim()).Where(s => s.Length > 0); this.textSourceFiles.Text = String.Join("\r\n", paths); Properties.Settings.Default.LastNativePaths = this.textSourceFiles.Text; Properties.Settings.Default.Save(); var fileIns = paths.Select(p => new PathFileInInformation(p, System.Text.Encoding.UTF8, errorSink, Expression.SymbolDocument(p, GlobalConstants.LanguageGuid, GlobalConstants.VendorGuid))); this.listErrors.Items.Clear(); if (!fileIns.Any()) { return; } //Dictionary<string, InterchangeVersionService> versionServicesMap = new Dictionary<string, InterchangeVersionService>(); //versionServicesMap.Add("1.0", new InterchangeVersionService10()); //versionServicesMap.Add("IronSmalltalk 1.0", new InterchangeVersionServiceIST10()); //IInterchangeFileInProcessor installer = new Installer(); //foreach (FileInInformation info in fileIns) //{ // using (TextReader souceCodeReader = info.GetTextReader()) // { // InterchangeFormatProcessor processor = new InterchangeFormatProcessor(info, souceCodeReader, installer, versionServicesMap); // processor.ProcessInterchangeFile(); // } //} var runtime = new SmalltalkRuntime(); var compilerService = new FileInService(runtime, true, fis => new InternalInstallerContext(fis.Runtime)); InterchangeInstallerContext installer = compilerService.Read(fileIns); installer.ErrorSink = new InstallErrorSink(); installer.InstallMetaAnnotations = compilerService.InstallMetaAnnotations; if (!installer.Install()) { return; } IronSmalltalk.NativeCompiler.NativeCompilerParameters parameters = new IronSmalltalk.NativeCompiler.NativeCompilerParameters(); parameters.AssemblyName = "IronSt"; parameters.Company = "Iron Company"; parameters.Copyright = "Copy(right)"; parameters.EmitDebugSymbols = true; parameters.AssemblyType = IronSmalltalk.NativeCompiler.NativeCompilerParameters.AssemblyTypeEnum.Dll; parameters.OutputDirectory = "c:\\temp"; parameters.Product = "Iron Smalltalk Product"; parameters.AssemblyVersion = "1.2.3.4"; parameters.FileVersion = "1.2.3.4"; parameters.ProductVersion = "1.2.3.4"; parameters.ProductTitle = "Iron Title"; parameters.ProductDescription = "Just a test of the Iron Smalltalk native compiler"; parameters.RootNamespace = "IronSmalltalk.Test"; parameters.Runtime = runtime; parameters.Trademark = "Iron(tm)"; IronSmalltalk.NativeCompiler.NativeCompiler.GenerateNativeAssembly(parameters); MessageBox.Show("SUCCESS!"); }
private InitializerCompilationResult CompileClassInitializer(SmalltalkRuntime runtime, SmalltalkClass cls, SmalltalkNameScope globalNameScope) { return this.Compile(runtime, BindingScope.ForClassInitializer(cls, globalNameScope), ReservedScope.ForClassInitializer()); }
public static BindingScope ForProgramInitializer(SmalltalkRuntime runtime) { return BindingScope.ForProgramInitializer(runtime.GlobalScope); }
private InitializerCompilationResult CompilePoolItemInitializer(SmalltalkRuntime runtime, Pool pool, SmalltalkNameScope globalNameScope) { return this.Compile(runtime, BindingScope.ForPoolInitializer(pool, globalNameScope), ReservedScope.ForPoolInitializer()); }
public DiscreteBindingDictionary(SmalltalkRuntime runtime, int initialCapacity) : base(runtime, initialCapacity) { }
private Func <object, ExecutionContext, object> NativeCompile(SmalltalkRuntime runtime) { return(this.Compile(runtime).Compile()); }
public SmalltalkNameScope(SmalltalkRuntime runtime) : this(runtime, null) { }
/// <summary> /// This method is the core of the dynamic method lookup system. /// It determines the class of an object and looks-up the method implementation /// for a given method selector. /// </summary> /// <param name="runtime">Required.</param> /// <param name="selector">Required.</param> /// <param name="superLookupScope">Optional.</param> /// <param name="receiver">Optional.</param> /// <param name="self">Required.</param> /// <param name="arguments">Required (currently not used).</param> /// <param name="receiverClass">Must Return!</param> /// <param name="restrictions">Must Return!</param> /// <param name="executableCode">Return null if missing.</param> public static void GetMethodInformation(SmalltalkRuntime runtime, Symbol selector, Symbol superLookupScope, object receiver, DynamicMetaObject self, DynamicMetaObject[] arguments, out SmalltalkClass receiverClass, out BindingRestrictions restrictions, out Expression executableCode) { restrictions = null; SmalltalkClass cls = null; // Special case for Smalltalk classes, because we want the class behavior first ... if (receiver is SmalltalkClass) { cls = (SmalltalkClass)receiver; if (cls.Runtime == runtime) { receiverClass = runtime.NativeTypeClassMap.Class; if (receiverClass == null) receiverClass = runtime.NativeTypeClassMap.Object; // Lookup method in class behavior CompiledMethod mth = MethodLookupHelper.LookupClassMethod(selector, ref cls, ref superLookupScope); if (mth != null) { // A class method, special restrictions restrictions = BindingRestrictions.GetInstanceRestriction(self.Expression, receiver); var compilationResult = mth.Code.CompileClassMethod(runtime, cls, self, arguments, superLookupScope); if (compilationResult == null) { executableCode = null; } else { executableCode = compilationResult.ExecutableCode; restrictions = compilationResult.MergeRestrictions(restrictions); } return; } // Not in class behavior ... fallback to instance / Object behavior cls = receiverClass; restrictions = BindingRestrictions.GetTypeRestriction(self.Expression, typeof(SmalltalkClass)); } } if ((cls == null) || (restrictions == null)) cls = GetClassAndRestrictions(runtime, receiver, self, arguments, out restrictions); receiverClass = cls; // Look-up the method CompiledMethod method = MethodLookupHelper.LookupInstanceMethod(selector, ref cls, ref superLookupScope); if (method == null) { executableCode = null; } else { var compilationResult = method.Code.CompileInstanceMethod(runtime, cls, self, arguments, superLookupScope); if (compilationResult == null) { executableCode = null; } else { executableCode = compilationResult.ExecutableCode; restrictions = compilationResult.MergeRestrictions(restrictions); } } }