private object OpLdtoken(MethodContext context, ITypeMember member) { var key = new InstructionKey(InstructionCode.Ldtoken, member); var var = context.Vars[key]; if (var != null) { return(var); } var field = member as IField; if (field != null) { if (field.IsArrayInitializer()) { var blob = field.GetBlob(); var arr = new JsArray(blob.ToArray().Select(x => (object)x)); return(context.Vars.Add(key, arr)); } throw new NotImplementedException(); } var type = member as IType; if (type != null) { CompileType(type); return(type.FullName); } throw new NotImplementedException(); }
private JsNode OpNewarr(MethodContext context, IType elemType) { var key = new InstructionKey(InstructionCode.Newarr, elemType); var var = context.Vars[key]; if (var != null) { return(var.Id()); } var type = RegisterArrayType(elemType); var elemInit = new JsFunction(null); elemInit.Body.Add(elemType.InitialValue().Return()); var info = new JsObject { { "init", elemInit }, { "type", type.FullName }, { "box", new BoxingImpl(this).Box(context, elemType) }, { "unbox", new BoxingImpl(this).Unbox(context, elemType) }, { "etc", elemType.JsTypeCode() }, }; var = context.Vars.Add(key, info); CompileClass(SystemTypes.Array); CompileType(elemType); return(var.Id()); }
private object OpLdftn(MethodContext context, Instruction i) { var method = i.Method; var key = new InstructionKey(i.Code, method); var info = context.Vars[key]; if (info != null) { return(info); } CompileCallMethod(method); var func = CreateCallFunc(context, method, i.CallInfo); return(context.Vars.Add(key, func)); }
private JsNode OpNewobj(MethodContext context, IMethod method) { var key = new InstructionKey(InstructionCode.Newobj, method); var data = context.Vars[key]; if (data != null) { return(data.Id()); } var args = "a".Id(); var func = new JsFunction(null, args.Value); var info = new JsObject { { "n", method.Parameters.Count }, { "f", func }, }; data = context.Vars.Add(key, info); CompileCallMethod(method); InitClass(context, func, method); if (method.IsConstructor && method.DeclaringType.IsString()) { func.Body.Add(method.Apply(null, args).Return()); } else { var obj = "o".Id(); func.Body.Add(method.DeclaringType.New().Var(obj.Value)); func.Body.Add(method.Apply(obj, args).AsStatement()); func.Body.Add(obj.Return()); } return(data.Id()); }
private JsNode OpInitobj(MethodContext context, IType type) { var key = new InstructionKey(InstructionCode.Initobj, type); var info = context.Vars[key]; if (info != null) { return(info.Id()); } var func = new JsFunction(null); info = context.Vars.Add(key, func); CompileClass(type); InitClass(context, func, type); func.Body.Add(type.New().Return()); return(info.Id()); }