Beispiel #1
0
        public JsProgram Compile()
        {
            if (_program != null)
            {
                return(_program);
            }

            _program = new JsProgram();

            _program.Require("core.js");

            var entryPoint = _assembly.EntryPoint;
            var method     = CompileMethod(entryPoint);

            // system exceptions
            CompileClass(CorlibTypes[CorlibTypeId.NullReferenceException]);
            CompileClass(CorlibTypes[CorlibTypeId.InvalidCastException]);
            CompileClass(CorlibTypes[CorlibTypeId.NotImplementedException]);
            CompileClass(CorlibTypes[CorlibTypeId.IndexOutOfRangeException]);

            // build types
            CompileClass(SystemTypes.Type);


            new TypeInfoBuilder(this, _program).Build();

            //TODO: pass args to main from node.js args

            var ctx  = new MethodContext(this, CompileClass(entryPoint.DeclaringType), entryPoint, new TryCatchBlock[0]);
            var main = new JsFunction(null);

            InitClass(ctx, main, entryPoint);
            main.Body.Add(method.FullName.Id().Call().AsStatement());

            _program.Add(main.Call().AsStatement());

            return(_program);
        }
Beispiel #2
0
 public TypeInfoBuilder(JsCompiler host, JsProgram program)
 {
     _host    = host;
     _program = program;
 }