PreviousUpNext

15.3.220  src/lib/compiler/execution/code-segments/code-segment.api

## code-segment.api

# Compiled by:
#     src/lib/compiler/execution/execute.sublib



# An interface for manipulating code chunks.




###                   "Knowledge is our ultimate good."
###
###                         -- Socrates (circa 470-399BC)


stipulate
    package bio =  data_file__premicrothread;                                           # data_file__premicrothread             is from   src/lib/std/src/posix/data-file--premicrothread.pkg
    package bv  =  vector_of_one_byte_unts;     # "bv" == "bytevector"                  # vector_of_one_byte_unts               is from   src/lib/std/src/vector-of-one-byte-unts.pkg
    package wbv =  rw_vector_of_one_byte_unts;  # "wbv" == "writable bytevector"        # rw_vector_of_one_byte_unts            is from   src/lib/std/src/rw-vector-of-one-byte-unts.pkg
    package uc  =  unsafe::unsafe_chunk;                                                # unsafe                                is from   src/lib/std/src/unsafe/unsafe.pkg
herein

    api Code_Segment {
        #
        Code_Segment;

        # This type is unused here.  It is used in three apis:                          # Possibly this type should be in its own package.
        #
        #     As a return value for  translate_anormcode_to_execode     in   src/lib/compiler/toplevel/main/backend.api
        #     As a return value for  translate_raw_syntax_to_execode    in   src/lib/compiler/toplevel/main/translate-raw-syntax-to-execode.api
        #     As an argument for     make_compiledfile                  in   src/lib/compiler/execution/compiledfile/compiledfile.api
        #
        Code_And_Data_Segments
          =
          { code_segment:                               Code_Segment,                   # The code segment for this compiled file.
            bytecodes_to_regenerate_literals_vector:    bv::Vector                      # Re/generates our literals via         src/c/heapcleaner/make-package-literals-via-bytecode-interpreter.c
          };                                                                            # This gets done in                     src/lib/compiler/execution/main/link-and-run-package.pkg

        Package_Closure =   uc::Chunk -> uc::Chunk;                                     # Calling this with an importtree+linkmapstack arg links the package into memory; return value is the package exports.

        exception FORMAT_ERROR;
            #  raised by input when there are insufficient bytes 

        make_code_segment_of_bytesize:  Int -> Code_Segment;                            # Allocate an unintialized code segment of the given size-in-bytes.


        read_machinecode_bytevector:  (bio::Input_Stream, Int) -> Code_Segment;         # Allocate a code chunk of the given size and initialize it from the input stream.

        write_machinecode_bytevector_and_flush                                          # Write a code chunk to given output stream.
            :
            (bio::Output_Stream, Code_Segment) -> Void;

        get_machinecode_bytevector:  Code_Segment -> wbv::Rw_Vector;                    # View the code chunk as an updatable rw_vector of bytes. 

        set_entrypoint:  (Code_Segment, Int) -> Void;                                   # Set the offset of the entrypoint of the code chunk (default: 0). 

        make_package_closure:  Code_Segment -> Package_Closure;                         # Prepare the machinecode bytevector for execution.  This has the side-effect
                                                                                        # of flushing the instruction cache (which is a no-op on intel32).


        get_machinecode_bytevector_size_in_bytes:  Code_Segment -> Int;                 # Return the size of the code chunk.

        get_entrypoint:  Code_Segment -> Int;                                           # Return the offset of the entry point of the code chunk.

        make_package_literals_via_bytecode_interpreter                                  # Use the bytecode interpreter in      src/c/heapcleaner/make-package-literals-via-bytecode-interpreter.c
            :                                                                           # to (re)generate our in-ram literals
            bv::Vector -> uc::Chunk;                                                    # vector after being loaded from disk.
                                
                        

    };
end;


## COPYRIGHT (c) 1998 Bell Labs, Lucent Technologies.
## Subsequent changes by Jeff Prothero Copyright (c) 2010-2015,
## released per terms of SMLNJ-COPYRIGHT.


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext