From 2e1f598aa2e0a2adfec3cb72a8d09d6e0a94174a Mon Sep 17 00:00:00 2001 From: Simon Forman Date: Sun, 11 Aug 2019 21:30:02 -0700 Subject: [PATCH] Experiment with putting logic vars on the stack. --- thun/gnu-prolog/defs.pl | 1 + thun/gnu-prolog/defs.txt | 1 + thun/gnu-prolog/parser.pl | 6 ++++-- thun/gnu-prolog/thun.pl | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/thun/gnu-prolog/defs.pl b/thun/gnu-prolog/defs.pl index 4ad0bb6..43851e2 100644 --- a/thun/gnu-prolog/defs.pl +++ b/thun/gnu-prolog/defs.pl @@ -28,6 +28,7 @@ def(grba,[[stack,popd],dip]). def(hypot,[[sqr],ii,+,sqrt]). def(ifte,[[nullary],dipd,swap,branch]). def(ii,[[dip],dupdip,i]). +def(infer,[thunk,dup,rollup,infra]). def(infra,[swons,swaack,[i],dip,swaack]). def(infrst,[infra,first]). def(least_fraction,[dup,[gcd],infra,[div],concat,map]). diff --git a/thun/gnu-prolog/defs.txt b/thun/gnu-prolog/defs.txt index f31f284..7be86c2 100644 --- a/thun/gnu-prolog/defs.txt +++ b/thun/gnu-prolog/defs.txt @@ -30,6 +30,7 @@ grba == [stack popd] dip hypot == [sqr] ii + sqrt ifte == [nullary] dipd swap branch ii == [dip] dupdip i +infer == thunk dup rollup infra infra == swons swaack [i] dip swaack infrst == infra first least_fraction == dup [gcd] infra [div] concat map diff --git a/thun/gnu-prolog/parser.pl b/thun/gnu-prolog/parser.pl index ab43ac7..fadd6c9 100644 --- a/thun/gnu-prolog/parser.pl +++ b/thun/gnu-prolog/parser.pl @@ -100,8 +100,10 @@ format_joy([T]) --> format_term(T), !. format_joy([T|S]) --> format_term(T), " ", format_joy(S). format_joy([]) --> []. -format_term(N) --> {number(N), number_codes(N, Codes)}, Codes. -format_term(A) --> { atom(A), atom_codes(A, Codes)}, Codes. +format_term(N) --> {number(N), number_codes(N, Codes)}, Codes. +format_term(A) --> { atom(A), atom_codes(A, Codes)}, Codes. +format_term(V) --> { var(V), write_to_codes(Codes, V)}, Codes. format_term([A|As]) --> "[", format_joy([A|As]), "]". +format_term(F) --> { write_to_codes(Codes, F)}, Codes. diff --git a/thun/gnu-prolog/thun.pl b/thun/gnu-prolog/thun.pl index 3eb8a97..b3651b6 100644 --- a/thun/gnu-prolog/thun.pl +++ b/thun/gnu-prolog/thun.pl @@ -91,6 +91,7 @@ func(clear, _ , []). func(first, [[X|_]|S], [X|S]). func(rest, [[_|X]|S], [X|S]). func(unit, [X|S], [[X]|S]). +func(thunk, S , [X|S]). func(rolldown, [A, B, C|S], [B, C, A|S]). func(dupd, [A, B|S], [A, B, B|S]).