···11+# Lambda Lisp has several backends, here we are using
22+# the blc one. Ideally, this should be made into several
33+# packages such as lambda-lisp-blc, lambda-lisp-lazyk,
44+# lambda-lisp-clamb, etc.
55+66+{ lib
77+, gccStdenv
88+, fetchFromGitHub
99+, fetchurl
1010+, runtimeShell
1111+}:
1212+1313+let
1414+ stdenv = gccStdenv;
1515+ s = import ./sources.nix { inherit fetchurl fetchFromGitHub; };
1616+in
1717+stdenv.mkDerivation rec {
1818+ pname = "lambda-lisp-blc";
1919+ version = s.lambdaLispVersion;
2020+ src = s.src;
2121+ flatSrc = s.flatSrc;
2222+ blcSrc = s.blcSrc;
2323+2424+ installPhase = ''
2525+ runHook preInstall
2626+2727+ mkdir -p ./build
2828+ cp $blcSrc ./build/Blc.S
2929+ cp $flatSrc ./build/flat.lds
3030+ cd build;
3131+ cat Blc.S | sed -e 's/#define.*TERMS.*//' > Blc.ext.S;
3232+ $CC -c -DTERMS=50000000 -o Blc.o Blc.ext.S
3333+ ld.bfd -o Blc Blc.o -T flat.lds
3434+ cd ..;
3535+ mv build/Blc ./bin
3636+ install -D -t $out/bin bin/Blc
3737+ install -D -t $out/lib bin/lambdalisp.blc
3838+3939+ cd build;
4040+ $CC ../tools/asc2bin.c -O2 -o asc2bin;
4141+ cd ..;
4242+ mv build/asc2bin ./bin;
4343+ chmod 755 ./bin/asc2bin;
4444+ install -D -t $out/bin bin/asc2bin
4545+4646+ echo -e "#!${runtimeShell}\n( cat $out/lib/lambdalisp.blc | $out/bin/asc2bin; cat ) | $out/bin/Blc" > lambda-lisp-blc
4747+ chmod +x lambda-lisp-blc
4848+4949+ install -D -t $out/bin lambda-lisp-blc
5050+ runHook postInstall
5151+ '';
5252+5353+ doInstallCheck = true;
5454+5555+ installCheckPhase = ''
5656+ runHook preInstallCheck
5757+5858+ a=$(echo "(* (+ 1 2 3 4 5 6 7 8 9 10) 12020569 (- 2 5))" | $out/bin/lambda-lisp-blc | tr -d "> ");
5959+ test $a == -1983393885
6060+6161+ runHook postInstallCheck
6262+ '';
6363+6464+ meta = with lib; {
6565+ description = "A Lisp interpreter written in untyped lambda calculus";
6666+ homepage = "https://github.com/woodrush/lambdalisp";
6767+ longDescription = ''
6868+ LambdaLisp is a Lisp interpreter written as a closed untyped lambda calculus term.
6969+ It is written as a lambda calculus term LambdaLisp = λx. ... which takes a string
7070+ x as an input and returns a string as an output. The input x is the Lisp program
7171+ and the user's standard input, and the output is the standard output. Characters
7272+ are encoded into lambda term representations of natural numbers using the Church
7373+ encoding, and strings are encoded as a list of characters with lists expressed as
7474+ lambdas in the Mogensen-Scott encoding, so the entire computation process solely
7575+ consists of the beta-reduction of lambda terms, without introducing any
7676+ non-lambda-type object.
7777+ '';
7878+ license = licenses.mit;
7979+ maintainers = with maintainers; [ cafkafk ];
8080+ platforms = [ "x86_64-linux" ];
8181+ };
8282+}