PreviousUpNext

15.4.551  src/lib/compiler/front/basics/print/print-junk.pkg

## print-junk.pkg 

# Compiled by:
#     src/lib/compiler/front/basics/basics.sublib



###          "Sometimes it pays to stay in bed in Monday,
###           rather than spending the rest of the week
###           debugging Monday's code."
###
###                                -- Dan Salomon



stipulate
    package fil =  file__premicrothread;                                # file__premicrothread  is from   src/lib/std/src/posix/file--premicrothread.pkg
herein

    package   print_junk
    : (weak)  Print_Junk                                                # Print_Junk            is from   src/lib/compiler/front/basics/print/print-junk.api
    {
        say = control_print::say;

        # Should rename this to 'sym' XXX SUCKO FIXME
        package symbol: (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

        fun newline ()
            =
            say "\n";

        fun tab 0 =>  ();
            tab n =>  { say " ";   tab (n - 1); };
        end;

        fun print_sequence  (separator: String)  pr  elements
            =
            print_elements  elements
            where
                fun print_elements [el]        =>  pr el;
                    print_elements (el ! rest) =>  { pr el;  say separator; print_elements rest;};
                    print_elements []          =>  ();
                end;
            end;

        fun print_closed_sequence (front: String, sep, back: String) pr elements
            =
            {   say front;
                #
                print_sequence sep pr elements;

                say back;
            };

        fun print_symbol (s: symbol::Symbol)
            =
            fil::print (symbol::name s);
            #  fix -- maybe this belongs in Symbol 

        fun format_qid p
            =
            cat (f p)
            where
                fun f [s]     =>  [symbol::name s];
                    f (a ! r) =>  symbol::name a ! "." ! f r;
                    f NIL     =>  ["<bogus qid>"];
                end;
            end;

        fun trimmed (s, maxsz)
            =
            if (size s <= maxsz)   s;
            else                   string::substring (s, 0, maxsz) + "#";
            fi;

        fun heap_string s
            =
            cat ["\"", string::to_string s, "\""];

        fun print_heap_string s
            =
            heap_string (trimmed (s, *control_print::string_depth));

        fun heap_string' s
            =
            cat ["'", string::to_string s, "'"];

        fun print_heap_string' s
            =
            heap_string' (trimmed (s, *control_print::string_depth));

        fun print_integer i
            =
            trimmed (multiword_int::to_string i, *control_print::integer_depth);

        fun newline_then_indent n
            =
            {   newline();
                tab n;
            };

        fun printvseq ind (sep: String) pr elements
            =
            print_elements elements
            where
                fun print_elements [el]        =>  pr el;
                    print_elements (el ! rest) =>  { pr el;   newline_then_indent ind;   say sep;   print_elements rest; };
                    print_elements []          =>  ();
                end;
            end;

        #  Debug print functions 

        print_int_path      =   print_closed_sequence ("[", ", ", "]") (say o int::to_string);

        print_symbol_path   =   print_sequence "." print_symbol;

    };          #  package print_junk 
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext