예제 #1
0
        // Trace mode entry point
        public TypeDefinitionCompiler(AssemblyCompiler parent, TypeTrace typeTrace)
        {
            Env = parent.Env;
            Parent = parent;
            TyconEnv = parent.AssmEnv.AddType(typeTrace.Type);
            this.TypeTrace = typeTrace;

            if (typeTrace.IncludeType && typeTrace.Parent.Parent.Flavor == TraceFlavor.Remainder)
            {
                // Create a self-loader fragment file
                NameSupply = new JST.NameSupply(Constants.Globals);
                // Will be bound by function passed to root's BindType
                RootId = NameSupply.GenSym();
                AssemblyId = NameSupply.GenSym();
                TypeDefinitionId = NameSupply.GenSym();
            }
            else {
                // Possibly inline type definition and/or method definitions into trace
                NameSupply = parent.NameSupply;
                // Already bound by parent
                RootId = parent.RootId;
                AssemblyId = parent.AssemblyId;
                // Will be bound locally
                TypeDefinitionId = NameSupply.GenSym();
            }
        }
예제 #2
0
        // Trace mode entry point
        public TypeDefinitionCompiler(AssemblyCompiler parent, TypeTrace typeTrace)
        {
            Env            = parent.Env;
            Parent         = parent;
            TyconEnv       = parent.AssmEnv.AddType(typeTrace.Type);
            this.TypeTrace = typeTrace;

            if (typeTrace.IncludeType && typeTrace.Parent.Parent.Flavor == TraceFlavor.Remainder)
            {
                // Create a self-loader fragment file
                NameSupply = new JST.NameSupply(Constants.Globals);
                // Will be bound by function passed to root's BindType
                RootId           = NameSupply.GenSym();
                AssemblyId       = NameSupply.GenSym();
                TypeDefinitionId = NameSupply.GenSym();
            }
            else
            {
                // Possibly inline type definition and/or method definitions into trace
                NameSupply = parent.NameSupply;
                // Already bound by parent
                RootId     = parent.RootId;
                AssemblyId = parent.AssemblyId;
                // Will be bound locally
                TypeDefinitionId = NameSupply.GenSym();
            }
        }
        public void BindUsage(ISeq <JST.Statement> statements, CST.Usage usage, TypePhase typePhase)
        {
            foreach (var kv in usage.Assemblies)
            {
                if (kv.Value > 1)
                {
                    if (!boundAssemblies.ContainsKey(kv.Key))
                    {
                        var e = env.JSTHelpers.DefaultResolveAssembly(this, kv.Key);
                        if (e != null)
                        {
                            if (env.DebugMode)
                            {
                                statements.Add(new JST.CommentStatement(kv.Key.ToString()));
                            }
                            var id = NameSupply.GenSym();
                            statements.Add(JST.Statement.Var(id, e));
                            boundAssemblies.Add(kv.Key, id.ToE());
                        }
                    }
                    // else: use outer binding
                }
                // else: inline expression as need it
            }

            foreach (var kv in usage.Types)
            {
                if (kv.Value > 1)
                {
                    var existing = default(ExpressionAndPhase);
                    var b        = boundTypes.TryGetValue(kv.Key, out existing);
                    if (!b || typePhase > existing.Phase)
                    {
                        var e = env.JSTHelpers.DefaultResolveType(this, kv.Key, typePhase);
                        if (e != null)
                        {
                            if (env.DebugMode)
                            {
                                statements.Add(new JST.CommentStatement(kv.Key.ToString()));
                            }
                            var id = NameSupply.GenSym();
                            statements.Add(JST.Statement.Var(id, e));
                            var updated = new ExpressionAndPhase(id.ToE(), typePhase);
                            if (b)
                            {
                                boundTypes[kv.Key] = updated;
                            }
                            else
                            {
                                boundTypes.Add(kv.Key, updated);
                            }
                        }
                    }
                    // else: use outer binding
                }
                // else: inline expression as need it
            }
        }
예제 #4
0
 // Collecting mode entry point
 public AssemblyCompiler(CompilerEnvironment env, CST.AssemblyDef assemblyDef)
     : this(env)
 {
     assmEnv       = env.Global.Environment().AddAssembly(assemblyDef);
     assemblyTrace = null;
     NameSupply    = new JST.NameSupply(Constants.Globals);
     rootId        = NameSupply.GenSym();
     assemblyId    = NameSupply.GenSym();
 }
예제 #5
0
 // Collecting mode entry point
 public AssemblyCompiler(CompilerEnvironment env, CST.AssemblyDef assemblyDef)
     : this(env)
 {
     assmEnv = env.Global.Environment().AddAssembly(assemblyDef);
     assemblyTrace = null;
     NameSupply = new JST.NameSupply(Constants.Globals);
     rootId = NameSupply.GenSym();
     assemblyId = NameSupply.GenSym();
 }
        public static TypeCompilerEnvironment EnterType
            (CompilerEnvironment env,
            JST.NameSupply nameSupply,
            JST.Identifier rootId,
            JST.Identifier assemblyId,
            JST.Identifier typeId,
            CST.TypeEnvironment typeEnv,
            TypeTrace typeTrace)
        {
            var typeBoundTypeParameterIds = new Seq <JST.Identifier>();

            for (var i = 0; i < typeEnv.Type.Arity; i++)
            {
                typeBoundTypeParameterIds.Add(nameSupply.GenSym());
            }

            var res = new TypeCompilerEnvironment
                          (typeEnv.Global,
                          typeEnv.SkolemDefs,
                          typeEnv.Assembly,
                          typeEnv.Type,
                          typeEnv.TypeBoundArguments,
                          env,
                          nameSupply,
                          rootId,
                          assemblyId,
                          typeId,
                          typeBoundTypeParameterIds,
                          typeTrace);

            res.BindSpecial();

            return(res);
        }
예제 #7
0
 private void BindMap <T>
     (ISeq <JST.Statement> statements,
     IMap <T, int> usageMap,
     IMap <T, JST.Expression> boundMap,
     Func <T, string> mkName,
     Func <T, JST.Expression> mkExpression)
 {
     foreach (var kv in usageMap)
     {
         if (!boundMap.ContainsKey(kv.Key))
         {
             if (kv.Value > 1)
             {
                 var e = mkExpression(kv.Key);
                 if (e != null)
                 {
                     if (env.DebugMode)
                     {
                         statements.Add(new JST.CommentStatement(mkName(kv.Key)));
                     }
                     var id = NameSupply.GenSym();
                     statements.Add(JST.Statement.Var(id, e));
                     boundMap.Add(kv.Key, id.ToE());
                 }
             }
             // else: inline expression as need it
         }
         // else: use outer binding
     }
 }
예제 #8
0
 // Traced mode entry point
 public AssemblyCompiler(TraceCompiler parent, AssemblyTrace assemblyTrace)
     : this(parent.Env)
 {
     assmEnv            = parent.Env.Global.Environment().AddAssembly(assemblyTrace.Assembly);
     this.assemblyTrace = assemblyTrace;
     if (assemblyTrace.Parent.Flavor == TraceFlavor.Remainder)
     {
         NameSupply = new JST.NameSupply(Constants.Globals);
         rootId     = NameSupply.GenSym();
         assemblyId = NameSupply.GenSym();
     }
     else
     {
         NameSupply = parent.NameSupply;
         rootId     = parent.RootId;
         assemblyId = NameSupply.GenSym();
     }
 }
예제 #9
0
 // Traced mode entry point
 public AssemblyCompiler(TraceCompiler parent, AssemblyTrace assemblyTrace)
     : this(parent.Env)
 {
     assmEnv = parent.Env.Global.Environment().AddAssembly(assemblyTrace.Assembly);
     this.assemblyTrace = assemblyTrace;
     if (assemblyTrace.Parent.Flavor == TraceFlavor.Remainder)
     {
         NameSupply = new JST.NameSupply(Constants.Globals);
         rootId = NameSupply.GenSym();
         assemblyId = NameSupply.GenSym();
     }
     else
     {
         NameSupply = parent.NameSupply;
         rootId = parent.RootId;
         assemblyId = NameSupply.GenSym();
     }
 }
예제 #10
0
 public TraceCompiler(CompilerEnvironment env, Trace trace)
 {
     Env   = env;
     Trace = trace;
     if (trace.Flavor != TraceFlavor.Remainder)
     {
         NameSupply = new JST.NameSupply(Constants.Globals);
         RootId     = NameSupply.GenSym();
     }
 }
예제 #11
0
 public TraceCompiler(CompilerEnvironment env, Trace trace)
 {
     Env = env;
     Trace = trace;
     if (trace.Flavor != TraceFlavor.Remainder)
     {
         NameSupply = new JST.NameSupply(Constants.Globals);
         RootId = NameSupply.GenSym();
     }
 }
예제 #12
0
 public TypeCompiler(TypeDefinitionCompiler parent)
 {
     // Type compiler is always in context of it's type definition
     Env = parent.Env;
     Parent = parent;
     var typeEnv = parent.TyconEnv.AddSelfTypeBoundArguments();
     NameSupply = typeEnv.Type.Arity > 0 ? parent.NameSupply.Fork() : parent.NameSupply;
     RootId = parent.RootId;
     AssemblyId = parent.AssemblyId;
     TypeDefinitionId = parent.TypeDefinitionId;
     TypeId = typeEnv.Type.Arity > 0 ? NameSupply.GenSym() : parent.TypeDefinitionId;
     TypeCompEnv = TypeCompilerEnvironment.EnterType(Env, NameSupply, RootId, AssemblyId, TypeId, typeEnv, parent.TypeTrace);
 }
예제 #13
0
 // Collecting mode entry point
 public TypeDefinitionCompiler(AssemblyCompiler parent, CST.TypeDef typeDef)
 {
     Env = parent.Env;
     Parent = parent;
     TyconEnv = parent.AssmEnv.AddType(typeDef);
     TypeTrace = null;
     // Inline type definition and method definitions into overall assembly
     NameSupply = parent.NameSupply;
     // Already bound by parent
     RootId = parent.RootId;
     AssemblyId = parent.AssemblyId;
     // Will be bound locally
     TypeDefinitionId = NameSupply.GenSym();
 }
예제 #14
0
 // Collecting mode entry point
 public TypeDefinitionCompiler(AssemblyCompiler parent, CST.TypeDef typeDef)
 {
     Env       = parent.Env;
     Parent    = parent;
     TyconEnv  = parent.AssmEnv.AddType(typeDef);
     TypeTrace = null;
     // Inline type definition and method definitions into overall assembly
     NameSupply = parent.NameSupply;
     // Already bound by parent
     RootId     = parent.RootId;
     AssemblyId = parent.AssemblyId;
     // Will be bound locally
     TypeDefinitionId = NameSupply.GenSym();
 }
예제 #15
0
        public static MethodCompilerEnvironment EnterMethod
            (CompilerEnvironment env,
            JST.NameSupply outerNameSupply,
            JST.NameSupply nameSupply,
            JST.Identifier rootId,
            JST.Identifier assemblyId,
            JST.Identifier typeDefinitonId,
            CST.CompilationEnvironment compEnv,
            TypeTrace typeTrace)
        {
            // BUG: IE messes up scoping for function identifiers. To compensate we must allocate its
            //      identifier in the outer scope
            var methodId = outerNameSupply.GenSym();

            if (env.DebugMode)
            {
                var sb = new StringBuilder();
                sb.Append(methodId.Value);
                sb.Append('_');
                var namedTypeDef = compEnv.Type as CST.NamedTypeDef;
                if (namedTypeDef != null)
                {
                    if (namedTypeDef.Name.Namespace.Length > 0)
                    {
                        JST.Lexemes.AppendStringToIdentifier(sb, namedTypeDef.Name.Namespace.Replace('.', '_'));
                        sb.Append('_');
                    }
                    foreach (var n in namedTypeDef.Name.Types)
                    {
                        JST.Lexemes.AppendStringToIdentifier(sb, n);
                        sb.Append('_');
                    }
                }
                JST.Lexemes.AppendStringToIdentifier(sb, compEnv.Method.Name);
                methodId = new JST.Identifier(sb.ToString());
            }

            var typeBoundTypeParameterIds = new Seq <JST.Identifier>();

            for (var i = 0; i < compEnv.Type.Arity; i++)
            {
                typeBoundTypeParameterIds.Add(nameSupply.GenSym());
            }

            var methodBoundTypeParameterIds = new Seq <JST.Identifier>();

            for (var i = 0; i < compEnv.Method.TypeArity; i++)
            {
                methodBoundTypeParameterIds.Add(nameSupply.GenSym());
            }

            var res = new MethodCompilerEnvironment
                          (compEnv.Global,
                          compEnv.SkolemDefs,
                          compEnv.Assembly,
                          compEnv.Type,
                          compEnv.TypeBoundArguments,
                          compEnv.Method,
                          compEnv.MethodBoundArguments,
                          compEnv.Variables,
                          compEnv.ValueParameterIds,
                          compEnv.LocalIds,
                          env,
                          nameSupply,
                          rootId,
                          assemblyId,
                          typeDefinitonId,
                          methodId,
                          typeBoundTypeParameterIds,
                          methodBoundTypeParameterIds,
                          typeTrace);

            res.BindSpecial();

            return(res);
        }