Ejemplo n.º 1
0
        void DefinePrototype(AvmTypeCode type, AbcMethod sig)
        {
            var srcmethod = sig.Method;

            if (srcmethod == null)
            {
                return;
            }

            string key = GetKey(type, srcmethod.Name);
            var    val = _prototypes[key] as object[];

            if (val == null)
            {
                return;
            }

            var m = val[1] as AbcMethod;

            if (m != null)
            {
                return;
            }

            var coder = val[0] as AbcCoder;

            m = Abc.DefineMethod(Sig.@from(sig), coder);

            _generator.NewApi.SetProtoFunction(type, sig.TraitName, m);

            val[0] = m;
        }
Ejemplo n.º 2
0
 private AbcMethod DefineString_GetTypeId()
 {
     return(Abc.DefineMethod(
                Sig.@global(AvmTypeCode.Int32),
                code =>
     {
         code.PushTypeId(SystemTypes.String);
         code.ReturnValue();
     }));
 }
Ejemplo n.º 3
0
        private void ConvertImpl(IMethod method)
        {
            var m = method.AbcMethod();

            if (m == null)
            {
                return;
            }

            string name = method.Name;

            if (name == "ToString")
            {
                var impl = Abc.DefineMethod(
                    Sig.@global(AvmTypeCode.String),
                    code => code.ReturnThis());

                _generator.NewApi.SetProtoFunction(AvmTypeCode.String, m.TraitName, impl);
                return;
            }

            if (name == "GetTypeCode")
            {
                Impl(method,
                     code =>
                {
                    code.PushInt(18);
                    code.ReturnValue();
                });
                return;
            }

            Impl(method,
                 code =>
            {
                var convertInstance = _generator.Corlib.Convert.Instance;
                var convertMethod   = FindConvertImpl(method);
                var impl            = _generator.MethodBuilder.BuildAbcMethod(convertMethod);

                code.Getlex(convertInstance);
                code.GetLocals(0, method.Parameters.Count);
                code.Call(impl);
                code.ReturnValue();
            });
        }
Ejemplo n.º 4
0
        private void DefineScript(AbcInstance instance)
        {
            var script = new AbcScript();

            Abc.Scripts.Add(script);

            script.DefineClassTraits(instance);

            script.Initializer = Abc.DefineMethod(
                Sig.@void(),
                code =>
            {
                code.PushThisScope();

                if (IsSwc && instance.Type.Is(SystemTypeCode.Object))
                {
                    code.AddRange(_generator.NewApi);
                }

                var list = GetBaseTypesWithCctors(instance);

                const int arr = 1;
                code.Add(InstructionCode.Newarray, 0);
                code.SetLocal(arr);

                _generator.StaticCtors.DelayCalls(code, list, arr);
                code.InitClassProperties(script);
                _generator.StaticCtors.UndelayCalls(code, list, arr);

                //code.Trace("Initialization of " + instance.FullName);

                _generator.StaticCtors.Call(code, instance);
                _generator.StaticCtors.CallRange(code, list);

                code.ReturnVoid();
            }
                );
        }