Beispiel #1
0
        /// <summary>
        /// new式のコンパイル
        /// </summary>
        /// <param name="ilgen">IL Generator</param>
        /// <param name="expr">new式</param>
        static void CompileNewExpr(ILGenerator ilgen, MNewExpr expr)
        {
            foreach (var arg in expr.Args)
            {
                CompileExpr(ilgen, arg);
            }

            ilgen.Emit(OpCodes.Newobj, expr.ConstructorInfo);
        }
Beispiel #2
0
        /// <summary>
        /// new式の型推論
        /// </summary>
        /// <param name="expr">new式</param>
        static void TypeinfNewExpr(MNewExpr expr)
        {
            foreach (var arg in expr.Args)
            {
                TypeinfExpr(arg);
            }

            var _runtime_dir = RuntimeEnvironment.GetRuntimeDirectory();
            var dll = Assembly.LoadFrom(Path.Combine(_runtime_dir, "mscorlib.dll"));
            var type = dll.GetType(expr.ClassName);

            var arg_types = new List<Type>();
            foreach (var arg in expr.Args)
            {
                arg_types.Add(arg.Type.Reduce());
            }
            var cstr = type.GetConstructor(arg_types.ToArray());

            expr.Type = new DotNetType(type);
            expr.ConstructorInfo = cstr;
        }