home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-387-Vol-3of3.iso / p / plbin.zip / pl / boot / aix_foreign.pl next >
Text File  |  1992-05-26  |  4KB  |  165 lines

  1. /*  aix_foreign.pl,v 1.1.1.1 1992/05/26 11:51:20 jan Exp
  2.  
  3.     Copyright (c) 1991 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Foreign interface for AIX version
  7. */
  8.  
  9. :- module($aix_foreign,
  10.     [ load_foreign/5
  11.     , load_foreign/2
  12.     , load_foreign/1
  13.     , foreign_file/1
  14.     ]).
  15.  
  16. :- module_transparent
  17.     load_foreign/2,
  18.     load_foreign/1.
  19.  
  20. %    load_foreign/5
  21. %    Not available on AIX.  Just print an error
  22.  
  23. load_foreign(_, _, _, _, _) :-
  24.     $warning('load_foreign/5: not on AIX; see load_foreign/[1,2]'),
  25.     fail.
  26.  
  27.  
  28. %    load_foreign(+Executable)
  29. %    Load a foreign file and call its entry point.
  30.  
  31. load_foreign(File) :-
  32.     statistics(heapused, OldHeap),
  33.     statistics(cputime, OldTime),
  34.  
  35.     (   $arch(Machine, _),
  36.         $chk_file(File, Path, [Machine, ''], [''])
  37.     ->  true
  38.     ;   $warning('~w: No such foreign file', [File]),
  39.         fail
  40.     ),    
  41.     $load_foreign(Path),
  42.     record_foreigns(Path),
  43.  
  44.     statistics(heapused, Heap),
  45.     statistics(cputime, Time),
  46.     HeapUsed is Heap - OldHeap,
  47.     TimeUsed is Time - OldTime,
  48.  
  49.     confirm_files(File, CFs),
  50.     list_to_atom(CFs, CF),
  51.     context_module(M),
  52.     module_spec(M, ModSpec),
  53.     $ttyformat('Foreign file `~w'' loaded~w, ~2f seconds, ~D bytes~n',
  54.            [CF, ModSpec, TimeUsed, HeapUsed]).
  55.  
  56.  
  57. %    load_foreign(+Files, +Entry)
  58.  
  59. load_foreign(Files, Entry) :-
  60.     statistics(heapused, OldHeap),
  61.     statistics(cputime, OldTime),
  62.  
  63.     check_files(Files, Paths),
  64.     list_to_atom(Paths, Atom),
  65.     confirm_files(Files, CFs),
  66.     list_to_atom(CFs, CF),
  67.     tmp_file(ld, Object),
  68.     import_file(Imports),
  69.     concat_atom(['cc -bI:', Imports,
  70.              ' -e ', Entry,
  71.              ' -o ', Object,
  72.              ' ', Atom], Cmd),
  73.     concat_atom(['cc -bI:', Imports,
  74.              ' -e ', Entry,
  75.              ' -o ', Object,
  76.              ' ', CF], UCmd),
  77.     format(user_output, '~w~n', [UCmd]),
  78.     (    shell(Cmd)
  79.     ->   $load_foreign(Object),
  80.          delete_file(Object)
  81.     ;    $warning('load_foreign/2: failed ~w', Cmd),
  82.          fail
  83.     ),
  84.     record_foreigns(Paths),
  85.  
  86.     statistics(heapused, Heap),
  87.     statistics(cputime, Time),
  88.     HeapUsed is Heap - OldHeap,
  89.     TimeUsed is Time - OldTime,
  90.  
  91.     context_module(M),
  92.     module_spec(M, ModSpec),
  93.     $ttyformat('Foreign file(s) ~w loaded~w, ~2f seconds, ~D bytes~n',
  94.            [CF, ModSpec, TimeUsed, HeapUsed]).
  95.     
  96.  
  97. %    import_file(-File)
  98. %    Return path-name to file with import declarations
  99.  
  100. import_file(File) :-
  101.     $home(Home),
  102.     concat(Home, '/include/SWI-Exports', File).
  103.  
  104. %    foreign_file(?File)
  105. %    Is true if 'File' is loaded as a foreign file.
  106.  
  107. foreign_file(File) :-
  108.     recorded($foreign_file, File).
  109.  
  110. module_spec(user, '') :- !.
  111. module_spec(M, S) :-
  112.     sformat(S, ' into ~w', [M]).
  113.  
  114. confirm_files([], []) :- !.
  115. confirm_files([H|T], [CH|CT]) :- !,
  116.     confirm_file(H, CH),
  117.     confirm_files(T, CT).
  118. confirm_files(F, CF) :-
  119.     confirm_file(F, CF).
  120.  
  121. confirm_file(library(File), Confirm) :- !,
  122.     check_files(library(File), Confirm).
  123. confirm_file(File, File).
  124.  
  125. load_foreign_(Files, Entry, Options, Libraries, Size) :-
  126.     check_files(Files, Expanded),
  127.     list_to_atom(Expanded, F),    
  128.     list_to_atom(Options, O),
  129.     list_to_atom(Libraries, L),
  130.  
  131.     $load_foreign(F, Entry, O, L, Size),
  132.     record_foreigns(Expanded).
  133.  
  134. check_files(0, _) :- !, fail.        /* variable file name */
  135. check_files([], []) :- !.
  136. check_files([F|R], [A|T]) :- !,
  137.     check_files(F, A),
  138.     check_files(R, T).
  139. check_files(F, A) :-
  140.     $arch(Machine, _),
  141.     $chk_file(F, A, [Machine, ''], ['.o', '.a', '.c', '']), !.
  142. check_files(F, _) :-
  143.     $warning('~w: No such foreign file', [F]),
  144.     fail.
  145.  
  146. list_to_atom(Atom, Atom) :-
  147.     atomic(Atom), !.    
  148. list_to_atom(List, Atom) :-
  149.     insert_spaces(List, SPList),    
  150.     concat_atom(SPList, Atom).
  151.  
  152. insert_spaces([One], [One]) :- !.
  153. insert_spaces([H|T], [H, ' '| R]) :-
  154.     insert_spaces(T, R).
  155.  
  156. record_foreigns([]) :- !.
  157. record_foreigns([H|T]) :- !,
  158.     record_foreigns(H),
  159.     record_foreigns(T).
  160. record_foreigns(F) :-
  161.     absolute_file_name(F, Path),
  162.     (   recorded($foreign_file, Path)
  163.     ;   recordz($foreign_file, F)
  164.     ), !.
  165.