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 / foreign.pl < prev    next >
Text File  |  1992-05-26  |  3KB  |  111 lines

  1. /*  foreign.pl,v 1.1.1.1 1992/05/26 11:51:22 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     jan@swi.psy.uva.nl
  5.  
  6.     Purpose: Foreign language loader front end
  7. */
  8.  
  9. :- module($foreign,
  10.     [ load_foreign/5
  11.     , load_foreign/2
  12.     , foreign_file/1
  13.     ]).
  14.  
  15. :- module_transparent
  16.     load_foreign/5,
  17.     load_foreign_/5,
  18.     load_foreign/2.
  19.  
  20. %    foreign_file(?File)
  21. %    Is true if 'File' is loaded as a foreign file.
  22.  
  23. foreign_file(File) :-
  24.     recorded($foreign_file, File).
  25.  
  26. %    load_foreign(+File, +Entry)
  27. %    Load foreign file and initialise with specified entry.
  28.  
  29. load_foreign(File, Entry) :-
  30.     load_foreign(File, Entry, '', '', 0).
  31.  
  32. %    load_foreign(+File, +Entry, +Options, +Libraries, +Size)
  33. %    Load a (list of) .o file(s) as produced with  'cc  -c  ...'  and
  34. %    install the foreign predicates defined in them. 
  35.  
  36. load_foreign(Files, Entry, Options, Libraries, Size) :-
  37.     statistics(heapused, OldHeap),
  38.     statistics(cputime, OldTime),
  39.  
  40.     (   load_foreign_(Files, Entry, Options, Libraries, Size)
  41.     ;   true
  42.     ), !,
  43.  
  44.     statistics(heapused, Heap),
  45.     statistics(cputime, Time),
  46.     HeapUsed is Heap - OldHeap,
  47.     TimeUsed is Time - OldTime,
  48.  
  49.     confirm_files(Files, CFs),
  50.     list_to_atom(CFs, CF),
  51.     context_module(M),
  52.     module_spec(M, ModSpec),
  53.     $ttyformat('Foreign file(s) ~w loaded~w, ~2f seconds, ~D bytes~n',
  54.                     [CF, ModSpec, TimeUsed, HeapUsed]).
  55.     
  56. module_spec(user, '') :- !.
  57. module_spec(M, S) :-
  58.     sformat(S, ' into ~w', [M]).
  59.  
  60. confirm_files([], []) :- !.
  61. confirm_files([H|T], [CH|CT]) :- !,
  62.     confirm_file(H, CH),
  63.     confirm_files(T, CT).
  64. confirm_files(F, CF) :-
  65.     confirm_file(F, CF).
  66.  
  67. confirm_file(library(File), Confirm) :- !,
  68.     check_files(library(File), Confirm).
  69. confirm_file(File, File).
  70.  
  71. load_foreign_(Files, Entry, Options, Libraries, Size) :-
  72.     check_files(Files, Expanded),
  73.     list_to_atom(Expanded, F),    
  74.     list_to_atom(Options, O),
  75.     list_to_atom(Libraries, L),
  76.  
  77.     $load_foreign(F, Entry, O, L, Size),
  78.     record_foreigns(Expanded).
  79.  
  80. check_files(0, _) :- !, fail.        /* variable file name */
  81. check_files([], []) :- !.
  82. check_files([F|R], [A|T]) :- !,
  83.     check_files(F, A),
  84.     check_files(R, T).
  85. check_files(F, A) :-
  86.     $arch(Machine, _),
  87.     $chk_file(F, A, [Machine, ''], ['.o', '.a', '']), !.
  88. check_files(F, _) :-
  89.     $warning('~w: No such foreign file', [F]),
  90.     fail.
  91.  
  92. list_to_atom(Atom, Atom) :-
  93.     atomic(Atom), !.    
  94. list_to_atom(List, Atom) :-
  95.     insert_spaces(List, SPList),    
  96.     concat_atom(SPList, Atom).
  97.  
  98. insert_spaces([One], [One]) :- !.
  99. insert_spaces([H|T], [H, ' '| R]) :-
  100.     insert_spaces(T, R).
  101.  
  102. record_foreigns([]) :- !.
  103. record_foreigns([H|T]) :- !,
  104.     record_foreigns(H),
  105.     record_foreigns(T).
  106. record_foreigns(F) :-
  107.     absolute_file_name(F, Path),
  108.     (   recorded($foreign_file, Path)
  109.     ;   recordz($foreign_file, F)
  110.     ), !.
  111.