private void InitSlotPtr(AbcCode code, VarPtr ptr) { GetActivation(code); if (AbcGenConfig.UseActivationTraits) { switch (ptr.Ptr.PtrKind) { case PointerKind.SlotPtr: code.CreateSlotPtr(ptr.Ptr, _activationVar); break; case PointerKind.PropertyPtr: code.CreatePropertyPtr(ptr.Slot.Name, () => GetActivation(code)); break; case PointerKind.FuncPtr: code.CreateFuncPtr(ptr.Slot); break; } } else { code.Getlex(ptr.Ptr.SlotType); GetActivation(code); code.Construct(1); } code.SetSlot(ptr.Ptr); }
public static void SetProperty_String_String(AbcCode code) { var vh = code.Generator.RuntimeImpl.ValueHolder; var value = vh.GetStaticSlot("value"); code.Getlex(vh); code.Swap(); code.SetSlot(value); code.FixRuntimeQName(); code.Getlex(vh); code.GetSlot(value); code.SetRuntimeProperty(); }
public static void exit(IMethod method, AbcCode code) { var m = code.Generator.RuntimeImpl.Exit(); code.Getlex(m); code.Call(m); }
public static void get_IsFlashPlayer(AbcCode code) { var m = code.Generator.RuntimeImpl.IsFlashPlayer(); code.Getlex(m); code.Call(m); }
private void LoadCtorReceiver(AbcCode code, IMethod method) { if (!method.IsConstructor) { throw new ArgumentException("method is not ctor", "method"); } var declType = method.DeclaringType; var vec = declType.Data as IVectorType; if (vec != null) { code.LoadGenericClass(vec.Name); return; } var nativeType = declType.Data as NativeType; if (nativeType != null) { code.Getlex(nativeType.Name); return; } var abcMethod = method.AbcMethod(); if (abcMethod == null) { throw new ArgumentException("Invalid method tag"); } var instance = DefineAbcInstance(declType); if (instance == null) { throw new InvalidOperationException(); } if (UseThisForStaticReceiver(declType)) { code.LoadThis(); return; } code.Getlex(instance); }
private bool PushKeyValue(string line, AbcCode code, ResourceBundleContext context) { if (string.IsNullOrEmpty(line)) { return(false); } line = line.Trim(); if (string.IsNullOrEmpty(line)) { return(false); } if (line.IsResourceBundleComment()) { return(false); } int sep = line.IndexOf('='); if (sep >= 0) { //TODO: process standard escape sequences string key = line.Substring(0, sep).Trim(); string value = line.Substring(sep + 1).Trim(); code.PushString(key); if (value.StartsWith(PrefixEmbed)) { var res = EmbedResource(context, value); code.Getlex(res); return(true); } if (value.StartsWith(PrefixClassReference)) { var cr = ResolveClassRef(value); code.Getlex(cr); return(true); } code.PushString(value); return(true); } //TODO: Is it warning or error? return(false); }
private void SetCalledFlag(AbcCode code, AbcInstance instance, bool value) { var f = CalledFlag(instance); code.Getlex(f.Instance); code.PushNativeBool(value); code.SetProperty(f); }
private void LoadStaticInstance(AbcCode code, IType type, AbcInstance instance) { if (instance.IsNative) { code.Getlex(instance.Name); return; } if (UseThisForStaticReceiver(type)) { code.LoadThis(); } else { code.Getlex(instance.Name); } }
public IEnumerable <IInstruction> LoadReceiver(IMethod method, bool newobj) { EnsureMethod(method); if (!HasReceiver(method, newobj)) { return(null); } var code = new AbcCode(_abc); CallStaticCtor(code, method); if (newobj) { LoadCtorReceiver(code, method); return(code); } if (LoadSpecReceiver(method, code)) { return(code); } var inlineCall = method.Data as InlineCall; if (inlineCall != null && inlineCall.TargetType != null) { code.Getlex(inlineCall.TargetType); return(code); } if (method.IsStaticCall()) { LoadStaticInstance(code, method.DeclaringType); return(code); } // TODO: check that code below is not needed now and remove it var mname = method.Data as AbcMultiname; if (mname != null) { code.FindPropertyStrict(mname); return(code); } //NOTE: //Primitive types should be boxed before calling of any instance method //But not here because object must be onto the stack. //And this operation must be controlled from the top level //if (TypeService.IsBoxablePrimitiveType(type)) //{ // BoxPrimitive(code, type, false); //} return(code); }
public static void SetProperty(AbcCode code) { // stack: name, value var vh = code.Generator.RuntimeImpl.ValueHolder; var value = vh.GetStaticSlot("value"); code.Getlex(vh); //after: name, value, vh code.Swap(); //after: name, vh, value code.SetSlot(value); code.PushGlobalPackage(); //after: name, ns code.Swap(); //ns, name code.Getlex(vh); code.GetSlot(value); code.SetRuntimeProperty(); }
public void Call(AbcCode code, AbcInstance instance) { var m = BuildCctorCaller(instance); if (m == null) { return; } code.Getlex(m); code.Call(m); }
public static void NewArray(IMethod method, AbcCode code) { if (method.Parameters.Count == 1) { //size is onto the stack code.Getlex(AvmTypeCode.Array); code.Swap(); code.Construct(1); code.CoerceArray(); return; } code.Add(InstructionCode.Newarray, 0); }
private void LoadGlobalReceiver(AbcCode code, IMethod method) { var type = method.DeclaringType; if (type.Data is GlobalFunctionsContainer) { var mn = GetMethodName(method); code.FindPropertyStrict(mn); return; } if (type.IsInternalType()) { string name = method.Name; var mn = _abc.DefineName(QName.Global(name)); code.FindPropertyStrict(mn); return; } if (type.Is(SystemTypeCode.String)) { code.Getlex(AvmTypeCode.String); return; } if (type.Is(AvmTypeCode.Class)) { if (method.Name == "Find") { var m = _generator.RuntimeImpl.FindClass(); code.Getlex(m); return; } } throw new InvalidOperationException(); }
/// <summary> /// Calls entry point (Main method). /// //NOTE: This method always adds return instruction /// </summary> /// <param name="code"></param> internal void CallEntryPoint(AbcCode code) { //Note: in swf entry point will be called in ctor of root sprite if (EntryPoint == null) { code.ReturnVoid(); return; } var main = EntryPoint.AbcMethod(); if (main == null) { throw new InvalidOperationException("Invalid entry point"); } code.Getlex(main); if (AbcGenConfig.ParameterlessEntryPoint) { code.Add(InstructionCode.Callpropvoid, main.TraitName, 0); code.ReturnVoid(); } else { //TODO: pass process args int n = EntryPoint.Parameters.Count; for (int i = 0; i < n; ++i) { //code.GetLocal(i + 1); code.PushNull(); } bool isVoid = EntryPoint.IsVoid(); if (isVoid || IsSwf) { code.Add(InstructionCode.Callpropvoid, main.Trait.Name, n); code.ReturnVoid(); } else { code.Add(InstructionCode.Callproperty, main.Trait.Name, n); code.ReturnValue(); } } }
private void RegisterRemoteClasses(AbcFile app, AbcCode code) { if (_remoteClasses.Count == 0) { return; } var registerClassAlias = app.DefineName(QName.Package("flash.net", "registerClassAlias")); foreach (var pair in _remoteClasses) { code.FindPropertyStrict(registerClassAlias); code.PushString(pair.Key); code.Getlex(pair.Value); code.CallVoid(registerClassAlias, 2); } }
void CallToException(AbcCode code, int var) { var avmErrors = Assembly.Corlib().FindType("AvmErrors"); if (avmErrors == null) { throw new InvalidOperationException(string.Format("Unable to find AvmErrors. Invalid corlib.")); } EnsureType(avmErrors); var fromError = avmErrors.Methods.Find("ExceptionFromError", 1); var m = DefineAbcMethod(fromError); code.Getlex(m); code.GetLocal(var); code.Call(m); }
private void RegisterEffectTriggers(AbcFile app, AbcCode code) { if (_effects.Count == 0) { return; } var effectManager = _compiler.ImportType(app, "mx.effects.EffectManager"); var mn = app.DefineName(QName.MxInternal("registerEffectTrigger")); foreach (var pair in _effects) { code.Getlex(effectManager); code.PushString(pair.Key); code.PushString(pair.Value); code.CallVoid(mn, 2); } }
private static void GetCurrentAppDomain(AbcCode code) { code.Getlex("flash.system", "ApplicationDomain"); code.GetProperty("currentDomain"); }