PreviousUpNext

15.4.77  src/app/makelib/main/makelib-preprocessor-dictionary.pkg

## makelib-preprocessor-dictionary.pkg
## (C) 1999 Lucent Technologies, Bell Laboratories
## Author: Matthias Blume (blume@kurims.kyoto-u.ac.jp)

# Compiled by:
#     src/app/makelib/makelib.sublib



# We're directly referenced (only) in
#      src/app/makelib/main/makelib-preprocessor-state-g.pkg

stipulate
    package sa  =  supported_architectures;                                             # supported_architectures               is from   src/lib/compiler/front/basics/main/supported-architectures.pkg
herein

    api Makelib_Preprocessor_Dictionary {
        #
        Makelib_Preprocessor_Dictionary;

        get:  Makelib_Preprocessor_Dictionary
                  ->
                  String                                                                # key
                  ->
                  Null_Or( Int );                                                       # NULL means to drop key from dictionary; THE(value) means set it to given value.

        empty_makelib_preprocessor_dictionary:   Makelib_Preprocessor_Dictionary;

        # Add/drop a definition to preprocessor dictionary:
        #
        define:  ( Makelib_Preprocessor_Dictionary,
                   String,              # Key
                   Null_Or( Int )       # Value. NULL means to drop the key.
                 )
                 ->
                 Makelib_Preprocessor_Dictionary;

        make_default_makelib_preprocessor_dictionary
          :
          { architecture:               sa::Supported_Architectures,
            os_kind:                    platform_properties::os::Kind,
            #
            compiler_version:           List( Int ),
            extra_symbols:              List( String )
          }
          ->
          Makelib_Preprocessor_Dictionary;
    };
end;



stipulate
    package sa  =  supported_architectures;                                             # supported_architectures               is from   src/lib/compiler/front/basics/main/supported-architectures.pkg
    package stm =  string_map;                                                          # string_map                            is from   src/lib/src/string-map.pkg
herein

    package   makelib_preprocessor_dictionary
    :         Makelib_Preprocessor_Dictionary
    {
        # We implement the makelib preprocessor dictionary
        # as a simple   String -> Int   map:
        #
        Makelib_Preprocessor_Dictionary
            =
            stm::Map( Int );

        fun get dictionary string
            =
            stm::get (dictionary, string);


        empty_makelib_preprocessor_dictionary
            =
            stm::empty;



      fun define (dictionary, string, THE value)                                        # Define 'string' in 'dictionary' with integer value 'value'
                =>
                stm::set (dictionary, string, value);

          define (dictionary, string, NULL)                                             # Delete 'string' from 'dictionary'.
                =>
                (   #1 (stm::drop (dictionary, string))
                    except
                       lib_base::NOT_FOUND =  dictionary
                );
        end;
            

        # This fn is invoked (only) from:
        #
        #     src/app/makelib/main/makelib-preprocessor-state-g.pkg
        #
        fun make_default_makelib_preprocessor_dictionary
              { architecture,
                os_kind,
                compiler_version,               # Something like:          [110,58,3,0.2]
                extra_symbols                   # Currently this will be   ["ABI_Darwin"]   on intel macs, otherwise always  [].
              }
            =
            {
                (sa::architecture_info  architecture)
                    ->
                    { architecture_name, big_endian, pointer_size_in_bits };

                architecture_symbol =  "ARCH_" + architecture_name;

                pointer_size_in_bits_symbol =  "POINTER_SIZE_IN_BITS";          # Fundamental word size for this implementation. Currently always 32.

                endian_symbol
                    =
                    big_endian   ??     "BIG_ENDIAN"
                                 ::  "LITTLE_ENDIAN";

                os_symbol
                    =
                    case os_kind
                        #
                        platform_properties::os::POSIX => "OPSYS_UNIX";
                        platform_properties::os::WIN32 => "OPSYS_WIN32";
                        platform_properties::os::MACOS => "OPSYS_MACOS";
                        platform_properties::os::OS2   => "OPSYS_OS2";
                        platform_properties::os::BEOS  => "OPSYS_BEOS";
                    esac;

                my (major, minor)
                    =
                    case compiler_version
                        #                 
                        []                 =>  (0, 0);
                        [major]            =>  (major, 0);
                        major ! minor ! _  =>  (major, minor);
                    esac;

                major_symbol = "MYTHRYL_COMPILER_MAJOR_VERSION";
                minor_symbol = "MYTHRYL_COMPILER_MINOR_VERSION";

                my all_defs:   List( (String, Int) )                            # Extend our local key-val list with 'extra_symbols', all with value '1'.
                    =
                    fold_backward
                        (fn (s, l) =  (s, 1) ! l)
                        [ (architecture_symbol, 1),
                          (endian_symbol, 1),
                          (pointer_size_in_bits_symbol, pointer_size_in_bits),
                          (os_symbol, 1),
                          (major_symbol, major),
                          (minor_symbol, minor)
                        ]
                        extra_symbols;

                fold_forward
                    stm::set'                                                   # Fn to apply.          set' def in    src/lib/src/string-map.pkg
                    empty_makelib_preprocessor_dictionary                       # Initial value.
                    all_defs;                                                   # List to process.
            };
    };
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext