PreviousUpNext

15.4.465  src/lib/compiler/back/top/closures/nextcode-globalfix.pkg

## nextcode-globalfix.pkg

# Compiled by:
#     src/lib/compiler/core.sublib



# This file implements one of the nextcode transforms.
# For context, see the comments in
#
#     src/lib/compiler/back/top/highcode/highcode-form.api




#       "Do not worry about your problems with mathematics, 
#        I assure you mine are far greater."

#                                     --Albert Einstein 




stipulate
    package ncf =  nextcode_form;                       # nextcode_form         is from   src/lib/compiler/back/top/nextcode/nextcode-form.pkg
herein

    api Nextcode_Globalfix {
        #
        nextcode_globalfix:  ncf::Function  ->  List( ncf::Function );
    };
end;



stipulate
    package ncf =  nextcode_form;                       # nextcode_form         is from   src/lib/compiler/back/top/nextcode/nextcode-form.pkg
herein

    # This package is referenced (only) in:
    #
    #     src/lib/compiler/back/top/main/backend-tophalf-g.pkg
    #   
    package   nextcode_globalfix
    : (weak)  Nextcode_Globalfix                        # Nextcode_Globalfix    is from   src/lib/compiler/back/top/closures/nextcode-globalfix.pkg
    {
        fun nextcode_globalfix (fk, f, vl, cl, cexp)
            =
            {   (gfix cexp) ->   (l, body);
                #       
                (fk, f, vl, cl, body) ! l;
            }
            where
                fun gfix ce
                    =
                    case ce 
                        #
                        ncf::TAIL_CALL _   =>   ([], ce);

                        ncf::DEFINE_FUNS { funs, next }
                            =>
                            {   (gfix next) ->   (n, next');

                                l'  =   fold_forward
                                            (   fn ((k, v, a, t, next), m)
                                                    =
                                                    {   (gfix next) ->   (l, d);
                                                        #
                                                        (k, v, a, t, d)  !  l @ m;
                                                    }
                                            )
                                            n
                                            funs;

                                (l', next');
                            };

                        ncf::JUMPTABLE { i, xvar, nexts }
                            =>
                            {   my (f, nexts)
                                    =
                                    fold_backward
                                        (   fn (c, (fl, cl))
                                               =
                                               {   (gfix c) ->   (f, d);

                                                   ( f @ fl,
                                                     d ! cl
                                                   );
                                               }
                                        )

                                        ([], [])

                                        nexts;

                                (f, ncf::JUMPTABLE { i, xvar, nexts });
                            };

                        ncf::DEFINE_RECORD          { kind, fields, to_temp,    next } =>     {  (gfix next) ->   (f, next);  (f, ncf::DEFINE_RECORD            { kind, fields,    to_temp,       next });  };
                        ncf::GET_FIELD_I            { i, record, to_temp, type, next } =>     {  (gfix next) ->   (f, next);  (f, ncf::GET_FIELD_I              { i, record, type, to_temp,       next });  };
                        ncf::GET_ADDRESS_OF_FIELD_I { i, record, to_temp,       next } =>     {  (gfix next) ->   (f, next);  (f, ncf::GET_ADDRESS_OF_FIELD_I   { i, record,       to_temp,       next });  };

                        ncf::STORE_TO_RAM           { op, args,                 next } =>     {  (gfix next) ->   (f, next);   (f, ncf::STORE_TO_RAM            { op, args,                       next });  };
                        ncf::FETCH_FROM_RAM         { op, args,  to_temp, type, next } =>     {  (gfix next) ->   (f, next);   (f, ncf::FETCH_FROM_RAM          { op, args,        to_temp, type, next });  };
                        ncf::MATH                   { op, args,  to_temp, type, next } =>     {  (gfix next) ->   (f, next);   (f, ncf::MATH                    { op, args,        to_temp, type, next });  };

                        ncf::PURE                   { op, args, to_temp, type, next } =>     {  (gfix next) ->   (f, next);   (f, ncf::PURE                     { op, args,        to_temp, type, next });  };

                        ncf::RAW_C_CALL { kind, cfun_name, cfun_type, args, to_ttemps, next }
                            =>
                            {   (gfix next) ->   (f, next);
                                #
                                ( f,
                                  ncf::RAW_C_CALL { kind, cfun_name, cfun_type, args, to_ttemps, next }
                                );
                            };

                        ncf::IF_THEN_ELSE { op, args, xvar, then_next, else_next }
                            =>
                            {   (gfix then_next) ->   (f1, then_next);
                                (gfix else_next) ->   (f2, else_next);

                                ( f1 @ f2,
                                  ncf::IF_THEN_ELSE { op, args, xvar, then_next, else_next }
                                );
                            };
                    esac;
            end;

    };          #  package nextcode_globalfix 
end;


Comments and suggestions to: bugs@mythryl.org

PreviousUpNext