private void NewObject(AbcCode code, IMethod method) { var type = method.DeclaringType; var abcMethod = method.AbcMethod(); if (abcMethod != null) { if (abcMethod.IsInitializer) //default ctor! { if (type.Is(AvmTypeCode.Object)) { code.NewObject(0); } else { code.Construct(method.Parameters.Count); } return; } if (type.Is(SystemTypeCode.String)) { code.Call(abcMethod); return; } var ctor = _generator.TypeBuilder.DefineCtorStaticCall(method); code.Call(ctor); } else { throw new NotImplementedException(); } }
public static void exit(IMethod method, AbcCode code) { var m = code.Generator.RuntimeImpl.Exit(); code.Getlex(m); code.Call(m); }
public IEnumerable <IInstruction> GetArrayLength() { var code = new AbcCode(_abc); code.Call(ArrayMethodId.GetLength); return(code); }
public static void CopyArray(AbcCode code) { var prop = code.Abc.DefineName(QName.Global("concat")); code.Call(prop, 0); code.Coerce(AvmTypeCode.Array); }
public static void get_IsFlashPlayer(AbcCode code) { var m = code.Generator.RuntimeImpl.IsFlashPlayer(); code.Getlex(m); code.Call(m); }
public static void CopyTo(IMethod method, AbcCode code) { code.LoadThis(); code.GetLocal(1); code.GetLocal(2); code.Call(ArrayMethodId.CopyTo); code.ReturnVoid(); }
private void CallInitStyles(AbcCode code, AbcInstance instance) { code.Trace("PFC: calling App.initStyles"); var initStyles = DefineInitFlexAppStyles(instance); code.LoadThis(); code.Call(initStyles); }
public static void Find_Namespace_String(AbcCode code) { //NOTE: VerifyError: Error #1078: Illegal opcode/multiname combination: 96<[]::[]>. //code.Getlex(code.abc.RuntimeQName); var m = code.Generator.RuntimeImpl.FindClass(); code.Call(m); }
public static void IndexOf(IMethod method, AbcCode code) { code.LoadThis(); var type = method.Parameters[0].Type; code.BoxVariable(type, 1); code.Call(ArrayMethodId.IndexOf); code.ReturnValue(); }
public void Call(AbcCode code, AbcInstance instance) { var m = BuildCctorCaller(instance); if (m == null) { return; } code.Getlex(m); code.Call(m); }
public static InlineCall Create(AbcFile abc, IMethod method, InlineMethodInfo info) { var code = new AbcCode(abc); var targetType = info.TargetType != null?info.TargetType.Define(abc) : null; var name = info.Name.Define(abc); switch (info.Kind) { case InlineKind.Property: if (method.IsSetter()) { code.SetProperty(name); } else { code.GetProperty(name); code.Coerce(method.Type, true); } break; case InlineKind.Operator: { int n = method.Parameters.Count; if (n <= 1) { throw new InvalidOperationException(); } var op = info.Op; for (int i = 1; i < n; ++i) { code.Add(op); } code.Coerce(method.Type, true); } break; default: if (method.IsVoid()) { code.CallVoid(name, method.Parameters.Count); } else { code.Call(name, method.Parameters.Count); code.Coerce(method.Type, true); } break; } return(new InlineCall(method, targetType, name, code)); }
private static void ToFlatIndex(AbcCode code, int n, bool getter) { code.LoadThis(); if (getter) { code.LoadArguments(n); code.Add(InstructionCode.Newarray, n); } else { //Last argument is a value code.GetLocals(1, n - 1); code.Add(InstructionCode.Newarray, n - 1); } code.Call(ArrayMethodId.ToFlatIndex); }
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 NewAttribute(AbcCode code, ICustomAttribute attr, int varAttr) { code.NewObject(attr.Constructor, () => { foreach (var arg in attr.FixedArguments()) { code.PushValue(code, arg.Value); } }); code.SetLocal(varAttr); //TODO: Set fields and properties foreach (var arg in attr.NamedArguments()) { code.GetLocal(varAttr); code.PushValue(code, arg.Value); if (arg.Kind == ArgumentKind.Field) { var field = arg.Member as IField; if (field == null) { throw new InvalidOperationException(); } code.SetField(field); } else { var prop = arg.Member as IProperty; if (prop == null) { throw new InvalidOperationException(); } var s = _generator.MethodBuilder.BuildAbcMethod(prop.Setter); code.Call(s); } } code.GetLocal(varAttr); }
public static void get_Count(IMethod method, AbcCode code) { code.LoadThis(); code.Call(ArrayMethodId.GetLength); code.ReturnValue(); }
private void BaseCall(AbcCode code, IType receiverType, IMethod method) { var m = DefineBaseCall(receiverType, method); code.Call(m); }
public IEnumerable <IInstruction> Branch(BranchOperator op, IType left, IType right) { if (op.IsUnary()) { if (op == BranchOperator.Null) { var code = new AbcCode(_abc); //NOTE: old code - not working with nullable types //code.PushNull(); //code.Add(InstructionCode.Ifeq); code.IsNull(left, right); code.Add(InstructionCode.Iftrue); return(code); } if (op == BranchOperator.NotNull) { var code = new AbcCode(_abc); //NOTE: old code - not working with nullable types //code.PushNull(); //code.Add(InstructionCode.Ifne); code.IsNull(left, right); code.Add(InstructionCode.Iffalse); return(code); } if (left.IsDecimalOrInt64()) { var code = new AbcCode(_abc); bool isTrue = op == BranchOperator.True; var abcOp = _generator.Operators.BuildBoolOp(left, isTrue); //TODO: Should we enshure not null value onto the stack??? //AbcMethod abcOp = _generator.DefineTruthOperator(left, isTrue); //code.LoadStaticReceiver(abcOp); //code.Swap(); code.Call(abcOp); code.Add(isTrue ? InstructionCode.Iftrue : InstructionCode.Iffalse); return(code); } } else if (InternalTypeExtensions.IsDecimalOrInt64(left, right)) { var code = new AbcCode(_abc); var opm = _generator.Operators.Build(op, left, right); code.Call(opm); code.Add(InstructionCode.Iftrue); return(code); } switch (op) { case BranchOperator.True: return(If(InstructionCode.Iftrue)); case BranchOperator.False: return(If(InstructionCode.Iffalse)); case BranchOperator.Equality: return(If(InstructionCode.Ifeq)); case BranchOperator.Inequality: return(If(InstructionCode.Ifne)); case BranchOperator.LessThan: return(If(InstructionCode.Iflt)); case BranchOperator.LessThanOrEqual: return(If(InstructionCode.Ifle)); case BranchOperator.GreaterThan: return(If(InstructionCode.Ifgt)); case BranchOperator.GreaterThanOrEqual: return(If(InstructionCode.Ifge)); default: throw new NotSupportedException(); } }