Changeset 4296

Show
Ignore:
Timestamp:
05/31/08 06:13:11 (4 months ago)
Author:
pmoura
Message:

Updated the Logtalk compiler and runtime to use multifile predicates for the runtime tables of loaded entities and entities relations. This is necessary to generate sensible intermediate Prolog code for large files with tens of thousands of objects. The workaround of using the directive initialization/1 is still available (for now) for Prolog compilers that fail to support the thirteen years old ISO Prolog standard.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4294 r4296  
    6464% tables of loaded entities and respective relationships 
    6565 
    66 :- dynamic('$lgt_current_protocol_'/3).         % '$lgt_current_protocol_'(Ptc, Prefix, Type) 
    67 :- dynamic('$lgt_current_category_'/6).         % '$lgt_current_category_'(Ctg, Prefix, Dcl, Def, Type, Synchronized) 
    68 :- dynamic('$lgt_current_object_'/8).           % '$lgt_current_object_'(Obj, Prefix, Dcl, Def, Super, Type, Synchronized, Threaded) 
     66:- multifile('$lgt_current_protocol_'/3).       % '$lgt_current_protocol_'(Ptc, Prefix, Type) 
     67:- dynamic('$lgt_current_protocol_'/3). 
     68 
     69:- multifile('$lgt_current_category_'/6).       % '$lgt_current_category_'(Ctg, Prefix, Dcl, Def, Type, Synchronized) 
     70:- dynamic('$lgt_current_category_'/6). 
     71 
     72:- multifile('$lgt_current_object_'/8).         % '$lgt_current_object_'(Obj, Prefix, Dcl, Def, Super, Type, Synchronized, Threaded) 
     73:- dynamic('$lgt_current_object_'/8). 
     74 
    6975                                                 
    70 :- dynamic('$lgt_implements_protocol_'/3).      % '$lgt_implements_protocol_'(ObjOrCtg, Ptc, Scope) 
    71 :- dynamic('$lgt_imports_category_'/3).         % '$lgt_imports_category_'(Obj, Ctg, Scope) 
    72 :- dynamic('$lgt_instantiates_class_'/3).       % '$lgt_instantiates_class_'(Instance, Class, Scope) 
    73 :- dynamic('$lgt_specializes_class_'/3).        % '$lgt_specializes_class_'(Class, Superclass, Scope) 
    74 :- dynamic('$lgt_extends_category_'/3).         % '$lgt_extends_category_'(Ctg1, Ctg2, Scope) 
    75 :- dynamic('$lgt_extends_object_'/3).           % '$lgt_extends_object_'(Prototype, Parent, Scope) 
    76 :- dynamic('$lgt_extends_protocol_'/3).         % '$lgt_extends_protocol_'(Ptc1, Ptc2, Scope) 
     76:- multifile('$lgt_implements_protocol_'/3).    % '$lgt_implements_protocol_'(ObjOrCtg, Ptc, Scope) 
     77:- dynamic('$lgt_implements_protocol_'/3). 
     78 
     79:- multifile('$lgt_imports_category_'/3).       % '$lgt_imports_category_'(Obj, Ctg, Scope) 
     80:- dynamic('$lgt_imports_category_'/3). 
     81 
     82:- multifile('$lgt_instantiates_class_'/3).     % '$lgt_instantiates_class_'(Instance, Class, Scope) 
     83:- dynamic('$lgt_instantiates_class_'/3). 
     84 
     85:- multifile('$lgt_specializes_class_'/3).      % '$lgt_specializes_class_'(Class, Superclass, Scope) 
     86:- dynamic('$lgt_specializes_class_'/3). 
     87 
     88:- multifile('$lgt_extends_category_'/3).       % '$lgt_extends_category_'(Ctg1, Ctg2, Scope) 
     89:- dynamic('$lgt_extends_category_'/3). 
     90 
     91:- multifile('$lgt_extends_object_'/3).         % '$lgt_extends_object_'(Prototype, Parent, Scope) 
     92:- dynamic('$lgt_extends_object_'/3). 
     93 
     94:- multifile('$lgt_extends_protocol_'/3).       % '$lgt_extends_protocol_'(Ptc1, Ptc2, Scope) 
     95:- dynamic('$lgt_extends_protocol_'/3). 
    7796                                                 
    78 :- dynamic('$lgt_complemented_object_'/4).      % '$lgt_complemented_object_'(Obj, Ctg, Dcl, Def) 
     97:- multifile('$lgt_complemented_object_'/4).    % '$lgt_complemented_object_'(Obj, Ctg, Dcl, Def) 
     98:- dynamic('$lgt_complemented_object_'/4). 
    7999 
    80100 
     
    86106% debugger status and tables 
    87107 
     108:- multifile('$lgt_debugging_'/1).              % '$lgt_debugging_'(Entity) 
    88109:- dynamic('$lgt_debugging_'/1).                % '$lgt_debugging_'(Entity) 
    89110                                                 
     
    231252:- dynamic('$lgt_pp_file_encoding_'/2).         % '$lgt_pp_file_encoding_'(LogtalkEncoding, PrologEncoding))) 
    232253:- dynamic('$lgt_pp_file_bom_'/1).              % '$lgt_pp_file_bom_'(BOM))) 
     254 
     255:- dynamic('$lgt_pp_file_rclause_'/1).          % '$lgt_pp_file_rclause_'(Clause) 
    233256 
    234257 
     
    44064429        ('$lgt_write_directives'(Output),                       % write out any Prolog code that may occur 
    44074430         '$lgt_write_prolog_clauses'(Output),                   % after the last entity on the source file; 
     4431         '$lgt_write_runtime_clauses'(Output),                  % write entity runtime directives and clauses; 
    44084432         '$lgt_write_init_call'(Output)),                       % write initialization/1 directive at the 
    44094433        OutputError,                                            % end of the file to improve compatibility  
     
    46884712    '$lgt_write_entity_doc'(Entity), 
    46894713    '$lgt_restore_file_op_table', 
     4714    '$lgt_save_entity_rclauses', 
    46904715    '$lgt_clean_pp_entity_clauses'. 
     4716 
     4717 
     4718 
     4719% save entity runtime clauses for Prolog compilers supporting the multifile/1 predicate  
     4720% directive; these clauses are written at the end of the generated Prolog file, just  
     4721% before the source file initialization goal 
     4722 
     4723'$lgt_save_entity_rclauses' :- 
     4724    (   '$lgt_compiler_flag'(multifile_directive, supported) -> 
     4725        (   '$lgt_pp_rclause'(Clause), 
     4726            assertz('$lgt_pp_file_rclause_'(Clause)), 
     4727            fail 
     4728        ;   true 
     4729        ) 
     4730    ;   true 
     4731    ). 
    46914732 
    46924733 
     
    47024743    retractall('$lgt_pp_entity_init_'(_, _, _)), 
    47034744    retractall('$lgt_pp_file_encoding_'(_, _)), 
    4704     retractall('$lgt_pp_file_bom_'(_)). 
     4745    retractall('$lgt_pp_file_bom_'(_)), 
     4746    retractall('$lgt_pp_file_rclause_'(_)). 
    47054747 
    47064748 
     
    87258767    '$lgt_pp_referenced_object_'(Obj), 
    87268768    \+ '$lgt_current_object_'(Obj, _, _, _, _, _, _, _),        % not a currently loaded object 
    8727     \+ '$lgt_pp_object_'(Obj, _, _, _, _, _, _, _, _, _, _),    % not the object being compiled (self references) 
     8769    \+ '$lgt_pp_object_'(Obj, _, _, _, _, _, _, _, _, _, _),    % not the object being compiled (self reference) 
    87288770    \+ '$lgt_pp_entity_init_'(object, Obj, _),                  % not an object defined in the source file being compiled 
     8771    \+ '$lgt_pp_file_rclause_'('$lgt_current_object_'(Obj, _, _, _, _, _, _, _)), 
    87298772    \+ catch(current_module(Obj), _, fail).                     % not a currently loaded module; use catch/3 to avoid  
    87308773                                                                % errors with Prolog compilers with no module support 
     
    87518794    '$lgt_pp_referenced_protocol_'(Ptc), 
    87528795    \+ '$lgt_current_protocol_'(Ptc, _, _),         % not a currently loaded protocol 
    8753     \+ '$lgt_pp_protocol_'(Ptc, _, _, _, _),        % not the protocol being compiled (self references) 
    8754     \+ '$lgt_pp_entity_init_'(protocol, Ptc, _).    % not a protocol defined in the source file being compiled 
     8796    \+ '$lgt_pp_protocol_'(Ptc, _, _, _, _),        % not the protocol being compiled (self reference) 
     8797    \+ '$lgt_pp_entity_init_'(protocol, Ptc, _),    % not a protocol defined in the source file being compiled 
     8798    \+ '$lgt_pp_file_rclause_'('$lgt_current_protocol_'(Ptc, _, _)). 
    87558799 
    87568800 
     
    87768820    '$lgt_pp_referenced_category_'(Ctg), 
    87778821    \+ '$lgt_current_category_'(Ctg, _, _, _, _, _),    % not a currently loaded category 
    8778     \+ '$lgt_pp_category_'(Ctg, _, _, _, _, _),         % not the category being compiled (self references) 
    8779     \+ '$lgt_pp_entity_init_'(category, Ctg, _).        % not a category defined in the source file being compiled 
     8822    \+ '$lgt_pp_category_'(Ctg, _, _, _, _, _),         % not the category being compiled (self reference) 
     8823    \+ '$lgt_pp_entity_init_'(category, Ctg, _),        % not a category defined in the source file being compiled 
     8824    \+ '$lgt_pp_file_rclause_'('$lgt_current_category_'(Ctg, _, _, _, _, _)). 
    87808825 
    87818826 
     
    1040010445 
    1040110446 
     10447% '$lgt_write_runtime_clauses'(@stream) 
     10448% 
     10449% writes the entity runtime multifile and dynamic directives and the entity  
     10450% runtime clauses for all defined entities for Prolog compilers supporting 
     10451% the multifile/1 predicate directive 
     10452 
     10453'$lgt_write_runtime_clauses'(Stream) :- 
     10454    (   '$lgt_compiler_flag'(multifile_directive, supported) -> 
     10455        '$lgt_write_runtime_clauses'(Stream, '$lgt_current_protocol_'/3), 
     10456        '$lgt_write_runtime_clauses'(Stream, '$lgt_current_category_'/6), 
     10457        '$lgt_write_runtime_clauses'(Stream, '$lgt_current_object_'/8), 
     10458        '$lgt_write_runtime_clauses'(Stream, '$lgt_implements_protocol_'/3), 
     10459        '$lgt_write_runtime_clauses'(Stream, '$lgt_imports_category_'/3), 
     10460        '$lgt_write_runtime_clauses'(Stream, '$lgt_instantiates_class_'/3), 
     10461        '$lgt_write_runtime_clauses'(Stream, '$lgt_specializes_class_'/3), 
     10462        '$lgt_write_runtime_clauses'(Stream, '$lgt_extends_category_'/3), 
     10463        '$lgt_write_runtime_clauses'(Stream, '$lgt_extends_object_'/3), 
     10464        '$lgt_write_runtime_clauses'(Stream, '$lgt_extends_protocol_'/3), 
     10465        '$lgt_write_runtime_clauses'(Stream, '$lgt_complemented_object_'/4), 
     10466        '$lgt_write_runtime_clauses'(Stream, '$lgt_debugging_'/1) 
     10467    ;   true 
     10468    ). 
     10469 
     10470 
     10471'$lgt_write_runtime_clauses'(Stream, Functor/Arity) :- 
     10472    functor(Clause, Functor, Arity), 
     10473    (   \+ \+ '$lgt_pp_file_rclause_'(Clause) -> 
     10474        write_canonical(Stream, (:- multifile(Functor/Arity))), write(Stream, '.'), nl(Stream), 
     10475        write_canonical(Stream, (:- dynamic(Functor/Arity))), write(Stream, '.'), nl(Stream), 
     10476        (   '$lgt_pp_file_rclause_'(Clause), 
     10477            write_canonical(Stream, Clause), write(Stream, '.'), nl(Stream), 
     10478            fail 
     10479        ;   true 
     10480        ) 
     10481    ;   true 
     10482    ). 
     10483 
     10484 
     10485 
    1040210486% '$lgt_write_init_call'(@stream) 
    1040310487% 
    10404 % writes the initialization call for the compiled source file that will assert  
    10405 % the relation clauses for all defined entities and call any declared entity  
    10406 % initialization goals when the source file is loaded 
     10488% writes the initialization goal for the compiled source file, a conjunction 
     10489% of the initialization goals of the defined entities; for Prolog compilers 
     10490% that don't support the multifile/1 predicate directive, the initialization 
     10491% goal also asserts the relation clauses for all defined entities 
    1040710492 
    1040810493'$lgt_write_init_call'(Stream) :- 
     
    1044910534'$lgt_gen_entity_init_goal' :- 
    1045010535    '$lgt_pp_entity'(Type, Entity, Prefix, _, Compilation), 
    10451     findall(Clause, '$lgt_pp_rclause'(Clause), Clauses), 
    10452     Goal1 = '$lgt_assert_runtime_clauses'(Entity, Clauses), 
     10536    (   '$lgt_compiler_flag'(multifile_directive, supported) -> 
     10537        Goal1 = true 
     10538    ;   findall(Clause, '$lgt_pp_rclause'(Clause), Clauses), 
     10539        Goal1 = '$lgt_assert_runtime_clauses'(Entity, Clauses) 
     10540    ), 
    1045310541    (   setof(Mutex, Head^'$lgt_pp_synchronized_'(Head, Mutex), Mutexes) -> 
    1045410542        Goal2 = (Goal1, '$lgt_create_mutexes'(Mutexes)) 
     
    1046710555    ;   Goal = Goal5   
    1046810556    ), 
    10469     assertz('$lgt_pp_entity_init_'(Type, Entity, Goal)). 
     10557    (   Goal == true -> 
     10558        true 
     10559    ;   assertz('$lgt_pp_entity_init_'(Type, Entity, Goal)) 
     10560    ). 
    1047010561 
    1047110562 
  • trunk/RELEASE_NOTES.txt

    r4289 r4296  
    1212 
    13132.31.7 - June ??, 2008 
     14 
     15    Updated the Logtalk compiler and runtime to use multifile predicates for  
     16    the runtime tables of loaded entities and entities relations. This is  
     17    necessary to generate sensible intermediate Prolog code for large files  
     18    with tens of thousands of objects. The workaround of using the directive  
     19    initialization/1 is still available (for now) for Prolog compilers that  
     20    fail to support the thirteen years old ISO Prolog standard. 
    1421 
    1522    Added a new default compiler option, multifile_directive, to all config