piet.scm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2020 Jesse Gibbons <jgibbons2357+guix@gmail.com>
  3. ;;; Copyright © 2020 Tobias Geerinckx-Rice <me@tobias.gr>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu packages piet)
  20. #:use-module (guix packages)
  21. #:use-module (guix download)
  22. #:use-module (guix git-download)
  23. #:use-module ((guix licenses) #:prefix license:)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (gnu packages gd)
  26. #:use-module (gnu packages groff)
  27. #:use-module (gnu packages image)
  28. #:use-module (gnu packages netpbm)
  29. #:use-module (gnu packages perl)
  30. #:use-module (gnu packages tcl))
  31. (define-public npiet
  32. (package
  33. (name "npiet")
  34. (version "1.3f")
  35. (source (origin
  36. (method url-fetch)
  37. (uri (string-append "https://www.bertnase.de/npiet/npiet-"
  38. version ".tar.gz"))
  39. (sha256
  40. (base32
  41. "0nl59fhdqqr7nslxdirdn8nvlq5wws67c7jyx2ckbmxbc9h8bv9d"))))
  42. (build-system gnu-build-system)
  43. (arguments
  44. `(#:phases
  45. (modify-phases %standard-phases
  46. (add-after 'install 'wrap-binaries
  47. (lambda* (#:key outputs #:allow-other-keys)
  48. (let ((out (assoc-ref outputs "out")))
  49. (wrap-program (string-append out "/bin/npietedit")
  50. `("PATH" ":" prefix (,(dirname (which "wish")))))
  51. #t))))))
  52. (inputs
  53. `(("gd" ,gd)
  54. ("giflib" ,giflib)
  55. ("libpng" ,libpng)
  56. ("tk" ,tk)))
  57. (native-inputs `(("groff" ,groff)))
  58. (synopsis "Piet interpreter")
  59. (description
  60. "Npiet is an interpreter for the Piet programming language. Instead of
  61. text, Piet programs are pictures. Commands are determined based on changes in
  62. color.
  63. This package includes:
  64. @enumerate
  65. @item @command{npiet}, a Piet interpreter with debugging capabilities
  66. @item @command{npiet-foogol}, a program that builds a Piet program from Foogol,
  67. an Algol-like language
  68. @item @command{npietedit}, an editor for Piet programs.
  69. @end enumerate\n")
  70. (home-page "https://www.bertnase.de/npiet/")
  71. (license license:gpl2+)))
  72. (define-public piet-toolchain
  73. (let ((commit "f002ff6a924a6bbace5eef94f3be06f425e7f590")
  74. (revision "0"))
  75. (package
  76. (name "piet-toolchain")
  77. (version (git-version "0.0.0" revision commit))
  78. (source
  79. (origin
  80. (method git-fetch)
  81. (uri (git-reference
  82. (url "https://github.com/sl236/Piet")
  83. (commit commit)))
  84. (file-name (git-file-name name version))
  85. (sha256
  86. (base32 "0xwbhwizfbn080fmrgavaz3b939brycmlar3m5px9avl2b68c816"))
  87. (modules '((guix build utils)))
  88. (snippet
  89. '(begin
  90. ;; Remove a bundled fork of Marc Majcher's Piet interpreter.
  91. (delete-file-recursively "interpreter")
  92. #t))))
  93. (build-system gnu-build-system)
  94. (arguments
  95. `(#:modules ((guix build gnu-build-system)
  96. (guix build utils)
  97. (srfi srfi-26))
  98. #:phases
  99. (modify-phases %standard-phases
  100. (delete 'configure) ; no configure script
  101. (delete 'build) ; nothing to build
  102. (delete 'check) ; run our own tests below
  103. (replace 'install
  104. (lambda* (#:key outputs #:allow-other-keys)
  105. (let* ((out (assoc-ref outputs "out"))
  106. (bin (string-append out "/bin"))
  107. (doc (string-append out "/share/doc/"
  108. ,name "-" ,version)))
  109. (for-each (lambda (script)
  110. (install-file script bin)
  111. (wrap-program (string-append bin "/" script)
  112. `("PERL5LIB" ":" = (,(getenv "PERL5LIB")))))
  113. (list "piet-assembler"
  114. "piet-compiler"))
  115. ;; Fix an odd mode.
  116. (chmod "compiler-samples/test-binary-ops.script" #o644)
  117. (for-each (lambda (file) ; INSTALL-FILE is not recursive
  118. (copy-recursively file
  119. (string-append doc "/" file)))
  120. (list "assembler-samples"
  121. "compiler-samples"
  122. "README.md")) ; includes the licence grant
  123. #t)))
  124. (add-after 'install 'check
  125. (lambda* (#:key outputs tests? #:allow-other-keys)
  126. (let* ((out (assoc-ref outputs "out"))
  127. (bin (string-append out "/bin")))
  128. (when tests?
  129. (unsetenv "PERL5LIB") ; test the wrapping
  130. ;; Compile all scripts assemble all Piets.
  131. (for-each (lambda (file)
  132. (system (string-append bin "/piet-compiler "
  133. file ">"
  134. file ".piet")))
  135. (find-files "." "\\.script$"))
  136. (for-each (lambda (file)
  137. (system (string-append bin "/piet-assembler "
  138. file "|pnmtopng>"
  139. file ".png")))
  140. (find-files "." "\\.piet$"))
  141. ;; Don't run the interactive one.
  142. (delete-file "assembler-samples/quest.piet.png")
  143. (for-each (cut invoke "npiet" <>)
  144. (find-files "." "\\.png$"))
  145. #t)))))))
  146. (native-inputs
  147. ;; For our tests.
  148. `(("netpbm" ,netpbm)
  149. ("npiet" ,npiet)))
  150. (inputs
  151. `(("perl" ,perl)
  152. ("perl-parse-recdescent" ,perl-parse-recdescent)))
  153. (home-page "https://www.toothycat.net/wiki/wiki.pl?MoonShadow/Piet")
  154. (synopsis "Piet compiler and assembler")
  155. (description
  156. "This package provides a compiler and assembler that target the Piet
  157. graphical programming language.
  158. @command{piet-assembler} converts Piet assembler instructions (e.g.,
  159. @code{push}, @code{add}, @code{switch}, @code{outn}) and directives into an
  160. executable @code{netpbm} image of the corresponding Piet program.
  161. @command{piet-compiler} compiles a C-like high-level language into assembly
  162. source understood by @command{piet-assembler}. It supports common arithmetic
  163. and boolean logic operators (though not bitwise manipulation), flow control
  164. (@code{if}, @code{for}, @code{while}), recursive functions, in-line assembler,
  165. and input/output intrinsics. The only supported data type is the integer.
  166. The language is documented only by the compiler's Perl source code and the
  167. included samples.")
  168. (license license:cc-by-sa4.0))))