From e49b0b70cba49c71ccdaa3d0a527f94ce2b44a22 Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sat, 10 Aug 2019 22:03:44 -0700 Subject: [PATCH] Build defs.pl from defs.txt. --- thun/gnu-prolog/Makefile | 4 ++-- thun/gnu-prolog/defs.pl | 12 +----------- thun/gnu-prolog/defs.txt | 5 ++--- thun/gnu-prolog/meta-defs.pl | 6 ++++-- thun/gnu-prolog/thun.pl | 10 ---------- 5 files changed, 9 insertions(+), 28 deletions(-) diff --git a/thun/gnu-prolog/Makefile b/thun/gnu-prolog/Makefile index 486a33e..527d872 100644 --- a/thun/gnu-prolog/Makefile +++ b/thun/gnu-prolog/Makefile @@ -1,8 +1,8 @@ GPLC_OPTIONS="--min-size" thun: thun.pl parser.pl defs.pl - gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl + gplc $(GPLC_OPTIONS) -o thun thun.pl parser.pl defs.pl defs.pl: meta-defs.pl parser.pl defs.txt - gprolog --consult-file meta-defs.pl --consult-file parser.pl --query-goal do > defs.pl + gprolog --consult-file meta-defs.pl --consult-file parser.pl --query-goal do diff --git a/thun/gnu-prolog/defs.pl b/thun/gnu-prolog/defs.pl index 17230e7..1007c10 100644 --- a/thun/gnu-prolog/defs.pl +++ b/thun/gnu-prolog/defs.pl @@ -1,12 +1,3 @@ -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,+]). @@ -16,7 +7,6 @@ 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]). @@ -67,7 +57,7 @@ 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(step_zero,[0,rollup,step]). def(sum,[0,swap,[+],step]). def(swons,[swap,cons]). def(take,[[],rolldown,[shift],times,pop]). diff --git a/thun/gnu-prolog/defs.txt b/thun/gnu-prolog/defs.txt index 3ad9205..2963ed1 100644 --- a/thun/gnu-prolog/defs.txt +++ b/thun/gnu-prolog/defs.txt @@ -7,7 +7,6 @@ app2 == [grba swap grba swap] dip [infrst] cons ii app3 == 3 appN appN == [grabN] cons dip map disenstacken at == drop first -average == [sum 1.0 *] [size] cleave / b == [i] dip i binary == unary popd ccons == cons cons @@ -58,7 +57,7 @@ shunt == [swons] step size == 0 swap [pop ++] step split_at == [drop] [take] clop sqr == dup * -step_zero == 0 roll> step +step_zero == 0 rollup step sum == 0 swap [+] step swons == swap cons take == [] rolldown [shift] times pop @@ -69,4 +68,4 @@ unit == [] cons unquoted == [i] dip unswons == uncons swap while == swap [nullary] cons dup dipd concat loop -x == dup i \ No newline at end of file +x == dup i diff --git a/thun/gnu-prolog/meta-defs.pl b/thun/gnu-prolog/meta-defs.pl index a78bd4c..da96665 100644 --- a/thun/gnu-prolog/meta-defs.pl +++ b/thun/gnu-prolog/meta-defs.pl @@ -34,7 +34,9 @@ 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). + open(`defs.pl`, write, Stream), + maplist(print_def(Stream), List), + close(Stream). -print_def(Def) :- write(Def), write(`.`), nl. +print_def(Stream, Def) :- write(Stream, Def), write(Stream, `.`), nl(Stream). diff --git a/thun/gnu-prolog/thun.pl b/thun/gnu-prolog/thun.pl index 52d80c0..1b3fa79 100644 --- a/thun/gnu-prolog/thun.pl +++ b/thun/gnu-prolog/thun.pl @@ -196,16 +196,6 @@ prepare_mapping( P, S, [T|In], Acc, Out) :- - - -/* -Definitions -*/ - -def(x, [dup, i]). - - - /* Main Loop */