## stamp.pkg
#
# See overview comments in:
#
#
src/lib/compiler/front/typer-stuff/basics/stamp.api# Compiled by:
#
src/lib/compiler/front/typer-stuff/typecheckdata.sublibstipulate
package im = int_red_black_map; # int_red_black_map is from
src/lib/src/int-red-black-map.pkg package ph = picklehash; # picklehash is from
src/lib/compiler/front/basics/map/picklehash.pkgherein
package stamp
: Stamp # Stamp is from
src/lib/compiler/front/typer-stuff/basics/stamp.api {
Picklehash = ph::Picklehash; # For global stamps.
# For background see FRESH/STATIC/GLOBAL comments in
#
#
src/lib/compiler/front/typer-stuff/basics/stamp.api #
Stamp
#
= FRESH Int
#
| STATIC String
#
| GLOBAL { picklehash: Picklehash,
count: Int
}
;
Key = Stamp;
Fresh_Stamp_Maker = Void -> Stamp;
fun compare (FRESH i, FRESH i' ) => int::compare (i, i'); # int is from
src/lib/std/int.pkg compare (FRESH _, _ ) => GREATER;
compare (_, FRESH _ ) => LESS;
compare (STATIC s, STATIC s') => string::compare (s, s');
compare (STATIC _, _ ) => GREATER;
compare (_, STATIC _ ) => LESS;
compare (GLOBAL g, GLOBAL g')
=>
case (int::compare (g.count, g'.count))
#
EQUAL => ph::compare (g.picklehash, g'.picklehash);
unequal => unequal;
esac;
end;
fun same_stamp (s, s')
=
compare (s, s') == EQUAL;
fun make_fresh_stamp_maker ()
=
make_fresh_stamp
where
next_stamp = REF 0;
#
fun make_fresh_stamp ()
=
{ stamp = *next_stamp;
#
next_stamp := stamp + 1;
#
FRESH stamp;
};
end;
make_static_stamp = STATIC;
make_global_stamp = GLOBAL;
Converter
=
( Ref( im::Map (Int) ),
Ref( Int )
);
fun new_converter ()
=
( REF im::empty,
REF 0
);
fun case' _ (STATIC s) { fresh, global, static }
=>
static s;
case' _ (GLOBAL g) { global, ... }
=>
global g;
case' (m, n) (FRESH i) { fresh, ... }
=>
case (im::get (*m, i))
#
THE i' => fresh i';
NULL =>
{
i' = *n;
n := i' + 1;
m := im::set (*m, i, i');
fresh i';
};
esac;
end;
fun is_fresh (FRESH _) => TRUE;
is_fresh _ => FALSE;
end;
fun to_string (FRESH i)
=>
cat ["FRESH_STAMP(", int::to_string i, ")"];
to_string (GLOBAL { picklehash, count } )
=>
cat ["GLOBAL_STAMP(", ph::to_hex picklehash, ", ", int::to_string count, ")"];
to_string (STATIC s)
=>
cat ["STATIC_STAMP(", s, ")"];
end;
fun to_short_string (FRESH i)
=>
"#FRESH(" + int::to_string i + ")";
to_short_string (STATIC s)
=>
"#STATIC(" + s + ")";
to_short_string (GLOBAL { picklehash, count } )
=>
{ fun trim3 s
=
substring (s, size s - 3, 3);
cat ["#GLOBAL(", trim3 (ph::to_hex picklehash), ".", int::to_string count, ")"];
};
end;
};
end;