PreviousUpNext

15.4.1231  src/lib/std/src/unsafe/unsafe.pkg

## unsafe.pkg
#
# Unsafe operations on Mythryl values.

# Compiled by:
#     src/lib/std/src/standard-core.sublib



package unsafe
      : Unsafe                                                          # Unsafe                                is from   src/lib/std/src/unsafe/unsafe.api
{
    #
    package mythryl_callable_c_library_interface
          = mythryl_callable_c_library_interface;                       # mythryl_callable_c_library_interface  is from   src/lib/std/src/unsafe/mythryl-callable-c-library-interface.pkg

    package unsafe_chunk
          = unsafe_chunk;                                               # unsafe_chunk                          is from   src/lib/std/src/unsafe/unsafe-chunk.pkg

    package software_generated_periodic_events
          = software_generated_periodic_events;                         # software_generated_periodic_events    is from   src/lib/std/src/unsafe/software-generated-periodic-events.pkg

    package vector {
        #
        get  =  inline_t::poly_vector::get;                             # inline_t                              is from   src/lib/core/init/built-in.pkg
        make =  core::runtime::asm::make_typeagnostic_ro_vector;        # core                                  is from   src/lib/core/init/core.pkg
    };

    package rw_vector {
        #
        get  =  inline_t::poly_rw_vector::get;
        set  =  inline_t::poly_rw_vector::set;
        make =  core::runtime::asm::make_typeagnostic_rw_vector;
    };

    package vector_of_chars {
        #
        Vector  =  vector_of_chars::Vector;                             # vector_of_chars                       is from   src/lib/std/src/vector-of-chars.pkg
        Element =  vector_of_chars::Element;

        get     =  inline_t::vector_of_chars::get_byte_as_char;
        set     =  inline_t::vector_of_chars::set_char_as_byte;

        make    =  core::runtime::asm::make_string;
    };

    package rw_vector_of_chars {
        #
        Rw_Vector =  rw_vector_of_chars::Rw_Vector;                     # rw_vector_of_chars                    is from   src/lib/std/src/rw-vector-of-chars.pkg
        Element   =  rw_vector_of_chars::Element;

        get    = inline_t::rw_vector_of_chars::get;
        set    = inline_t::rw_vector_of_chars::set;

        my make:  Int -> Rw_Vector
            =
            inline_t::cast  core::runtime::asm::make_unt8_rw_vector;
    };

    package vector_of_one_byte_unts {
        #
        Vector  =  vector_of_one_byte_unts::Vector;                     # vector_of_one_byte_unts               is from   src/lib/std/src/vector-of-one-byte-unts.pkg
        Element =  vector_of_one_byte_unts::Element;

        get    =  inline_t::vector_of_one_byte_unts::get;
        set    =  inline_t::vector_of_one_byte_unts::set;

        my make:  Int -> Vector
            =
            inline_t::cast core::runtime::asm::make_string;
    };

    package rw_vector_of_one_byte_unts {
        #
        Rw_Vector = rw_vector_of_one_byte_unts::Rw_Vector;              # rw_vector_of_one_byte_unts            is from   src/lib/std/src/rw-vector-of-one-byte-unts.pkg
        Element   = rw_vector_of_one_byte_unts::Element;

        get   = inline_t::rw_vector_of_one_byte_unts::get;
        set   = inline_t::rw_vector_of_one_byte_unts::set;

        make  = core::runtime::asm::make_unt8_rw_vector;
    };

/** once we have flat float vectors, we can include this subpackage

    package vector_of_eight_byte_floats {
        #
        type Vector = vector_of_eight_byte_floats::Vector
        type Element = vector_of_eight_byte_floats::Element
        my get:  (Vector * Int) -> Element
        my set:  (Vector * Int * Element) -> Void
        my make:  Int -> Vector
    };
**/
    package rw_vector_of_eight_byte_floats {
        #
        Rw_Vector = rw_vector_of_eight_byte_floats::Rw_Vector;          # rw_vector_of_eight_byte_floats        is from   src/lib/std/src/rw-vector-of-eight-byte-floats.pkg
        Element   = rw_vector_of_eight_byte_floats::Element;

        get   = inline_t::rw_vector_of_eight_byte_floats::get;
        set   = inline_t::rw_vector_of_eight_byte_floats::set;

        make  = core::runtime::asm::make_float64_rw_vector;
    };

    get_current_microthread_register = inline_t::get_current_microthread_register;
    set_current_microthread_register = inline_t::set_current_microthread_register;

    get_handler =  inline_t::gethandler;
    set_handler =  inline_t::sethandler;

    get_pseudo =  inline_t::getpseudo;
    set_pseudo =  inline_t::setpseudo;


    boxed =   inline_t::boxed;
    cast  =   inline_t::cast;

    # Actual representation of pervasive_package_pickle_list__global,
    # a C global used to communicate with the C runtime.
    # It contains a linklist of picklehash-pickle pairs:
    # see (e.g.)
    #     src/c/main/construct-runtime-package.c
    #     src/c/main/load-compiledfiles.c 
    #
    package p {
        #
        Pervasive_Package_Pickle_List
          #
          = NIL                                                         # NIL and CONS are traditional LISP terms for final and nonfinal (respectively) linklist nodes.
          #
          | CONS  ( vector_of_one_byte_unts::Vector,                    # 16-byte hash of chunk.
                    unsafe_chunk::Chunk,                                # Arbitrary ram-chunk on Mythryl heap.
                    Pervasive_Package_Pickle_List                       # 'next' pointer in linklist.
                  )
          ;
    };

    pervasive_package_pickle_list__global
        =
        (inline_t::cast  runtime::pervasive_package_pickle_list__global)
        :
        Ref( p::Pervasive_Package_Pickle_List );


    sigint_fate                                                         # Set only in   src/lib/compiler/toplevel/interact/read-eval-print-loop-g.pkg
        =                                                               # Called by handle_sigint() in src/lib/core/internal/make-mythryld-executable.pkg
        REF (inline_t::make_isolated_fate (\\ () = ()));                # XXX BUGGO FIXME more icky thread-hostile mutable global storage. :-(


    posix_interprocess_signal_handler_refcell__global
        =
        runtime::posix_interprocess_signal_handler_refcell__global;



    unpickle_datastructure
        =
        (\\ x =  mythryl_callable_c_library_interface::find_c_function { lib_name => "heap", fun_name => "unpickle_datastructure" } x)
        :
        vector_of_one_byte_unts::Vector -> X;

    pickle_datastructure
        =
        (\\ x =  mythryl_callable_c_library_interface::find_c_function { lib_name => "heap", fun_name => "pickle_datastructure" } x)
        :
        X -> vector_of_one_byte_unts::Vector;

        ###############################################################
        # NB: The above two fns are never called, and I have a feeling
        # that if they were, that switching over from using
        # find_c_function() to using find_c_function'() would
        # not be a win, so for now I'm leaving them as-is.
        #                                        -- 2012-04-21 CrT
};




Comments and suggestions to: bugs@mythryl.org

PreviousUpNext