forked from Homebrew/homebrew-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agda.rb
187 lines (145 loc) · 4.97 KB
/
agda.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
require "language/haskell"
class Agda < Formula
include Language::Haskell::Cabal
desc "Dependently typed functional programming language"
homepage "http://wiki.portal.chalmers.se/agda/"
stable do
url "https://hackage.haskell.org/package/Agda-2.5.4.1/Agda-2.5.4.1.tar.gz"
sha256 "7759aa76936e6a35325c2e186a7546553921775155a426c8edc9a234f58ab72f"
resource "stdlib" do
url "https://github.com/agda/agda-stdlib.git",
:revision => "a1a10b39d35b8fc40e87723a89f5682252d46380"
end
end
bottle do
sha256 "a040cb1a273037a0ed2983be3c7ccddf8c606e762e976f22da5b7c89a7c5ae8a" => :high_sierra
sha256 "b097269cfd028fae6bf73db2eccb41e253d4962340ae962e104196e36868985b" => :sierra
sha256 "8b189b0fa2e7c2332d9ca1239c21f0dca0df714f59eb2fd5dd5e0483f33bd90a" => :el_capitan
end
head do
url "https://github.com/agda/agda.git"
resource "stdlib" do
url "https://github.com/agda/agda-stdlib.git"
end
end
deprecated_option "without-ghc@8.2" => "without-ghc"
deprecated_option "without-malonzo" => "without-ghc"
option "without-stdlib", "Don't install the Agda standard library"
option "without-ghc", "Disable the GHC backend"
depends_on "ghc" => :recommended
if build.with? "ghc"
depends_on "cabal-install" => [:build, :test]
else
depends_on "cabal-install" => :build
depends_on "ghc" => :build
end
depends_on "emacs" => :recommended
def install
# install Agda core
install_cabal_package :using => ["alex", "happy", "cpphs"]
if build.with? "stdlib"
resource("stdlib").stage lib/"agda"
# generate the standard library's bytecode
cd lib/"agda" do
cabal_sandbox :home => buildpath, :keep_lib => true do
cabal_install "--only-dependencies"
cabal_install
system "GenerateEverything"
end
end
# generate the standard library's documentation and vim highlighting files
cd lib/"agda" do
system bin/"agda", "-i", ".", "-i", "src", "--html", "--vim", "README.agda"
end
end
# compile the included Emacs mode
if build.with? "emacs"
system bin/"agda-mode", "compile"
elisp.install_symlink Dir["#{share}/*/Agda-#{version}/emacs-mode/*"]
end
end
def caveats
s = ""
if build.with? "stdlib"
s += <<~EOS
To use the Agda standard library by default:
mkdir -p ~/.agda
echo #{HOMEBREW_PREFIX}/lib/agda/standard-library.agda-lib >>~/.agda/libraries
echo standard-library >>~/.agda/defaults
EOS
end
s
end
test do
simpletest = testpath/"SimpleTest.agda"
simpletest.write <<~EOS
module SimpleTest where
data ℕ : Set where
zero : ℕ
suc : ℕ → ℕ
infixl 6 _+_
_+_ : ℕ → ℕ → ℕ
zero + n = n
suc m + n = suc (m + n)
infix 4 _≡_
data _≡_ {A : Set} (x : A) : A → Set where
refl : x ≡ x
cong : ∀ {A B : Set} (f : A → B) {x y} → x ≡ y → f x ≡ f y
cong f refl = refl
+-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
EOS
stdlibtest = testpath/"StdlibTest.agda"
stdlibtest.write <<~EOS
module StdlibTest where
open import Data.Nat
open import Relation.Binary.PropositionalEquality
+-assoc : ∀ m n o → (m + n) + o ≡ m + (n + o)
+-assoc zero _ _ = refl
+-assoc (suc m) n o = cong suc (+-assoc m n o)
EOS
iotest = testpath/"IOTest.agda"
iotest.write <<~EOS
module IOTest where
open import Agda.Builtin.IO
open import Agda.Builtin.Unit
postulate
return : ∀ {A : Set} → A → IO A
{-# COMPILED return (\\_ -> return) #-}
main : _
main = return tt
EOS
stdlibiotest = testpath/"StdlibIOTest.agda"
stdlibiotest.write <<~EOS
module StdlibIOTest where
open import IO
main : _
main = run (putStr "Hello, world!")
EOS
# typecheck a simple module
system bin/"agda", simpletest
# typecheck a module that uses the standard library
if build.with? "stdlib"
system bin/"agda", "-i", lib/"agda"/"src", stdlibtest
end
# compile a simple module using the JS backend
system bin/"agda", "--js", simpletest
# test the GHC backend
if build.with? "ghc"
cabal_sandbox do
cabal_install "text", "ieee754"
dbpath = Dir["#{testpath}/.cabal-sandbox/*-packages.conf.d"].first
dbopt = "--ghc-flag=-package-db=#{dbpath}"
# compile and run a simple program
system bin/"agda", "-c", dbopt, iotest
assert_equal "", shell_output(testpath/"IOTest")
# compile and run a program that uses the standard library
if build.with? "stdlib"
system bin/"agda", "-c", "-i", lib/"agda"/"src", dbopt, stdlibiotest
assert_equal "Hello, world!", shell_output(testpath/"StdlibIOTest")
end
end
end
end
end