#
# A "private" extension to the encoding of C types in Mythryl.
# The routines here are for use by code that will be automatically
# generated from corresponding C files. User code is not supposed
# to access them because they are unsafe. (Not that subverting the C
# type system is a big deal! :)
#
# (C) 2001, Lucent Technologies, Bell Laboratories
#
# author: Matthias Blume (blume@research.bell-labs.com)
# Compiled by:
#
src/lib/c-glue-lib/internals/c-internals.libapi Ckit_Internal {
include api Ctypes; # Ctypes is from
src/lib/c-glue-lib/c.api Addr = cmemory::Addr;
# Make struct or union size from its size given as a word.
# Needs explicit type constraint:
make_su_size: Unt -> s::Size( S );
# Make struct or union RTTI given its corresponding size:
make_su_type: s::Size ( Su( S ) ) -> t::Type( Su( S ) );
# Make function pointer type given the Mythryl function
# that implements the calling protocol:
make_fptr_type: (Addr -> X -> Y) -> t::Type( Fptr (X -> Y) );
# Make light-weight chunks:
make_chunk' : Addr -> Chunk' (T, C);
# Make a void* from an address:
make_voidptr: Addr -> Voidptr;
# Given the function that implements the calling protocol
# and the function's raw address, make a function pointer:
make_fptr: ((Addr -> X -> Y), Addr) -> Fptr (X -> Y);
# Make normal and const-declared struct- or union-fields
# given the field's type and its offset:
make_rw_field: (t::Type( M ), Int, Su_Chunk( S, C )) -> Chunk (M, C);
make_ro_field: (t::Type( M ), Int, Su_Chunk( S, C )) -> Chunk (M, Ro);
# Lightweight (no run-time type information) version:
# NOTE: We do not pass RTTI to the light version (which would
# internally throw it away anyway). This means that we
# will need an explicit type constraint.
make_field' : (Int, Su_Chunk' (S, A_ac)) -> Chunk' (M, A_rc);
# Make normal signed bitfields
make_rw_sbf: (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk (S, C) -> Sbf( C );
make_ro_sbf: (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk (S, C) -> Sbf( Ro );
# Lightweight versions:
make_rw_sbf' : (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk' (S, C) -> Sbf( C );
make_ro_sbf' : (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk' (S, C) -> Sbf( Ro );
# Make normal unsigned bitfields:
make_rw_ubf: (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk (S, C) -> Ubf( C );
make_ro_ubf: (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk (S, C) -> Ubf( Ro );
# Lightweight versions:
make_rw_ubf' : (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk' (S, C) -> Ubf( C );
make_ro_ubf' : (Int, Unt, Unt) -> # offset * bits * shift
Su_Chunk' (S, C) -> Ubf( Ro );
# Reveal address behind void*.
# This is used to implement the function-call protocol
# for functions that have pointer arguments:
reveal: Voidptr -> Addr;
freveal: Fptr'( F ) -> Addr;
vcast: Addr -> Voidptr;
pcast: Addr -> Ptr'( O );
fcast: Addr -> Fptr'( F );
# Unsafe low-level rw_vector subscript that does not require RTTI:
unsafe_sub: Int -> # element size
(Chunk'( Arr(T, N), C), Int) ->
Chunk' (T, N);
};