build defs.pl
This commit is contained in:
parent
32e77f6d73
commit
731c59088e
|
|
@ -3,5 +3,6 @@ GPLC_OPTIONS="--min-size"
|
|||
thun: thun.pl parser.pl
|
||||
gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl
|
||||
|
||||
defs.pl: meta-defs.pl defs.txt
|
||||
gprolog --consult-file meta-defs.pl defs.txt
|
||||
defs.pl: meta-defs.pl parser.pl defs.txt
|
||||
gprolog --consult-file meta-defs.pl --consult-file parser.pl --query-goal do > defs.pl
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,81 @@
|
|||
GNU Prolog 1.4.4 (64 bits)
|
||||
Compiled Oct 11 2018, 14:29:28 with cc
|
||||
By Daniel Diaz
|
||||
Copyright (C) 1999-2013 Daniel Diaz
|
||||
compiling /home/sforman/src/Joypy/thun/gnu-prolog/meta-defs.pl for byte code...
|
||||
/home/sforman/src/Joypy/thun/gnu-prolog/meta-defs.pl compiled, 40 lines read - 4480 bytes written, 6 ms
|
||||
compiling /home/sforman/src/Joypy/thun/gnu-prolog/parser.pl for byte code...
|
||||
/home/sforman/src/Joypy/thun/gnu-prolog/parser.pl compiled, 72 lines read - 7481 bytes written, 8 ms
|
||||
| ?- do.
|
||||
def(--,[1,-]).
|
||||
def(?,[dup,bool]).
|
||||
def(++,[1,+]).
|
||||
def(anamorphism,[[pop,[]],swap,[dip,swons],genrec]).
|
||||
def(app1,[grba,infrst]).
|
||||
def(app2,[[grba,swap,grba,swap],dip,[infrst],cons,ii]).
|
||||
def(app3,[3,appN]).
|
||||
def(appN,[[grabN],cons,dip,map,disenstacken]).
|
||||
def(at,[drop,first]).
|
||||
def(average,[[sum,1,.0,*],[size],cleave,/]).
|
||||
def(b,[[i],dip,i]).
|
||||
def(binary,[unary,popd]).
|
||||
def(ccons,[cons,cons]).
|
||||
def(cleave,[fork,popdd]).
|
||||
def(clop,[cleave,popdd]).
|
||||
def(codireco,[cons,dip,rest,cons]).
|
||||
def(dinfrirst,[dip,infrst]).
|
||||
def(disenstacken,[?,[uncons,?],loop,pop]).
|
||||
def(down_to_zero,[[0,>],[dup,--],while]).
|
||||
def(drop,[[rest],times]).
|
||||
def(dupd,[[dup],dip]).
|
||||
def(dupdd,[[dup],dipd]).
|
||||
def(dupdipd,[dup,dipd]).
|
||||
def(enstacken,[stack,[clear],dip]).
|
||||
def(flatten,[[],swap,[concat],step]).
|
||||
def(fork,[[i],app2]).
|
||||
def(fourth,[rest,third]).
|
||||
def(gcd,[true,[tuck,mod,dup,0,>],loop,pop]).
|
||||
def(grabN,[[],swap,[cons],times]).
|
||||
def(grba,[[stack,popd],dip]).
|
||||
def(hypot,[[sqr],ii,+,sqrt]).
|
||||
def(ifte,[[nullary],dipd,swap,branch]).
|
||||
def(ii,[[dip],dupdip,i]).
|
||||
def(infra,[swons,swaack,[i],dip,swaack]).
|
||||
def(infrst,[infra,first]).
|
||||
def(make_generator,[[codireco],ccons]).
|
||||
def(neg,[0,swap,-]).
|
||||
def(nullary,[[stack],dinfrirst]).
|
||||
def(of,[swap,at]).
|
||||
def(pam,[[i],map]).
|
||||
def(pm,[[+],[-],clop]).
|
||||
def(popd,[[pop],dip]).
|
||||
def(popdd,[[pop],dipd]).
|
||||
def(popop,[pop,pop]).
|
||||
def(popopd,[[popop],dip]).
|
||||
def(popopdd,[[popop],dipd]).
|
||||
def(primrec,[[i],genrec]).
|
||||
def(product,[1,swap,[*],step]).
|
||||
def(quoted,[[unit],dip]).
|
||||
def(range,[[0,<=],[1,-,dup],anamorphism]).
|
||||
def(range_to_zero,[unit,[down_to_zero],infra]).
|
||||
def(reverse,[[],swap,shunt]).
|
||||
def(rrest,[rest,rest]).
|
||||
def(run,[[],swap,infra]).
|
||||
def(second,[rest,first]).
|
||||
def(shift,[uncons,[swons],dip]).
|
||||
def(shunt,[[swons],step]).
|
||||
def(size,[0,swap,[pop,++],step]).
|
||||
def(split_at,[[drop],[take],clop]).
|
||||
def(sqr,[dup,*]).
|
||||
def(step_zero,[0,roll>,step]).
|
||||
def(sum,[0,swap,[+],step]).
|
||||
def(swons,[swap,cons]).
|
||||
def(take,[[],rolldown,[shift],times,pop]).
|
||||
def(ternary,[binary,popd]).
|
||||
def(third,[rest,second]).
|
||||
def(unary,[nullary,popd]).
|
||||
def(unit,[[],cons]).
|
||||
def(unquoted,[[i],dip]).
|
||||
def(unswons,[uncons,swap]).
|
||||
def(while,[swap,[nullary],cons,dup,dipd,concat,loop]).
|
||||
def(x,[dup,i]).
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
/*
|
||||
Definitions
|
||||
*/
|
||||
|
||||
do :- assert_defs(`defs.txt`), print_defs, halt.
|
||||
|
||||
joy_def(def(Def, Body)) --> symbol(Def), blanks, "==", joy_parse(Body).
|
||||
|
||||
joy_defs --> blanks, joy_def(Def), {assert_def(Def)}, blanks, joy_defs.
|
||||
joy_defs --> [].
|
||||
|
||||
assert_defs(DefsFile) :-
|
||||
read_file_to_codes(DefsFile, Codes, []),
|
||||
phrase(joy_defs, Codes).
|
||||
|
||||
assert_def(def(Def, Body)) :-
|
||||
retractall(def(Def, _)),
|
||||
assertz(def(Def, Body)).
|
||||
|
||||
|
||||
|
||||
read_file_to_codes(File, Codes, _) :-
|
||||
open(File, read, Stream),
|
||||
stream_to_codes(Stream, Codes),
|
||||
close(Stream).
|
||||
|
||||
|
||||
stream_to_codes(Stream, Codes) :-
|
||||
get_code(Stream, Code),
|
||||
stream_to_codes(Code, Stream, Codes).
|
||||
|
||||
stream_to_codes(-1, _, []) :- !.
|
||||
stream_to_codes(Ch, Stream, [Ch|Codes]) :- stream_to_codes(Stream, Codes).
|
||||
|
||||
print_defs :-
|
||||
findall(def(Name, Body), def(Name, Body), List),
|
||||
maplist(print_def, List).
|
||||
|
||||
print_def(Def) :- write(Def), write(`.`), nl.
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ char(Ch) --> [Ch], { Ch \== 0'[, Ch \== 0'], Ch >= 33, Ch =< 126 }.
|
|||
blanks --> blank, !, blanks.
|
||||
blanks --> [].
|
||||
|
||||
blank --> [32].
|
||||
blank --> [32] | [13] | [10].
|
||||
|
||||
|
||||
% TODO: negative numbers, floats, scientific notation.
|
||||
|
|
|
|||
Loading…
Reference in New Issue