## print-as-nada-junk.pkg
# Compiled by:
#
src/lib/compiler/front/typer/typer.sublibstipulate
package pp = standard_prettyprinter; # standard_prettyprinter is from
src/lib/prettyprint/big/src/standard-prettyprinter.pkg package ip = inverse_path; # inverse_path is from
src/lib/compiler/front/typer-stuff/basics/symbol-path.pkg package sp = symbol_path; # symbol_path is from
src/lib/compiler/front/typer-stuff/basics/symbol-path.pkg #
Pp = pp::Pp;
herein
package print_as_nada_junk
: (weak) Print_As_Nada_Junk # Print_As_Nada_Junk is from
src/lib/compiler/front/typer/print/print-as-nada-junk.api {
package s: (weak) Symbol # Symbol is from
src/lib/compiler/front/basics/map/symbol.api = symbol; # symbol is from
src/lib/compiler/front/basics/map/symbol.pkg pps = pp::lit;
fun print_sequence0_as_nada pp (sep: pp::Prettyprinter -> Void, pr, elems)
=
{ fun pr_elems [el] => pr pp el;
pr_elems (el ! rest) =>
{ pr pp el;
sep pp;
pr_elems rest;};
pr_elems [] => (); end;
pr_elems elems;
};
Break_Style
=
CONSISTENT
| INCONSISTENT;
fun open_style_box style pp indent
=
case style
CONSISTENT => pp::open_box (pp, indent, pp::normal, 100 );
INCONSISTENT => pp::open_box (pp, indent, pp::ragged_right, 100 );
esac;
fun print_sequence_as_nada
pp
{ sep: pp::Prettyprinter -> Void,
pr: pp::Prettyprinter -> X -> Void,
style: Break_Style
}
(elems: List(X))
=
{ open_style_box style pp (pp::typ::CURSOR_RELATIVE { blanks => 1, tab_to => 0, tabstops_are_every => 4 });
print_sequence0_as_nada pp (sep, pr, elems);
pp::shut_box pp;
};
fun print_closed_sequence_as_nada
pp
{ front: pp::Prettyprinter -> Void,
sep: pp::Prettyprinter -> Void,
back: pp::Prettyprinter -> Void,
pr: pp::Prettyprinter -> X -> Void,
style: Break_Style
}
(elems: List(X))
=
{ pp::open_box (pp, pp::typ::BOX_RELATIVE { blanks => 1, tab_to => 0, tabstops_are_every => 4 }, pp::normal, 100 );
front pp;
open_style_box style pp (pp::typ::CURSOR_RELATIVE { blanks => 1, tab_to => 0, tabstops_are_every => 4 });
print_sequence0_as_nada pp (sep, pr, elems);
pp::shut_box pp;
back pp;
pp::shut_box pp;
};
fun print_symbol_as_nada pp (s: s::Symbol)
=
pp::lit pp (s::name s);
string_depth = control_print::string_depth;
heap_string = print_junk::heap_string;
fun print_lib7_string_as_nada pp = pp::lit pp o print_junk::print_heap_string;
fun print_integer_as_nada pp = pp::lit pp o print_junk::print_integer;
fun ppvseq pp ind (separator: String) pr elements
=
{ fun print_elements [element] => pr pp element;
print_elements (element ! rest) => { pr pp element;
pp::lit pp separator;
pp::newline pp;
print_elements rest;
};
print_elements [] => ();
end;
pp::open_box (pp, pp::typ::CURSOR_RELATIVE { blanks => 1, tab_to => 0, tabstops_are_every => 4 }, pp::normal, 100 ); # '4' was 'ind' before arg became a tabstop.
print_elements elements;
pp::shut_box pp;
};
fun ppvlist (pp:Pp) (header, separator, print_item, items)
=
case items
#
NIL => ();
first ! rest
=>
{ pp.lit header;
print_item pp first;
apply (\\ x = { pp.newline();
pp.lit separator;
print_item pp x;
}
)
rest;
};
esac;
fun ppvlist' (pp:Pp) (header, separator, print_item, items)
=
case items
#
NIL => ();
first ! rest
=>
{ print_item pp header first;
#
apply (\\ x = { pp.newline ();
print_item pp separator x;
}
)
rest;
};
esac;
# Debug print functions
fun print_int_path_as_nada pp
=
print_closed_sequence_as_nada
pp
{ front => \\ pp = pp.lit "[",
sep => \\ pp = pp.txt ", ",
back => \\ pp = pp.lit "]",
style => INCONSISTENT,
pr => \\ pp = pp.lit o int::to_string
};
fun print_symbol_path_as_nada pp (sp: symbol_path::Symbol_Path)
=
pp::lit pp (symbol_path::to_string sp);
fun print_inverse_path_as_nada pp (inverse_path::INVERSE_PATH path: inverse_path::Inverse_Path)
=
print_closed_sequence_as_nada
pp
{ front => \\ pp = pp.lit "<",
sep => \\ pp = pp.lit ".",
back => \\ pp = pp.lit ">",
style => INCONSISTENT,
pr => print_symbol_as_nada
}
path;
# find_path: Convert inverse symbolic path names
# to a printable string in the context
# of a dictionary.
#
# Its arguments are the inverse symbolic path, a check predicate on static
# semantic values, and a lookup function mapping paths to their namings
# (if any) in an dictionary and raising Dictionary::UNBOUND on paths with no
# naming.
#
# It looks up each suffix of the path name, going from shortest to longest
# suffix, in the current dictionary until it finds one whose lookup value
# satisfies the check predicate. It then converts that suffix to a string.
# If it doesn't find any suffix, the full path (reversed, i.e. in the
# normal order) and the boolean value FALSE are returned, otherwise the
# suffix and TRUE are returned.
#
# Example:
# Given a::B.t as a path, and a lookup function for an
# dictionary, this function tries:
# t
# b::t
# a::B.t
# If none of these work, it returns ?.a::B.t
#
# Note: the symbolic path is passed in reverse order because that is
# the way all symbolic path names are stored within static semantic chunks.
result_id = s::make_package_symbol "<result_package>";
return_id = s::make_package_symbol "<return_package>";
fun find_path (ip::INVERSE_PATH p: ip::Inverse_Path, check, get): ((List( s::Symbol ), Bool))
=
try (p, [])
where
fun try (name ! untried, tried)
=>
( if ((s::eq (name, result_id)) or (s::eq (name, return_id)))
#
try (untried, tried);
else
{ element = get (sp::SYMBOL_PATH (name ! tried));
#
if (check element) (name ! tried, TRUE);
else try (untried, name ! tried);
fi;
}
except
symbolmapstack::UNBOUND
=
try (untried, name ! tried);
fi
);
try([], tried) => (tried, FALSE);
end;
end;
fun print_int_as_nada (pp:Pp) (i: Int)
=
pp.lit (int::to_string i);
fun print_comma_as_nada (pp:Pp)
=
pp.txt ", ";
fun print_comma_newline_as_nada (pp:Pp)
=
{ print_comma_as_nada pp;
pp.newline();
};
fun newline_indent pp i
=
{ linewidth = 10000;
pp::break pp { blanks => linewidth, indent_on_wrap => i };
};
fun newline_apply pp f
=
{ fun g [] => ();
g [element] => f pp element;
g (element ! rest) => { f pp element; pp::newline pp; g rest;};
end;
g;
};
fun break_apply pp f
=
{ fun g [] => ();
g [el] => f pp el;
g (el ! rst) => { f pp el; pp::break pp { blanks=>1, indent_on_wrap=>0 }; g rst;};
end;
g;
};
fun print_array_as_nada pp (f: pp::Prettyprinter -> X -> Void, a: Rw_Vector(X))
=
pp.wrap' 0 -1 {. pp.rulename "pptw9";
loop 0 except exceptions::INDEX_OUT_OF_BOUNDS = ();
}
where
fun loop i
=
{ element = rw_vector::get (a, i);
#
pp.lit (int::to_string i);
pp.txt ": ";
f pp element;
pp.txt " ";
loop (i+1);
};
end;
fun by f x y
=
f y x;
fun print_tuple_as_mythrl7 pp f
=
print_closed_sequence_as_nada
pp
{ front => \\ pp = pp.lit "(",
sep => \\ pp = pp.txt ", ",
back => \\ pp = pp.lit ")",
pr => f,
style => INCONSISTENT
};
}; # package print_as_nada_junk
end;