## inlining-junk.pkg
## (C) 2001 Lucent Technologies, Bell Labs
#
# The Mythryl compiler contains several sort of inlining.
# The oldest (and in practice currently most important) is
# the 'Baseop' ops defined in
#
#
src/lib/compiler/back/top/highcode/highcode-baseops.api#
# and then made available to application programmers via the 'inline' package in
#
#
src/lib/compiler/front/semantic/symbolmapstack/base-types-and-ops.pkg#
# and then the inline_t package in
#
#
src/lib/core/init/built-in.pkg#
# These are basic operations like addition, multiplication and fetch-from-vector
# which absolutely must expand into inline code if we are to produce decent quality
# native code, so we hardwire the inlining process.
#
# The first stage in this hardwired-inlining process is fun translate_variable_in_expression
#
#
src/lib/compiler/back/top/translate/translate-deep-syntax-to-lambdacode.pkg#
# Compiled by:
#
src/lib/compiler/core.sublib### "If I had eight hours to chop down a tree,
### I'd spend six sharpening my axe."
###
### -- Abraham Lincoln
stipulate
package err = error_message; # error_message is from
src/lib/compiler/front/basics/errormsg/error-message.pkg package id = inlining_data; # inlining_data is from
src/lib/compiler/front/typer-stuff/basics/inlining-data.pkg package hbo = highcode_baseops; # highcode_baseops is from
src/lib/compiler/back/top/highcode/highcode-baseops.pkg package tdt = type_declaration_types; # type_declaration_types is from
src/lib/compiler/front/typer-stuff/types/type-declaration-types.pkgherein
package inlining_junk
: (weak) Inlining_Junk # Inlining_Junk is from
src/lib/compiler/front/semantic/basics/inlining-junk.api {
fun bug s
=
err::impossible ("inlining_data: " + s);
exception BASEOP_WRAPPER (hbo::Baseop, tdt::Typoid);
Inlining_Data = id::Inlining_Data;
inline_baseop = id::LEAF o BASEOP_WRAPPER;
inline_list = id::LIST;
inline_nil = id::NIL;
fun case_inlining_data inlining_data { do_inline_baseop, do_inline_list, do_inline_nil } # Called from
src/lib/compiler/front/semantic/modules/generics-expansion-junk-parameter.pkg = # and
src/lib/compiler/front/semantic/pickle/pickler-junk.pkg case inlining_data
#
id::LEAF (BASEOP_WRAPPER x) => do_inline_baseop x; # This is where we extract the data/type we want from the potentially infinite range of stuff that could be stored here via the "exception hack".
id::LEAF _ => bug "bogus LEAF node";
#
id::LIST l => do_inline_list l;
id::NIL => do_inline_nil ();
esac;
fun print_inlining_data inlining_data
=
cat (loop (inlining_data, []))
where
fun loop (inlining_data, result)
=
case_inlining_data inlining_data
{
do_inline_baseop => \\ (p, _) = hbo::baseop_to_string p ! result,
do_inline_nil => \\ () = "<InlNo>" ! result,
#
do_inline_list => \\ [] => "{ }" ! result;
first ! rest => "{ " ! loop ( first,
fold_backward (\\ (x, a) = ", " ! loop (x, a))
("}" ! result)
rest
);
end
};
end;
fun get_inlining_data_for_prettyprinting inlining_data
=
case_inlining_data inlining_data
{
do_inline_baseop => \\ (baseop, typoid) = (hbo::baseop_to_string baseop, typoid), # We return baseop as String to allow use where hbo package is not visible.
do_inline_nil => \\ () = ("<id::NULL -- ignore wildcard>", tdt::WILDCARD_TYPOID),
do_inline_list => \\ _ = ("<id::LIST [...] -- ignore wildcard>", tdt::WILDCARD_TYPOID)
};
my _ = # Backpatch get_inlining_data_for_prettyprinting to inlining_data.
id::ref_get_inlining_data_for_prettyprinting # (We cannot move the fn there because inlining_data
:= # cannot see hbo::*.)
get_inlining_data_for_prettyprinting;
select_inlining_data = id::select;
is_baseop_info = id::is_simple;
fun is_callcc_baseop (id::LEAF (BASEOP_WRAPPER ((hbo::CALLCC
| hbo::CALL_WITH_CURRENT_CONTROL_FATE), _)))
=>
TRUE;
is_callcc_baseop _
=>
FALSE;
end;
fun is_pure_baseop (id::LEAF (BASEOP_WRAPPER (baseop, _)))
=>
is_pure baseop
where
fun is_pure hbo::CAST => TRUE;
is_pure _ => FALSE;
end;
# isPure = hbo::purePrimop
end;
is_pure_baseop _ => FALSE;
end;
make_baseop_inlining_data = inline_baseop;
make_inlining_data_list = inline_list;
null_inlining_data = inline_nil;
};
end;