示例#1
0
        public MethodCompilerEnvironment EnterBlock()
        {
            var res = new MethodCompilerEnvironment
                          (Global,
                          SkolemDefs,
                          Assembly,
                          Type,
                          TypeBoundArguments,
                          Method,
                          MethodBoundArguments,
                          Variables,
                          ValueParameterIds,
                          LocalIds,
                          Env,
                          NameSupply,
                          rootId,
                          assemblyId,
                          typeDefinitionId,
                          MethodId,
                          TypeBoundTypeParameterIds,
                          MethodBoundTypeParameterIds,
                          typeTrace);

            res.InheritBindings(this);

            return(res);
        }
示例#2
0
 private void InheritBindings(MethodCompilerEnvironment outer)
 {
     foreach (var kv in outer.boundAssemblies)
     {
         boundAssemblies.Add(kv.Key, kv.Value);
     }
     foreach (var kv in outer.boundTypes)
     {
         boundTypes.Add(kv.Key, kv.Value);
     }
     foreach (var kv in outer.boundVariablePointers)
     {
         boundVariablePointers.Add(kv.Key, kv.Value);
     }
 }
示例#3
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);
        }