## proto-basis.pkg
#
# This contains definitions of various standard.lib types that are
# abstract but need to be concrete to the standard.lib implementation.
# It also has some ultility functions.
# Compiled by:
#
src/lib/std/src/standard-core.sublib### "Now and then we had a hope
### that if we lived and were good,
### God would permit us to be pirates."
###
### -- Mark Twain,
### Life on the Mississippi
stipulate
package it = inline_t; # inline_t is from
src/lib/core/init/built-in.pkg #
(-) = it::default_int::(-);
(+) = it::default_int::(+);
(<) = it::default_int::(<);
herein
# This package is referenced in:
#
#
src/lib/std/src/time-guts.pkg #
src/lib/std/src/bool.pkg #
src/lib/std/src/two-word-int.pkg #
src/lib/std/src/one-byte-unt-guts.pkg #
src/lib/std/src/tagged-unt-guts.pkg #
src/lib/std/src/two-word-unt.pkg #
src/lib/std/src/one-word-unt-guts.pkg #
src/lib/std/src/internal-wallclock-timer.pkg #
src/lib/std/src/internal-cpu-timer.pkg #
src/lib/std/src/number-string.pkg #
src/lib/std/src/one-word-int-guts.pkg #
package proto_basis {
#
# The time type is abstract in the time package,
# but other modules need access to it.
#
# Here we open the type-only Time package
# to expose the representation.
include package time; # time is from
src/lib/std/types-only/basis-time.pkg ############################################################################
# These definitions are part of the number_string package, but are defined here
# so that they can be used in other standard.lib modules.
############################################################################
fun scan_string scan_g input_string
=
{ n = it::vector_of_chars::length input_string;
#
fun getc i
=
if (i < n) THE (it::vector_of_chars::get_byte_as_char (input_string, i), i+1);
else NULL;
fi;
case (scan_g getc 0)
#
THE (x, _) => THE x;
NULL => NULL;
esac;
};
fun skip_ws (getc: X -> Null_Or( (Char, X) ) )
=
lp
where
fun is_ws (' ') => TRUE;
is_ws ('\t') => TRUE;
is_ws ('\n') => TRUE;
is_ws _ => FALSE;
end;
fun lp cs
=
case (getc cs)
#
THE (c, cs') => if (is_ws c) lp cs';
else cs ;
fi;
NULL => cs;
esac;
end;
# Get n characters from a character source.
# (This is not a visible part of number_string.)
#
fun get_nchars (getc: X -> Null_Or ((Char, X)) )
(cs, n)
=
get (cs, n, [])
where
fun reverse ([], l2) => l2;
reverse (x ! l1, l2) => reverse (l1, x ! l2);
end;
fun get (cs, 0, l)
=>
THE (reverse (l, []), cs);
get (cs, i, l)
=>
case (getc cs)
#
NULL => NULL;
THE (c, cs') => get (cs', i - 1, c ! l);
esac;
end;
end;
};
end; # stipulate