1# Lambda Lisp has several backends, here we are using 2# the blc one. Ideally, this should be made into several 3# packages such as lambda-lisp-blc, lambda-lisp-lazyk, 4# lambda-lisp-clamb, etc. 5 6{ lib 7, gccStdenv 8, fetchFromGitHub 9, fetchurl 10, runtimeShell 11}: 12 13let 14 stdenv = gccStdenv; 15 s = import ./sources.nix { inherit fetchurl fetchFromGitHub; }; 16in 17stdenv.mkDerivation rec { 18 pname = "lambda-lisp-blc"; 19 version = s.lambdaLispVersion; 20 src = s.src; 21 flatSrc = s.flatSrc; 22 blcSrc = s.blcSrc; 23 24 installPhase = '' 25 runHook preInstall 26 27 mkdir -p ./build 28 cp $blcSrc ./build/Blc.S 29 cp $flatSrc ./build/flat.lds 30 cd build; 31 cat Blc.S | sed -e 's/#define.*TERMS.*//' > Blc.ext.S; 32 $CC -c -DTERMS=50000000 -o Blc.o Blc.ext.S 33 ld.bfd -o Blc Blc.o -T flat.lds 34 cd ..; 35 mv build/Blc ./bin 36 install -D -t $out/bin bin/Blc 37 install -D -t $out/lib bin/lambdalisp.blc 38 39 cd build; 40 $CC ../tools/asc2bin.c -O2 -o asc2bin; 41 cd ..; 42 mv build/asc2bin ./bin; 43 chmod 755 ./bin/asc2bin; 44 install -D -t $out/bin bin/asc2bin 45 46 echo -e "#!${runtimeShell}\n( cat $out/lib/lambdalisp.blc | $out/bin/asc2bin; cat ) | $out/bin/Blc" > lambda-lisp-blc 47 chmod +x lambda-lisp-blc 48 49 install -D -t $out/bin lambda-lisp-blc 50 runHook postInstall 51 ''; 52 53 doInstallCheck = true; 54 55 installCheckPhase = '' 56 runHook preInstallCheck 57 58 a=$(echo "(* (+ 1 2 3 4 5 6 7 8 9 10) 12020569 (- 2 5))" | $out/bin/lambda-lisp-blc | tr -d "> "); 59 test $a == -1983393885 60 61 runHook postInstallCheck 62 ''; 63 64 meta = with lib; { 65 description = "A Lisp interpreter written in untyped lambda calculus"; 66 homepage = "https://github.com/woodrush/lambdalisp"; 67 longDescription = '' 68 LambdaLisp is a Lisp interpreter written as a closed untyped lambda calculus term. 69 It is written as a lambda calculus term LambdaLisp = λx. ... which takes a string 70 x as an input and returns a string as an output. The input x is the Lisp program 71 and the user's standard input, and the output is the standard output. Characters 72 are encoded into lambda term representations of natural numbers using the Church 73 encoding, and strings are encoded as a list of characters with lists expressed as 74 lambdas in the Mogensen-Scott encoding, so the entire computation process solely 75 consists of the beta-reduction of lambda terms, without introducing any 76 non-lambda-type object. 77 ''; 78 license = licenses.mit; 79 maintainers = with maintainers; [ cafkafk ]; 80 platforms = [ "x86_64-linux" ]; 81 }; 82}