internal JsClass CompileClass(IType type) { if (type == null || type.IsExcluded()) { return(null); } var klass = type.Data as JsClass; if (klass != null) { return(klass); } if (type.IsEnum && type.ValueType.IsInt64()) { CompileClass(type.ValueType); } var baseType = type.BaseType; var baseClass = CompileClass(baseType.Is(SystemTypeCode.ValueType) || type.IsEnum ? SystemTypes.Object : baseType); var ns = string.IsNullOrEmpty(type.Namespace) ? "$global" : type.Namespace; _program.DefineNamespace(ns); klass = new JsClass(type, baseType.Is(SystemTypeCode.ValueType) || type.IsString() ? null : baseClass); type.Data = klass; if (baseClass != null) { baseClass.Subclasses.Add(klass); } foreach (var iface in type.Interfaces) { JsInterface.Make(iface).Implementations.Add(klass); } _program.Add(klass); switch (type.TypeKind) { case TypeKind.Struct: JsStruct.CompileCopy(klass); break; case TypeKind.Delegate: JsDelegate.CreateInstanceImpl(klass); break; } CompileImpls(klass, type); return(klass); }
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); }