示例#1
0
文件: Type.cs 项目: clearz/IonDotNet
        Type *type_incomplete(Sym *sym)
        {
            var type = type_alloc(TYPE_INCOMPLETE);

            type->sym = sym;
            return(type);
        }
示例#2
0
文件: Type.cs 项目: clearz/IonDotNet
        Type *type_enum(Sym *sym, Type * @base)
        {
            Type *type = type_alloc(TYPE_ENUM);

            type->sym   = sym;
            type->@base = @base;
            type->size  = type_int->size;
            type->align = type_int->align;
            return(type);
        }
示例#3
0
        int ion_main(string[] args)
        {
            if (args.Length == 0)
            {
                return(usage());
            }
            init_target_names();
            var package_name = args[0];

            if (!parse_env_vars(args))
            {
                return(usage());
            }

            initialise();
            if (flag_verbose)
            {
                printf("Target operating system: {0}\n", os_names[(int)target_os]);
                printf("Target architecture: {0}\n", arch_names[(int)target_arch]);
            }

            builtin_package = import_package("builtin".ToPtr());
            if (builtin_package == null)
            {
                error_here("Failed to compile package 'builtin'.\n");
            }
            builtin_package->external_name = _I("");
            enter_package(builtin_package);
            postinit_builtin();
            Sym *any_sym = resolve_name(_I("any"));

            if (any_sym == null || any_sym->kind != SymKind.SYM_TYPE)
            {
                printf("error: Any type not defined");
                return(1);
            }
            type_any = any_sym->type;
            leave_package(builtin_package);
            fixed(char *c = package_name)
            for (char *ptr = c; *ptr != '\0'; ptr++)
            {
                if (*ptr == '.')
                {
                    *ptr = '/';
                }
            }

            Package *main_package = import_package(package_name.ToPtr());

            if (main_package == null)
            {
                error_here("Failed to compile package '{0}'\n", package_name);
            }
            char *main_name = _I("main");
            Sym * main_sym  = get_package_sym(main_package, main_name);

            if (!flag_raw_code)
            {
                if (main_sym == null)
                {
                    error_here("No 'main' entry point defined in package '{0}'\n", package_name);
                }
                main_sym->external_name = main_name;
                resolve_sym(main_sym);
            }
            reachable_phase = REACHABLE_NATURAL;

            for (int i = 0; i < package_list->count; i++)
            {
                var pkg = package_list->Get <Package>(i);
                if (pkg->always_reachable)
                {
                    resolve_package_syms(pkg);
                }
            }
            finalize_reachable_syms();
            if (flag_verbose)
            {
                printf("Reached {0} symbols in {1} packages from {2}/main\n", reachable_syms->count, package_list->count, package_name);
            }
            if (!flag_lazy)
            {
                reachable_phase = REACHABLE_FORCED;
                for (int i = 0; i < package_list->count; i++)
                {
                    var pkg = package_list->Get <Package>(i);
                    resolve_package_syms(pkg);
                }
                finalize_reachable_syms();
            }

            printf("Processed {0} symbols in {1} packages\n", reachable_syms->count, package_list->count);

            if (!flag_check)
            {
                printf("Generating {0}\n", output_name);
                gen_all();

                output_name = output_name ?? $"out_{package_name}.c";

                try {
                    File.WriteAllText(output_name, gen_buf.ToString());
                }
                catch {
                    printf("error: Failed to write file: {0}\n", output_name);
                    return(1);
                }
            }
            printf("Intern: {0:0.00} MB\n", (float)Intern.intern_memory_usage / (1024 * 1024));
            printf("Source: {0:0.00} MB\n", (float)source_memory_usage / (1024 * 1024));
            printf("AST:    {0:0.00} MB\n", (float)ast_memory_usage / (1024 * 1024));
            printf("Ratio:  {0:0.00}\n", (float)(Intern.intern_memory_usage + ast_memory_usage) / source_memory_usage);
            return(0);
        }