Esempio n. 1
0
        public override Cell Simplify(SimplifierContext ctxt)
        {
            var simpArray = Array.Simplify(ctxt);
            var simpIndex = Index.Simplify(ctxt);

            return(new ElementCell(simpArray, simpIndex, isReadOnly));
        }
Esempio n. 2
0
 public override Cell Simplify(SimplifierContext ctxt)
 {
     if (Object == null)
     {
         return(this);
     }
     else
     {
         var simpObject = Object.Simplify(ctxt);
         return(new FieldCell(simpObject, Field));
     }
 }
Esempio n. 3
0
 public CSTMethod Simplify(SimplifierContext ctxt)
 {
     return(new CSTMethod(CompEnv, Body.Simplify(ctxt)));
 }
Esempio n. 4
0
        private JST.FunctionExpression NormalMethod(CST.CSTWriter trace)
        {
            var cstmethod = CST.CSTMethod.Translate(methEnv, nameSupply, trace);
            var methCompEnv = MethodCompilerEnvironment.EnterMethod
                (env, outerNameSupply, nameSupply, rootId, assemblyId, typeDefinitionId, cstmethod.CompEnv, parent.TypeTrace);

            var simpCtxt = new CST.SimplifierContext(methCompEnv, nameSupply, this, trace);
            cstmethod = cstmethod.Simplify(simpCtxt);

            if (trace != null)
                trace.Trace("After simplification of intermediate representation", w2 => cstmethod.Append(w2));

            var usage = cstmethod.Body.Usage(methCompEnv);

            // Bind all type and value parameters
            var parameters = new Seq<JST.Identifier>();
            var body = new Seq<JST.Statement>();

            foreach (var id in methCompEnv.TypeBoundTypeParameterIds)
                parameters.Add(id);
            foreach (var id in methCompEnv.MethodBoundTypeParameterIds)
                parameters.Add(id);

            var delta = env.InteropManager.IsFactory(methCompEnv.Assembly, methCompEnv.Type, methCompEnv.Method) ? 1 : 0;
            for (var i = delta; i < methCompEnv.Method.Arity; i++)
            {
                var id = methCompEnv.ValueParameterIds[i];
                if (i == 0 && !methCompEnv.Method.IsStatic && methCompEnv.Type.Arity == 0)
                {
                    // Only instance methods of first-kinded types use 'this' for their first argument
                    if (usage.Variables.ContainsKey(id))
                        body.Add(JST.Statement.Var(id, new JST.ThisExpression()));
                }
                else
                    parameters.Add(id);
            }

            // Introduce the top level bindings based on usage
            methCompEnv.BindUsage(body, usage);

            // Introduce shared assembly/type/pointer bindings based on usage
            if (env.DebugMode)
                body.Add(new JST.CommentStatement("Locals"));
            var uninit = new Seq<JST.Identifier>();
            foreach (var kv in usage.Variables)
            {
                var v = methCompEnv.Variable(kv.Key);
                if (v.ArgLocal == CST.ArgLocal.Local)
                {
                    if (methCompEnv.Method.IsInitLocals && v.IsInit)
                        body.Add
                            (JST.Statement.Var(v.Id, env.JSTHelpers.DefaultExpressionForType(methCompEnv, v.Type)));
                    else
                        uninit.Add(v.Id);
                }
            }
            if (uninit.Count > 0)
                body.Add(new JST.VariableStatement(uninit.Select(id => new JST.VariableDeclaration(id)).ToSeq()));

            // Translate body to JavaScript statements/expressions
            foreach (var s in cstmethod.Body.Body)
                TranslateStatement(methCompEnv, body, s);

            var func = new JST.FunctionExpression(methCompEnv.MethodId, parameters, new JST.Statements(body));

            if (trace != null)
                trace.Trace
                    ("After translation to JavaScript",
                     w =>
                         {
                             func.Append(w);
                             w.EndLine();
                         });

            return func;
        }
Esempio n. 5
0
 public override Cell Simplify(SimplifierContext ctxt)
 {
     return(this);
 }
Esempio n. 6
0
 public abstract Cell Simplify(SimplifierContext ctxt);
Esempio n. 7
0
        public override Cell Simplify(SimplifierContext ctxt)
        {
            var simpBox = Box.Simplify(ctxt);

            return(new BoxCell(simpBox, ValueType));
        }
Esempio n. 8
0
 public override Cell Simplify(SimplifierContext ctxt)
 {
     return(ctxt.ApplyCell(Id));
 }