Changeset 4498 for trunk/compiler

Show
Ignore:
Timestamp:
10/11/08 12:09:02 (3 months ago)
Author:
pmoura
Message:

Modified the built-in methods create_category/4, create_object/4 and create_protocol/3 to accept a variable as the first argument, which will be instantiated to the identifier generated for the new entity.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/compiler/logtalk.pl

    r4480 r4498  
    524524 
    525525 
    526 % create_object(+object_identifier, +list, +list, +list) 
     526% create_object(?object_identifier, +list, +list, +list) 
    527527 
    528528create_object(Obj, Rels, Dirs, Clauses) :- 
    529     (var(Obj); var(Rels); var(Dirs); var(Clauses)), 
     529    (var(Rels); var(Dirs); var(Clauses)), 
    530530    throw(error(instantiation_error, create_object(Obj, Rels, Dirs, Clauses))). 
    531531 
    532532create_object(Obj, Rels, Dirs, Clauses) :- 
     533    nonvar(Obj), 
    533534    \+ callable(Obj), 
    534535    throw(error(type_error(object_identifier, Obj), create_object(Obj, Rels, Dirs, Clauses))). 
    535536 
    536537create_object(Obj, Rels, Dirs, Clauses) :- 
     538    nonvar(Obj), 
    537539    '$lgt_current_object_'(Obj, _, _, _, _, _, _, _, _, _, _, _, _), 
    538540    throw(error(permission_error(modify, object, Obj), create_object(Obj, Rels, Dirs, Clauses))). 
    539541 
    540542create_object(Obj, Rels, Dirs, Clauses) :- 
     543    nonvar(Obj), 
    541544    '$lgt_current_category_'(Obj, _, _, _, _, _, _), 
    542545    throw(error(permission_error(modify, category, Obj), create_object(Obj, Rels, Dirs, Clauses))). 
    543546 
    544547create_object(Obj, Rels, Dirs, Clauses) :- 
     548    nonvar(Obj), 
    545549    '$lgt_current_protocol_'(Obj, _, _, _, _), 
    546550    throw(error(permission_error(modify, protocol, Obj), create_object(Obj, Rels, Dirs, Clauses))). 
     
    559563 
    560564create_object(Obj, Rels, Dirs, Clauses) :- 
     565    (   var(Obj) -> 
     566        '$lgt_gen_entity_identifier'(0'o, Obj) 
     567    ;   true 
     568    ), 
    561569    '$lgt_clean_pp_clauses', 
    562570    '$lgt_tr_object_id'(Obj, (dynamic)), 
     
    574582 
    575583 
    576 % create_category(+category_identifier, +list, +list, +list) 
     584% create_category(?category_identifier, +list, +list, +list) 
    577585 
    578586create_category(Ctg, Rels, Dirs, Clauses) :- 
    579     (var(Ctg); var(Rels); var(Dirs); var(Clauses)), 
     587    (var(Rels); var(Dirs); var(Clauses)), 
    580588    throw(error(instantiation_error, create_category(Ctg, Rels, Dirs, Clauses))). 
    581589 
    582590create_category(Ctg, Rels, Dirs, Clauses) :- 
     591    nonvar(Ctg), 
    583592    \+ atom(Ctg), 
    584593    throw(error(type_error(category_identifier, Ctg), create_category(Ctg, Rels, Dirs, Clauses))). 
    585594 
    586595create_category(Ctg, Rels, Dirs, Clauses) :- 
     596    nonvar(Ctg), 
    587597    '$lgt_current_category_'(Ctg, _, _, _, _, _, _), 
    588598    throw(error(permission_error(modify, category, Ctg), create_category(Ctg, Rels, Dirs, Clauses))). 
    589599 
    590600create_category(Ctg, Rels, Dirs, Clauses) :- 
     601    nonvar(Ctg), 
    591602    '$lgt_current_object_'(Ctg, _, _, _, _, _, _, _, _, _, _, _, _), 
    592603    throw(error(permission_error(modify, object, Ctg), create_category(Ctg, Rels, Dirs, Clauses))). 
    593604 
    594605create_category(Ctg, Rels, Dirs, Clauses) :- 
     606    nonvar(Ctg), 
    595607    '$lgt_current_protocol_'(Ctg, _, _, _, _), 
    596608    throw(error(permission_error(modify, protocol, Ctg), create_category(Ctg, Rels, Dirs, Clauses))). 
     
    609621 
    610622create_category(Ctg, Rels, Dirs, Clauses) :- 
     623    (   var(Ctg) -> 
     624        '$lgt_gen_entity_identifier'(0'c, Ctg) 
     625    ;   true 
     626    ), 
    611627    '$lgt_clean_pp_clauses', 
    612628    '$lgt_tr_category_id'(Ctg, (dynamic)), 
     
    623639 
    624640 
    625 % create_protocol(+protocol_identifier, +list, +list) 
     641% create_protocol(?protocol_identifier, +list, +list) 
    626642 
    627643create_protocol(Ptc, Rels, Dirs) :- 
    628     (var(Ptc); var(Rels); var(Dirs)), 
     644    (var(Rels); var(Dirs)), 
    629645    throw(error(instantiation_error, create_protocol(Ptc, Rels, Dirs))). 
    630646 
    631647create_protocol(Ptc, Rels, Dirs) :- 
     648    nonvar(Ptc), 
    632649    \+ atom(Ptc), 
    633650    throw(error(type_error(protocol_identifier, Ptc), create_protocol(Ptc, Rels, Dirs))). 
    634651 
    635652create_protocol(Ptc, Rels, Dirs) :- 
     653    nonvar(Ptc), 
    636654    '$lgt_current_protocol_'(Ptc, _, _, _, _), 
    637655    throw(error(permission_error(modify, protocol, Ptc), create_protocol(Ptc, Rels, Dirs))). 
    638656 
    639657create_protocol(Ptc, Rels, Dirs) :- 
     658    nonvar(Ptc), 
    640659    '$lgt_current_object_'(Ptc, _, _, _, _, _, _, _, _, _, _, _, _), 
    641660    throw(error(permission_error(modify, object, Ptc), create_protocol(Ptc, Rels, Dirs))). 
    642661 
    643662create_protocol(Ptc, Rels, Dirs) :- 
     663    nonvar(Ptc), 
    644664    '$lgt_current_category_'(Ptc, _, _, _, _, _, _), 
    645665    throw(error(permission_error(modify, category, Ptc), create_protocol(Ptc, Rels, Dirs))). 
     
    654674 
    655675create_protocol(Ptc, Rels, Dirs) :- 
     676    (   var(Ptc) -> 
     677        '$lgt_gen_entity_identifier'(0'p, Ptc) 
     678    ;   true 
     679    ), 
    656680    '$lgt_clean_pp_clauses', 
    657681    '$lgt_tr_protocol_id'(Ptc, (dynamic)), 
     
    662686    '$lgt_assert_tr_entity', 
    663687    '$lgt_clean_pp_clauses'. 
     688 
     689 
     690 
     691% '$lgt_gen_entity_identifier'(+char_code, -entity_identifier) 
     692 
     693'$lgt_gen_entity_identifier'(Base, Id) :- 
     694    repeat, 
     695        '$lgt_next_integer'(1, New), 
     696        number_codes(New, Codes), 
     697        atom_codes(Id, [Base| Codes]), 
     698    \+ '$lgt_current_protocol_'(Id, _, _, _, _), 
     699    \+ '$lgt_current_object_'(Id, _, _, _, _, _, _, _, _, _, _, _, _), 
     700    \+ '$lgt_current_category_'(Id, _, _, _, _, _, _), 
     701    !. 
     702 
     703 
     704'$lgt_next_integer'(I, I). 
     705'$lgt_next_integer'(I, J) :- 
     706    I2 is I + 1, 
     707    '$lgt_next_integer'(I2, J). 
    664708 
    665709