This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/misc/buildswiatoms

63 lines
1.8 KiB
Plaintext
Raw Normal View History

2010-05-06 11:38:09 +01:00
:- use_module(library(lineutils),
[file_filter_with_init/5,
split/3]).
:- use_module(library(lists),
[append/2]).
:- initialization(main).
:- yap_flag(write_strings,on).
main :-
warning(Warning),
nb_setval(atom_counter,0),
nb_setval(functor_counter,0),
file_filter_with_init('misc/SWIATOMS','include/dswiatoms.h',gen_defs, Warning, ['dswiatoms.h']),
open('include/dswiatoms.h',append,W),
nb_getval(atom_counter,SWIAtoms),
nb_getval(functor_counter,SWIFunctors),
format(W,'~n~n#define N_SWI_ATOMS ~d~n',[SWIAtoms]),
format(W,'#define N_SWI_FUNCTORS ~d~n',[SWIFunctors]),
HashSizeBits is msb(SWIAtoms+SWIFunctors)+2,
HashSize is 2^HashSizeBits,
format(W,'#define N_SWI_HASH_BITS ~d~n',[HashSizeBits]),
format(W,'#define N_SWI_HASH ~d~n',[HashSize]),
close(W),
file_filter_with_init('misc/SWIATOMS','H/iswiatoms.h',gen_init, Warning, ['iswiatoms.h']).
warning('~n /* This file, ~a, was generated automatically~n by calling \"yap -L misc/buildswiatoms\"~n and is based on SWIATOMS, copied from the SWI-Prolog distribution~n please do not update */~n~n').
gen_defs(Inp,Out) :-
split(Inp," ",["A",Atom,_]), !,
nb_getval(atom_counter, Pos),
NPos is Pos+1,
nb_setval(atom_counter, NPos),
2010-12-05 00:07:22 +00:00
number_codes(Pos, Val),
append(["#define ATOM_",Atom," ((atom_t)(",Val,"*2+1))"], Out).
2010-05-06 11:38:09 +01:00
gen_defs(Inp,Out) :-
split(Inp," ",["F",Functor,Arity]), !,
nb_getval(functor_counter, Pos),
NPos is Pos+1,
nb_setval(functor_counter, NPos),
2010-12-05 00:07:22 +00:00
number_codes(Pos, Val),
append(["#define FUNCTOR_",Functor,Arity," ((functor_t)(",Val,"*4+2))"], Out).
2010-05-06 11:38:09 +01:00
gen_init(Inp,Out) :-
split(Inp," ",["A",_,String]), !,
2013-10-08 13:04:30 +01:00
append([" YAP_AtomToInt(Yap_LookupAtom(",String,"));"],Out).
2010-05-06 11:38:09 +01:00
gen_init(Inp,Out) :-
split(Inp," ",["F",String,Arity]), !,
append([" SWI_Functors[j++] = Yap_MkFunctor(SWIAtomToAtom(ATOM_",String,"),",Arity,");"],Out).