public void EmitCachedValues (IAstEmitter astEmitter, TypeExpressionCacher typeCacher, SignatureCacher signatureCacher, BaseMethodCacher baseMethodCacher) { var cts = typeCacher.CachedTypes.Values.OrderBy((ct) => ct.Index).ToArray(); if (cts.Length > 0) { foreach (var ct in cts) { Formatter.WriteRaw("var $T{0:X2} = function () ", ct.Index); Formatter.OpenBrace(); Formatter.WriteRaw("return ($T{0:X2} = JSIL.Memoize(", ct.Index); Formatter.Identifier(ct.Type, astEmitter.ReferenceContext, false); Formatter.WriteRaw(")) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } var css = signatureCacher.Global.Signatures.OrderBy((cs) => cs.Value).ToArray(); if (css.Length > 0) { foreach (var cs in css) { Formatter.WriteRaw("var $S{0:X2} = function () ", cs.Value); Formatter.OpenBrace(); Formatter.WriteRaw("return ($S{0:X2} = JSIL.Memoize(", cs.Value); Formatter.Signature(cs.Key.Method, cs.Key.Signature, astEmitter.ReferenceContext, cs.Key.IsConstructor, false); Formatter.WriteRaw(")) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } var bms = baseMethodCacher.CachedMethods.Values.OrderBy((ct) => ct.Index).ToArray(); if (bms.Length > 0) { foreach (var bm in bms) { Formatter.WriteRaw("var $BM{0:X2} = function () ", bm.Index); Formatter.OpenBrace(); Formatter.WriteRaw("return ($BM{0:X2} = JSIL.Memoize(", bm.Index); Formatter.WriteRaw("Function.call.bind("); Formatter.Identifier(bm.Method.Reference, astEmitter.ReferenceContext, true); Formatter.WriteRaw("))) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } var cims = signatureCacher.Global.InterfaceMembers.OrderBy((cim) => cim.Value).ToArray(); if (cims.Length > 0) { foreach (var cim in cims) { Formatter.WriteRaw("var $IM{0:X2} = function () ", cim.Value); Formatter.OpenBrace(); Formatter.WriteRaw("return ($IM{0:X2} = JSIL.Memoize(", cim.Value); Formatter.Identifier(cim.Key.InterfaceType, astEmitter.ReferenceContext, false); Formatter.Dot(); Formatter.Identifier(cim.Key.InterfaceMember, EscapingMode.MemberIdentifier); Formatter.WriteRaw(")) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } if ((cts.Length > 0) || (css.Length > 0)) Formatter.NewLine(); }
public void EmitCachedValues (IAstEmitter astEmitter, TypeExpressionCacher typeCacher, SignatureCacher signatureCacher, BaseMethodCacher baseMethodCacher) { var cts = typeCacher.CachedTypes.Values.OrderBy((ct) => ct.Index).ToArray(); if (cts.Length > 0) { foreach (var ct in cts) { Formatter.WriteRaw("var $T{0:X2} = function () ", ct.Index); Formatter.OpenBrace(); Formatter.WriteRaw("return ($T{0:X2} = JSIL.Memoize(", ct.Index); Formatter.Identifier(ct.Type, astEmitter.ReferenceContext, false); Formatter.WriteRaw(")) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } var css = signatureCacher.Global.Signatures.OrderBy((cs) => cs.Value).ToArray(); if (css.Length > 0) { foreach (var cs in css) { if (cs.Key.RewritenGenericParametersCount == 0) { Formatter.WriteRaw("var $S{0:X2} = function () ", cs.Value); Formatter.OpenBrace(); Formatter.WriteRaw("return ($S{0:X2} = JSIL.Memoize(", cs.Value); Formatter.Signature(cs.Key.Method, cs.Key.Signature, astEmitter.ReferenceContext, cs.Key.IsConstructor, false, true); Formatter.WriteRaw(")) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } else { Formatter.WriteRaw("var $S{0:X2} = function ", cs.Value); Formatter.LPar(); Formatter.CommaSeparatedList( Enumerable.Range(1, cs.Key.RewritenGenericParametersCount).Select(item => "arg" + item), astEmitter.ReferenceContext, ListValueType.Raw); Formatter.RPar(); Formatter.Space(); Formatter.OpenBrace(); Formatter.WriteRaw("return JSIL.MemoizeTypes($S{0:X2}, function() {{return ", cs.Value); Formatter.Signature(cs.Key.Method, cs.Key.Signature, astEmitter.ReferenceContext, cs.Key.IsConstructor, false, true); Formatter.WriteRaw(";}"); Formatter.Comma(); Formatter.OpenBracket(); Formatter.CommaSeparatedList( Enumerable.Range(1, cs.Key.RewritenGenericParametersCount).Select(item => "arg" + item), astEmitter.ReferenceContext, ListValueType.Raw); Formatter.CloseBracket(); Formatter.WriteRaw(")"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } } var bms = baseMethodCacher.CachedMethods.Values.OrderBy((ct) => ct.Index).ToArray(); if (bms.Length > 0) { foreach (var bm in bms) { Formatter.WriteRaw("var $BM{0:X2} = function () ", bm.Index); Formatter.OpenBrace(); Formatter.WriteRaw("return ($BM{0:X2} = JSIL.Memoize(", bm.Index); Formatter.WriteRaw("Function.call.bind("); Formatter.Identifier(bm.Method.Reference, astEmitter.ReferenceContext, true); Formatter.WriteRaw("))) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } var cims = signatureCacher.Global.InterfaceMembers.OrderBy((cim) => cim.Value).ToArray(); if (cims.Length > 0) { foreach (var cim in cims) { if (cim.Key.RewritenGenericParametersCount == 0) { Formatter.WriteRaw("var $IM{0:X2} = function () ", cim.Value); Formatter.OpenBrace(); Formatter.WriteRaw("return ($IM{0:X2} = JSIL.Memoize(", cim.Value); Formatter.Identifier(cim.Key.InterfaceType, astEmitter.ReferenceContext, false); Formatter.Dot(); Formatter.Identifier(cim.Key.InterfaceMember, EscapingMode.MemberIdentifier); Formatter.WriteRaw(")) ()"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } else { Formatter.WriteRaw("var $IM{0:X2} = function ", cim.Value); Formatter.LPar(); Formatter.CommaSeparatedList( Enumerable.Range(1, cim.Key.RewritenGenericParametersCount).Select(item => "arg" + item), astEmitter.ReferenceContext, ListValueType.Raw); Formatter.RPar(); Formatter.Space(); Formatter.OpenBrace(); Formatter.WriteRaw("return JSIL.MemoizeTypes($IM{0:X2}, function() {{return ", cim.Value); Formatter.Identifier(cim.Key.InterfaceType, astEmitter.ReferenceContext, false); Formatter.Dot(); Formatter.Identifier(cim.Key.InterfaceMember, EscapingMode.MemberIdentifier); Formatter.WriteRaw(";}"); Formatter.Comma(); Formatter.OpenBracket(); Formatter.CommaSeparatedList( Enumerable.Range(1, cim.Key.RewritenGenericParametersCount).Select(item => "arg" + item), astEmitter.ReferenceContext, ListValueType.Raw); Formatter.CloseBracket(); Formatter.WriteRaw(")"); Formatter.Semicolon(true); Formatter.CloseBrace(false); Formatter.Semicolon(true); } } } if ((cts.Length > 0) || (css.Length > 0)) Formatter.NewLine(); }
public void EmitCachedValues(IAstEmitter astEmitter, TypeExpressionCacher typeCacher, SignatureCacher signatureCacher, BaseMethodCacher baseMethodCacher) { }