예제 #1
0
 public NameSupply(IImSet<string> globals, NameSupply parent)
 {
     this.globals = globals ?? Constants.EmptyStringSet;
     boundInThisScope = new Set<string>();
     boundInChildScope = new Set<string>();
     this.parent = parent;
 }
예제 #2
0
 public NameSupply(IImSet <string> globals, NameSupply parent)
 {
     this.globals      = globals ?? Constants.EmptyStringSet;
     boundInThisScope  = new Set <string>();
     boundInChildScope = new Set <string>();
     this.parent       = parent;
 }
예제 #3
0
        public MethodCompiler(TypeDefinitionCompiler parent, JST.NameSupply outerNameSupply, CST.MethodDef methodDef, MethodCompilationMode mode)
        {
            env = parent.Env;
            this.parent = parent;
            methEnv = parent.TyconEnv.AddSelfTypeBoundArguments().AddMethod(methodDef).AddSelfMethodBoundArguments();
            messageCtxt = CST.MessageContextBuilders.Env(methEnv);
            this.mode = mode;
            this.outerNameSupply = outerNameSupply;

            var common = default(JST.NameSupply);
            switch (mode)
            {
            case MethodCompilationMode.SelfContained:
                common = outerNameSupply;
                // Will be bound by function passed to root's BindMethod
                rootId = common.GenSym();
                assemblyId = common.GenSym();
                typeDefinitionId = common.GenSym();
                break;
            case MethodCompilationMode.DirectBind:
                common = outerNameSupply.Fork();
                // Already bound
                rootId = parent.RootId;
                assemblyId = parent.AssemblyId;
                typeDefinitionId = parent.TypeDefinitionId;
                break;
            default:
                throw new ArgumentOutOfRangeException("mode");
            }

            nameSupply = common.Fork();
            simpNameSupply = common.Fork();
        }
예제 #4
0
 public SimplifierContext(bool inGlobalScope, bool keepFunctionNames, NameSupply nameSupply, Func <Expression, bool> isValue)
 {
     InGlobalScope     = inGlobalScope;
     KeepFunctionNames = keepFunctionNames;
     NameSupply        = nameSupply;
     subst             = new Map <Identifier, Expression>();
     statements        = null;
     contextEffects    = Effects.Bottom;
     this.isValue      = isValue;
 }
예제 #5
0
 public SimplifierContext(bool inGlobalScope, bool keepFunctionNames, NameSupply nameSupply, Func<Expression, bool> isValue)
 {
     InGlobalScope = inGlobalScope;
     KeepFunctionNames = keepFunctionNames;
     NameSupply = nameSupply;
     subst = new Map<Identifier, Expression>();
     statements = null;
     contextEffects = Effects.Bottom;
     this.isValue = isValue;
 }
예제 #6
0
 public SimplifierContext
     (CompilationEnvironment compEnv,
     JST.NameSupply nameSupply,
     ISimplifierDatabase database,
     CSTWriter trace)
 {
     CompEnv        = compEnv;
     NameSupply     = nameSupply;
     subst          = new Map <JST.Identifier, Expression>();
     statements     = null;
     contextEffects = JST.Effects.Bottom;
     Database       = database;
     Trace          = trace;
 }
예제 #7
0
        public static CSTMethod Translate(MethodEnvironment methEnv, JST.NameSupply nameSupply, CSTWriter trace)
        {
            // Infer machine states for each control point
            var machineStateInference = new MachineStateInference(methEnv, trace);

            machineStateInference.Infer();

            if (trace != null)
            {
                trace.Trace
                    ("After machine state inference",
                    w =>
                {
                    methEnv.Method.AppendDefinition(w);
                    w.EndLine();
                });
            }

            // Translate to basic-blocks which use structural control flow where possible
            var controlFlowRecovery = new ControlFlowRecovery(methEnv, nameSupply.GenSym, -1, trace);
            var root = controlFlowRecovery.Root();

            if (trace != null)
            {
                trace.Trace
                    ("After control flow recovery",
                    w =>
                {
                    root.AppendAll(w);
                    w.EndLine();
                });
            }

            var initState = root.Targets[0].Block.BeforeState;
            var compEnv   = methEnv.AddVariables(nameSupply, i => initState.ArgLocalIsAlive(ArgLocal.Local, i));

            // Translate to intermediate statements/expressions/cells language
            var translator = new Translator
                                 (compEnv, nameSupply, controlFlowRecovery.NextInstructionId, trace);
            var body = translator.Translate(root);

            var res = new CSTMethod(compEnv, body);

            if (trace != null)
            {
                trace.Trace("After translation to intermediate representation", res.Append);
            }

            return(res);
        }
예제 #8
0
 public SimplifierContext
     (CompilationEnvironment compEnv,
      JST.NameSupply nameSupply,
      ISimplifierDatabase database,
      CSTWriter trace)
 {
     CompEnv = compEnv;
     NameSupply = nameSupply;
     subst = new Map<JST.Identifier, Expression>();
     statements = null;
     contextEffects = JST.Effects.Bottom;
     Database = database;
     Trace = trace;
 }
예제 #9
0
 protected SimplifierContext
     (CompilationEnvironment compEnv,
     JST.NameSupply nameSupply,
     Map <JST.Identifier, Expression> subst,
     Seq <Statement> statements,
     JST.Effects contextEffects,
     ISimplifierDatabase database,
     CSTWriter trace)
 {
     CompEnv             = compEnv;
     NameSupply          = nameSupply;
     this.subst          = subst;
     this.statements     = statements;
     this.contextEffects = contextEffects;
     Database            = database;
     Trace = trace;
 }
예제 #10
0
 protected SimplifierContext
     (bool inGlobalScope,
     bool keepFunctionNames,
     NameSupply nameSupply,
     Map <Identifier, Expression> subst,
     Seq <Statement> statements,
     Effects contextEffects,
     Func <Expression, bool> isValue)
 {
     InGlobalScope       = inGlobalScope;
     KeepFunctionNames   = keepFunctionNames;
     NameSupply          = nameSupply;
     this.subst          = subst;
     this.statements     = statements;
     this.contextEffects = contextEffects;
     this.isValue        = isValue;
 }
예제 #11
0
 protected SimplifierContext
     (CompilationEnvironment compEnv,
      JST.NameSupply nameSupply,
      Map<JST.Identifier, Expression> subst,
      Seq<Statement> statements,
      JST.Effects contextEffects,
      ISimplifierDatabase database,
      CSTWriter trace)
 {
     CompEnv = compEnv;
     NameSupply = nameSupply;
     this.subst = subst;
     this.statements = statements;
     this.contextEffects = contextEffects;
     Database = database;
     Trace = trace;
 }
예제 #12
0
 protected SimplifierContext
     (bool inGlobalScope,
      bool keepFunctionNames,
      NameSupply nameSupply,
      Map<Identifier, Expression> subst,
      Seq<Statement> statements,
      Effects contextEffects,
      Func<Expression, bool> isValue)
 {
     InGlobalScope = inGlobalScope;
     KeepFunctionNames = keepFunctionNames;
     NameSupply = nameSupply;
     this.subst = subst;
     this.statements = statements;
     this.contextEffects = contextEffects;
     this.isValue = isValue;
 }