## process-mythryl-primordial-library.pkg
## (C) 1999 Lucent Technologies, Bell Laboratories
## Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)
# Compiled by:
#
src/app/makelib/makelib.sublib# This file handles parsing and processing of
#
# src/lib/core/init/init.cmi
#
# the primordial .lib file which defines the life-critical
# stuff which has to exist before anything else can be
# done.
#
# * Build a simple dependency graph from a direct DAG description.
#
# - This is used in the bootstrap compiler to establish the
# pervasive dictionary and the primitives which later
# get used by the rest of the system.
#
# - One important job is to set up a naming to "package _Core".
#
# - For more info, see the comments in
# src/lib/core/init/init.cmi
#
# RUNTIME INVOCATION
# We have one entrypoint 'process_mythryl_primordial_library' which is
# invoked exactly once, by make_compile in
#
#
src/app/makelib/mythryl-compiler-compiler/mythryl-compiler-compiler-g.pkg # anchor_dictionary is from
src/app/makelib/paths/anchor-dictionary.pkg # makelib_state is from
src/app/makelib/main/makelib-state.pkg # intra_library_dependency_graph is from
src/app/makelib/depend/intra-library-dependency-graph.pkg # sourcecode_info is from
src/lib/compiler/front/basics/source/sourcecode-info.pkg # error_message is from
src/lib/compiler/front/basics/errormsg/error-message.pkg # global_controls is from
src/lib/compiler/toplevel/main/global-controls.pkgstipulate
package ad = anchor_dictionary; # anchor_dictionary is from
src/app/makelib/paths/anchor-dictionary.pkg package err = error_message; # error_message is from
src/lib/compiler/front/basics/errormsg/error-message.pkg package fil = file__premicrothread; # file__premicrothread is from
src/lib/std/src/posix/file--premicrothread.pkg package inl = global_controls::inline; # global_controls is from
src/lib/compiler/toplevel/main/global-controls.pkg package sci = sourcecode_info; # sourcecode_info is from
src/lib/compiler/front/basics/source/sourcecode-info.pkg package sm = line_number_db; # line_number_db is from
src/lib/compiler/front/basics/source/line-number-db.pkg package sg = intra_library_dependency_graph; # intra_library_dependency_graph is from
src/app/makelib/depend/intra-library-dependency-graph.pkg package tlt = thawedlib_tome; # thawedlib_tome is from
src/app/makelib/compilable/thawedlib-tome.pkgherein
package process_mythryl_primordial_library
: Process_Mythryl_Primordial_Library # Process_Mythryl_Primordial_Library is from
src/app/makelib/mythryl-compiler-compiler/process-mythryl-primordial-library.api {
fun process_mythryl_primordial_library
#
(makelib_state: makelib_state::Makelib_State)
#
mythryl_primordial_library # "$ROOT/src/lib/core/init/init.cmi"
=
{
anchor_dictionary = makelib_state.makelib_session.anchor_dictionary;
plaint_sink = makelib_state.plaint_sink;
library_source_index = makelib_state.library_source_index;
path_root = ad::dir mythryl_primordial_library;
fil::say {.
cat [
" process-mythryl-primordial-library.pkg: Reading file ",
ad::abbreviate (ad::os_string' mythryl_primordial_library)
];
};
# See if string is defined in the makelib preprocessor
# symbol dictionary -- see
#
#
src/app/makelib/main/makelib-preprocessor-state-g.pkg #
fun defined (symbol: String)
=
not_null ((makelib_state.makelib_session.find_makelib_preprocessor_symbol symbol).get ());
safely::do
{
open_it => {. fil::open_for_read (ad::os_string mythryl_primordial_library); },
close_it => fil::close_input,
cleanup => \\ _ = ()
}
{. source = sci::make_sourcecode_info
{
file_name => ad::os_string mythryl_primordial_library,
line_num => 1,
source_stream => #stream,
is_interactive => FALSE,
error_consumer => plaint_sink
};
line_number_db = source.line_number_db;
library_source_index::register
library_source_index
(mythryl_primordial_library, source);
fun error r m
=
err::error
source
r
err::ERROR
m
err::null_error_body;
fun line_in pos
=
{ fun is_separator_char c
=
char::is_space c or # char is from
src/lib/std/char.pkg char::contains "(),=;" c;
sub = string::get_byte_as_char; # string is from
src/lib/std/string.pkg null = list::null; # list is from
src/lib/std/src/list.pkg fun return (pos, line)
=
THE (string::tokens is_separator_char line, pos);
fun loop (pos, NULL, [] )
=>
NULL;
loop (pos, NULL, lines)
=>
return (pos, cat (reverse lines));
loop (pos, THE line, lines)
=>
{
len = size line;
newpos = pos + len;
# Does line end with backslash?
line_is_continued
=
len >= 2 and
sub (line, len - 1) == '\n' and
sub (line, len - 2) == '\\';
line_number_db::newline line_number_db newpos;
if line_is_continued
#
loop (newpos, fil::read_line #stream,
substring (line, 0, len - 2) ! lines);
else
if (null lines and sub (line, 0) == '#')
#
THE ([], newpos);
else
return (newpos, cat (reverse (line ! lines)));
fi;
fi;
};
end;
loop (pos, fil::read_line #stream, []);
};
fun loop (crossmodule_inlining_aggressiveness, m, pos)
=
case (line_in pos)
#
NULL =>
{ error (pos, pos) "unexpected end of file";
NULL;
};
#
THE (line, newpos)
=>
{ error = error (pos, newpos);
#
fun sml (file_path, crossmodule_inlining_aggressiveness, extra_static_compile_dictionary, is_runtime_package, ecs)
=
{ p = ad::file
(ad::from_standard'
{ anchor_dictionary,
plaint_sink => error
}
{ path_root,
file_path
}
);
attributes
=
{ is_runtime_package,
extra_static_compile_dictionary,
#
crossmodule_inlining_aggressiveness,
#
explicit_core_symbol => ecs,
noguid => FALSE
};
tlt::make_thawedlib_tome'
attributes
makelib_state
{
sourcepath => p,
library => (mythryl_primordial_library, (pos, newpos)),
sharing_request => sharing_mode::DONT_CARE,
pre_compile_code => NULL,
postcompile_code => NULL,
is_local => FALSE,
controllers => [] # 2009-06-21 CrT: was [overload_controller]
};
};
fun bogus n
=
sg::THAWEDLIB_TOME_TIN
{
near_imports => [],
far_imports => [],
thawedlib_tome => sml (n, inl::use_default, NULL, FALSE, NULL)
};
fun get n
=
case (string_map::get (m, n))
#
THE x => x;
#
NULL => { error ("undefined: " + n);
bogus n;
};
esac;
fun node (name, file, args, is_runtime_package, ecs)
=
{ fun one (arg, (near_imports, needs_primenv))
=
if (arg == "primitive") (near_imports, TRUE);
else (get arg ! near_imports, needs_primenv);
fi;
(fold_backward one ([], FALSE) args)
->
(near_imports, needs_base_types_and_ops_symbolmapstack);
extra_static_compile_dictionary
=
if needs_base_types_and_ops_symbolmapstack THE base_types_and_ops::base_types_and_ops_symbolmapstack;
else NULL;
fi;
thawedlib_tome
=
sml (file, crossmodule_inlining_aggressiveness, extra_static_compile_dictionary, is_runtime_package, ecs);
n = sg::THAWEDLIB_TOME_TIN
{
thawedlib_tome,
near_imports,
far_imports => []
};
loop (crossmodule_inlining_aggressiveness, string_map::set (m, name, n), newpos);
};
looksb = sg::TOME_IN_THAWEDLIB o get;
fun split_it args
=
{ fun invalid ()
=
{ error "invalid inlining spec";
inl::use_default;
};
case args
[] => inl::use_default;
[x] => case (lsplit_arg::arg x)
THE ls => ls;
NULL => invalid ();
esac;
_ => invalid ();
esac;
};
fun proc [] => loop (crossmodule_inlining_aggressiveness, m, newpos);
proc ("split" ! arg) => loop (split_it arg, m, newpos); # XXX BUGGO FIXME split -> inlining please
proc ["nosplit"] => loop (inl::suggest NULL, m, newpos); # XXX BUGGO FIXME nosplit -> noinlining please
# The "runtime-system-placeholder" case implements
# part of the mechanism which allows Lib7 code
# to call functions in the C-coded runtime.
# For more info, see the comments in
#
src/lib/core/init/runtime.pkg proc ("runtime-system-placeholder" ! name ! file ! args) => node (name, file, args, TRUE, NULL);
proc ("bind" ! name ! file ! args) => node (name, file, args, FALSE, NULL);
proc ("bind-core" ! ecs ! name ! file ! args) => node (name, file, args, FALSE, THE (symbol::make_package_symbol ecs));
proc ("return" ! pervasive ! prims) => THE { pervasive => looksb pervasive,
others => map looksb prims,
source_code => source
};
proc ("ifdef" ! symbol ! line) => proc (if (defined symbol) line; else []; fi);
proc ("ifndef" ! symbol ! line) => proc (if (defined symbol) []; else line; fi);
proc _ => { error "malformed line"; NULL;};
end;
proc line;
};
esac;
loop (inl::use_default, string_map::empty, 1);
};
}; # fun process_mythryl_primordial_library
}; # package primordial_library
end;