public AbcMethod FindClass() { var instance = _generator.Corlib.SystemType.Instance; return(instance.DefineMethod( Sig.@static(QName.PfxPackage("FindClass"), AvmTypeCode.Class, AvmTypeCode.Namespace, "ns", AvmTypeCode.String, "name"), code => { const int ns = 1; const int name = 2; code.GetLocal(ns); code.GetLocal(name); code.FindPropertyStrict(code.Abc.RuntimeQName); code.GetLocal(ns); code.GetLocal(name); code.GetRuntimeProperty(); code.CoerceClass(); code.ReturnValue(); })); }
/// <summary> /// Returns instance that stores reflection data for API builtin in target player (AVM, Flash, AIR). /// </summary> /// <returns></returns> private AbcInstance DefineReflectionInstance() { if (_instanceReflection != null) { return(_instanceReflection); } var name = Abc.DefineName(QName.PfxPackage("PlayerReflectionData")); _instanceReflection = Abc.DefineEmptyInstance(name, true); Abc.DefineScript(_instanceReflection); return(_instanceReflection); }
public AbcInstance Define(AbcTrait slot) { if (slot == null) { throw new ArgumentNullException("slot"); } //NOTE: VerifyError: Error #1026: Slot 1 exceeds slotCount=0 of Object //therefore we can not use Get/Set slots by slot_id. string name = "slot_ptr$" + slot.NameString; AbcInstance instance; if (_cache.TryGetValue(name, out instance)) { return(instance); } var abc = _generator.Abc; var instanceName = abc.DefineName(QName.PfxPackage(name)); instance = abc.DefineEmptyInstance(instanceName, false); _cache[name] = instance; var obj = instance.CreatePrivateSlot("_obj", AvmTypeCode.Object); instance.Initializer = abc.DefineTraitsInitializer(obj); instance.DefineMethod( Sig.ptr_get, code => { code.LoadThis(); code.GetProperty(obj); code.GetProperty(slot); code.ReturnValue(); }); instance.DefineMethod( Sig.ptr_set, code => { code.LoadThis(); code.GetProperty(obj); code.GetLocal(1); //value code.SetProperty(slot); code.ReturnVoid(); }); return(instance); }
private AbcInstance BuildInstance(IAssembly assembly) { var name = Abc.DefineName(QName.PfxPackage(assembly.Name + "$runtime")); var instance = Abc.Instances[name]; if (instance != null) { return(instance); } instance = Abc.DefineEmptyInstance(name, true); Abc.DefineScript(instance); return(instance); }
private AbcInstance DefineEnumSuperType(IType type) { if (!type.IsEnum) { throw new InvalidOperationException("type is not enum"); } var vtype = type.ValueType; var st = vtype.SystemType(); if (st == null) { throw new InvalidOperationException(string.Format("invalid enum type {0}", type.FullName)); } int index = GetEnumIndex(st); var instance = _enumSuperTypes[index]; if (instance != null) { return(instance); } var super = BuildInstance(type.BaseType); instance = _enumSuperTypes[index]; if (instance != null) { return(instance); } instance = new AbcInstance(true) { Name = Abc.DefineName(QName.PfxPackage(GetEnumName(st))), BaseTypeName = super.Name, BaseInstance = super, Initializer = Initializers.BuildDefaultInitializer(Abc, null) }; Abc.AddInstance(instance); instance.Class.Initializer = Abc.DefineEmptyMethod(); _enumSuperTypes[index] = instance; string name = Const.Boxing.Value; instance.CreateSlot(Abc.DefineName(QName.Global(name)), BuildMemberType(vtype)); //SetFlags(instance, type); return(instance); }
private AbcInstance Build() { var instanceName = _abc.DefineName(QName.PfxPackage("prop_ptr")); var instance = _abc.DefineEmptyInstance(instanceName, false); var obj = instance.CreatePrivateSlot("_obj", AvmTypeCode.Object); var ns = instance.CreatePrivateSlot("_ns", AvmTypeCode.Namespace); var name = instance.CreatePrivateSlot("_name", AvmTypeCode.String); instance.Initializer = _abc.DefineTraitsInitializer(obj, ns, name); instance.DefineMethod( Sig.ptr_get, code => { code.LoadThis(); code.GetProperty(obj); code.LoadThis(); code.GetProperty(ns); code.LoadThis(); code.GetProperty(name); code.GetRuntimeProperty(); code.ReturnValue(); }); instance.DefineMethod( Sig.ptr_set, code => { code.LoadThis(); code.GetProperty(obj); code.LoadThis(); code.GetProperty(ns); code.LoadThis(); code.GetProperty(name); code.GetLocal(1); //value code.SetRuntimeProperty(); code.ReturnVoid(); }); return(instance); }
private AbcInstance Build() { var abc = _generator.Abc; var instanceName = abc.DefineName(QName.PfxPackage("elem_ptr")); var instance = abc.DefineEmptyInstance(instanceName, false); var arrType = _generator.Corlib.Array.Instance; var arr = instance.CreatePrivateSlot("_arr", arrType); var index = instance.CreatePrivateSlot("_index", AvmTypeCode.Int32); instance.Initializer = abc.DefineTraitsInitializer(arr, index); instance.DefineMethod( Sig.ptr_get, code => { code.LoadThis(); code.GetProperty(arr); code.LoadThis(); code.GetProperty(index); code.GetArrayElem(false); code.ReturnValue(); }); instance.DefineMethod( Sig.ptr_set, code => { code.LoadThis(); code.GetProperty(arr); code.LoadThis(); code.GetProperty(index); code.GetLocal(1); //value code.SetArrayElem(false); code.ReturnVoid(); }); return(instance); }
private AbcInstance Build() { var name = _abc.DefineName(QName.PfxPackage("func_ptr")); var instance = _abc.DefineEmptyInstance(name, false); var getter = instance.CreatePrivateSlot("_getter", AvmTypeCode.Function); var setter = instance.CreatePrivateSlot("_setter", AvmTypeCode.Function); instance.Initializer = _abc.DefineTraitsInitializer(getter, setter); instance.DefineMethod( Sig.ptr_get, code => { code.LoadThis(); code.GetProperty(getter); code.PushNull(); code.CallFunction(1); //this code.ReturnValue(); }); instance.DefineMethod( Sig.ptr_set, code => { code.LoadThis(); code.GetProperty(setter); code.PushNull(); code.GetLocal(1); //value code.CallFunction(2); //this + value code.Pop(); code.ReturnVoid(); }); return(instance); }