


## print-as-nada-junk.pkg
# Compiled by:
# src/lib/compiler/front/typer/typer.sublibpackage 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 package pp= prettyprint; # prettyprint is from src/lib/prettyprint/big/src/prettyprint.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 pps = pp::string;
fun print_sequence0_as_nada ppstream (sep: pp::Stream -> Void, pr, elems)
=
{ fun pr_elems [el] => pr ppstream el;
pr_elems (el ! rest) =>
{ pr ppstream el;
sep ppstream;
pr_elems rest;};
pr_elems [] => (); end;
pr_elems elems;
};
Break_Style
=
CONSISTENT | INCONSISTENT;
fun open_style_box style
=
case style
CONSISTENT => pp::begin_indented_horizontal_else_vertical_box;
INCONSISTENT => pp::begin_indented_wrap_box;
esac;
fun print_sequence_as_nada
ppstream
{ sep: pp::Stream -> Void,
pr: pp::Stream -> X -> Void,
style: Break_Style
}
(elems: List(X))
=
{ open_style_box style ppstream (pp::CURSOR_RELATIVE 0);
print_sequence0_as_nada ppstream (sep, pr, elems);
pp::end_box ppstream
;};
fun print_closed_sequence_as_nada
ppstream
{ front: pp::Stream -> Void,
sep: pp::Stream -> Void,
back: pp::Stream -> Void,
pr: pp::Stream -> X -> Void,
style: Break_Style
}
(elems: List(X))
=
{ pp::begin_horizontal_else_vertical_box ppstream;
front ppstream;
open_style_box style ppstream (pp::CURSOR_RELATIVE 0);
print_sequence0_as_nada ppstream (sep, pr, elems);
pp::end_box ppstream;
back ppstream;
pp::end_box ppstream
;};
fun print_symbol_as_nada ppstream (s: s::Symbol)
=
pp::string ppstream (s::name s);
string_depth = control_print::string_depth;
heap_string = print_junk::heap_string;
fun print_lib7_string_as_nada ppstream = pp::string ppstream o print_junk::print_heap_string;
fun print_integer_as_nada ppstream = pp::string ppstream o print_junk::print_integer;
fun ppvseq ppstream ind (separator: String) pr elements
=
{ fun print_elements [element] => pr ppstream element;
print_elements (element ! rest) => { pr ppstream element;
pp::string ppstream separator;
pp::newline ppstream;
print_elements rest
;};
print_elements [] => (); end;
pp::begin_indented_horizontal_else_vertical_box ppstream (pp::CURSOR_RELATIVE ind);
print_elements elements;
pp::end_box ppstream;
};
fun ppvlist stream (header, separator, print_item, items)
=
case items
NIL => ();
first ! rest
=>
{ pp::string stream header;
print_item stream first;
apply (fn x => { pp::newline stream;
pp::string stream separator;
print_item stream x
;}; end
)
rest
;}; esac;
fun ppvlist' stream (header, separator, print_item, items)
=
case items
NIL => ();
first ! rest
=>
{ print_item stream header first;
apply (fn x => { pp::newline stream;
print_item stream separator x
;}; end
)
rest
;}; esac;
# Debug print functions
fun print_int_path_as_nada ppstream
=
print_closed_sequence_as_nada
ppstream
{ front => (fn pps => pp::string pps "["; end ),
sep => (fn pps => { pp::string pps ", "; pp::break pps { spaces=>0, indent_on_wrap=>0 } ;}; end ),
back => (fn pps => pp::string pps "]"; end ),
style => INCONSISTENT,
pr => (fn pps => pp::string pps o int::to_string; end )
};
fun print_symbol_path_as_nada ppstream (sp: symbol_path::Symbol_Path)
=
pp::string ppstream (symbol_path::to_string sp);
fun print_inverse_path_as_nada ppstream (inverse_path::INVERSE_PATH path: inverse_path::Inverse_Path)
=
print_closed_sequence_as_nada
ppstream
{ front => (fn pps => pp::string pps "<"; end ),
sep => (fn pps => (pp::string pps "."); end ),
back => (fn pps => pp::string pps ">"; end ),
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))
=
{ 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); end ;fi
);
try([], tried) => (tried, FALSE); end;
try (p, []);
};
fun print_int_as_nada stream (i: Int)
=
pps stream (int::to_string i);
fun print_comma_as_nada stream
=
pps stream ", ";
fun print_comma_newline_as_nada stream
=
{ print_comma_as_nada stream;
pp::newline stream
;};
fun newline_indent stream i
=
{ linewidth = 10000;
pp::break stream { spaces => linewidth, indent_on_wrap => i };
};
fun newline_apply stream f
=
{ fun g [] => ();
g [element] => f stream element;
g (element ! rest) => { f stream element; pp::newline stream; g rest;}; end;
g;
};
fun break_apply stream f
=
{ fun g [] => ();
g [el] => f stream el;
g (el ! rst) => { f stream el; pp::break stream { spaces=>1, indent_on_wrap=>0 }; g rst;}; end;
g;
};
fun en_pp stream # "en" for ... "enclose" ...?
=
{ begin_horizontal_else_vertical_box => (fn indent => pp::begin_indented_horizontal_else_vertical_box stream (pp::CURSOR_RELATIVE indent); end ), # CONSISTENT
begin_wrap_box => (fn indent => pp::begin_indented_wrap_box stream (pp::CURSOR_RELATIVE indent); end ), # INCONSISTENT
end_box => fn () => pp::end_box stream; end ,
pps => pp::string stream,
break => fn nsp_offset => pp::break stream nsp_offset; end ,
newline => fn () => pp::newline stream; end
};
fun print_array_as_nada stream (f: pp::Stream -> X -> Void, a: Rw_Vector(X))
=
{ my { begin_horizontal_else_vertical_box, begin_wrap_box, pps, break, end_box, ... }
=
en_pp stream;
fun loop i
=
{ element = rw_vector::get (a, i);
pps (int::to_string i);
pps ": ";
f stream element;
break { spaces=>1, indent_on_wrap=>0 };
loop (i+1);
};
begin_wrap_box 0;
loop 0 except (exceptions::SUBSCRIPT|exceptions::INDEX_OUT_OF_BOUNDS) = ();
end_box();
};
fun by f x y
=
f y x;
fun print_tuple_as_mythrl7 stream f
=
print_closed_sequence_as_nada
stream
{ front => by pps "(",
sep => fn stream = { pps stream ", "; pp::break stream { spaces=>0, indent_on_wrap=>0 }; },
back => by pps ")",
pr => f,
style => INCONSISTENT
};
}; # package print_as_nada_junk


