git @ Cat's Eye Technologies Quylthulg / rel_1_0_2019_0326
Merge pull request #3 from catseye/develop-2019-2 Develop 2019-2 Chris Pressey authored 1 year, 5 months ago GitHub committed 1 year, 5 months ago
6 changed file(s) with 105 addition(s) and 51 deletion(s). Raw diff Collapse all Expand all
3232
3333 Also added `-m` option to the reference implementation, which tells it to
3434 use the monadic interpreter.
35
36 Version 1.0 revision 2019.0321
37 ------------------------------
38
39 Added a demo of a web-based interpreter, made by compiling Qlzqqlzuup.hs
40 to Javascript using the Haste compiler, and sticking that into an HTML
41 page along with some support glue.
42
43 Modernized the build system; `bin/qlzqqlzuup` is now a shell script that
44 runs the compiled executable if it can be found, or tries to run the source
45 using `runhaskell` if possible, or tries to run the source using `runhugs`
46 if possible, in that order.
47
48 Forgot to update this HISTORY file.
49
50 Version 1.0 revision 2019.0326
51 ------------------------------
52
53 Changed how Qlzqqlzuup, the Lord of Flesh depicts the final result of
54 running a Quylthulg program.
55
56 Previously, it would simply output the standard derived `show`
57 representation of its internal Haskell data structure. It now formats the
58 result as a literal term in Quylthulg's concrete syntax.
59
60 Such terms can be round-tripped: when treated as Quylthulg programs themselves,
61 they will evaluate to themselves. (This is true in almost all cases.
62 Discovering the one case where it is not true is left as an exercise for the
63 reader.)
64
65 This was done to make the output, if not more readable, then more idiomatic
66 (in some local sense).
67
68 Since the language doesn't really define how the result of a Quylthulg
69 program should be represented, this version number of the language remains
70 unchanged.
71
72 Also fixed a couple of typos in the README.
258258
259259 The third school (a school of fish) believes that comments are valuable,
260260 not just as comments, but also as integral (or at least distracting)
261 part of the computation, and champions their use in Quylthulg as string
261 parts of the computation, and champions their use in Quylthulg as string
262262 literals involved in expressions that are ultimately discarded. For
263 example, `<"Addition is fun!"<+1+2+<`.
263 example, `<~$Addition is fun!$<+1+2+<`.
264264
265265 ### Integration with the Rest of the Language
266266
33
44 if command -v ghc >/dev/null 2>&1; then
55 echo "building $PROG.exe with ghc"
6 (cd src && ghc --make Main.hs -o ../bin/$PROG.exe)
6 (cd src && ghc --make Main.hs -o ../bin/$PROG.exe) || exit 1
77 else
88 echo "ghc not found, not building $PROG.exe"
99 fi
1010
1111 if command -v hastec >/dev/null 2>&1; then
1212 echo "building $PROG.js with hastec"
13 (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js)
13 (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js) || exit 1
1414 else
1515 echo "hastec not found, not building $PROG.js"
1616 fi
00 #!/bin/sh
11
2 rm -f src/*.hi src/*.o src/*.jsmod
2 rm -f src/*.hi src/*.o src/*.jsmod bin/*.exe
3030 --
3131
3232 --
33 -- Qlzqqlzuup.hs revision 2015.0101
33 -- Qlzqqlzuup.hs revision 2019.0326
3434 --
3535 -- 'Qlzqqlzuup, the Lord of Flesh': Reference interpreter for
3636 -- The Quylthulg Programming Language
7676 | Label String Term
7777 | Goto String
7878 | Abort
79 deriving (Show, Ord, Eq)
79 deriving (Ord, Eq)
80
81 instance Show Term where
82 show (Int i) = show i
83 show (Str s) = "~" ++ (if elem '$' s then (show s) else "$" ++ s ++ "$")
84 show (Cons h t) = "[" ++ show h ++ showTail t
85 where showTail Null = "]"
86 showTail (Cons h t) = "," ++ show h ++ showTail t
87 showTail x = "|" ++ show x ++ "]"
88 show Null = "null"
89 show (Label s t) = ":" ++ s ++ ":" ++ show t
90 show (Goto s) = "goto " ++ "$" ++ s ++ "$"
91 show Abort = "abort"
92
8093
8194 isCons (Cons _ _) = True
8295 isCons _ = False
1010 --------------------
1111
1212 | 5
13 = Int 5
13 = 5
1414
1515 | +6+9+
16 = Int 15
16 = 15
1717
1818 | +1+*7*-8-1-*+
19 = Int 50
19 = 50
2020
2121 String expressions.
2222 -------------------
2323
24 | ~$Hello, world!$
25 = ~$Hello, world!$
26
2427 | &~$Shoes are $&&~~&~$4.99 a pair$&&
25 = Str "Shoes are $4.99 a pair"
28 = ~"Shoes are $4.99 a pair"
2629
2730 List expressions.
2831 -----------------
2932
3033 | [1,2,3]
31 = Cons (Int 1) (Cons (Int 2) (Cons (Int 3) Null))
34 = [1,2,3]
3235
3336 | [1,2|3]
34 = Cons (Int 1) (Cons (Int 2) (Int 3))
37 = [1,2|3]
3538
3639 | <[1,2|3]<abort<
37 = Int 1
40 = 1
3841
3942 | <1<abort<
40 = Abort
43 = abort
4144
4245 | >[1,2|3]>abort>
43 = Cons (Int 2) (Int 3)
46 = [2|3]
4447
4548 | >1>null>
46 = Null
49 = null
4750
4851 | <,1,2,<null<
49 = Int 1
52 = 1
5053
5154 | >,1,2,>null>
52 = Int 2
55 = 2
5356
5457 | ,1,,2,3,,
55 = Cons (Int 1) (Cons (Int 2) (Int 3))
58 = [1,2|3]
5659
5760 | ;[1,2];[3];
58 = Cons (Int 1) (Cons (Int 2) (Cons (Int 3) Null))
61 = [1,2,3]
5962
6063 | ;[1,2];3;
61 = Cons (Int 1) (Cons (Int 2) (Int 3))
64 = [1,2|3]
6265
6366 | ;null;null;
64 = Null
67 = null
6568
6669 | ;[1];null;
67 = Cons (Int 1) Null
70 = [1]
6871
6972 | ;null;[1];
70 = Cons (Int 1) Null
73 = [1]
7174
7275 Labels and gotos.
7376 -----------------
7477
7578 | :A:goto$A$
76 = Label "A" (Goto "A")
79 = :A:goto $A$
7780
7881 Foreach expressions.
7982 --------------------
8083
8184 | foreach $n$=[7,2,3] with $a$=0 be +$a$+$n$+ else be abort
82 = Int 12
85 = 12
8386
8487 | foreach $n$=null with $a$=0 be +$a$+$n$+ else be abort
85 = Abort
88 = abort
8689
8790 | foreach $n$=[1,2,3] with $a$=null be ,$n$,$a$, else be null
88 = Cons (Int 3) (Cons (Int 2) (Cons (Int 1) Null))
91 = [3,2,1]
8992
9093 This is how boolean expressions can be built with `foreach`es.
9194 We take `null` to mean **false** and `[1]` to mean **true**.
9396 Boolean NOT.
9497
9598 | foreach $n$=null with $a$=null be null else be [1]
96 = Cons (Int 1) Null
99 = [1]
97100
98101 | foreach $n$=[1] with $a$=null be null else be [1]
99 = Null
102 = null
100103
101104 Boolean OR.
102105
103106 | foreach $n$=;[1];[1]; with $a$=[1] be $a$ else be null
104 = Cons (Int 1) Null
107 = [1]
105108
106109 | foreach $n$=;null;[1]; with $a$=[1] be $a$ else be null
107 = Cons (Int 1) Null
110 = [1]
108111
109112 | foreach $n$=;[1];null; with $a$=[1] be $a$ else be null
110 = Cons (Int 1) Null
113 = [1]
111114
112115 | foreach $n$=;null;null; with $a$=[1] be $a$ else be null
113 = Null
116 = null
114117
115118 Boolean AND.
116119
118121 | foreach $m$=$a$ with $b$=null be [1]
119122 | else be null
120123 | else be null
121 = Cons (Int 1) Null
124 = [1]
122125
123126 | foreach $n$=null with $a$=[1] be
124127 | foreach $m$=$a$ with $b$=null be [1]
125128 | else be null
126129 | else be null
127 = Null
130 = null
128131
129132 | foreach $n$=[1] with $a$=null be
130133 | foreach $m$=$a$ with $b$=null be [1]
131134 | else be null
132135 | else be null
133 = Null
136 = null
134137
135138 | foreach $n$=null with $a$=null be
136139 | foreach $m$=$a$ with $b$=null be [1]
137140 | else be null
138141 | else be null
139 = Null
142 = null
140143
141144 Some list-processing-type things that you often see in functional
142145 programming.
148151 | ,$x$,$a$,
149152 | else be
150153 | null
151 = Cons (Int 80) (Cons (Int 40) (Cons (Int 20) (Cons (Int 10) Null)))
154 = [80,40,20,10]
152155
153156 Find the length and the sum of a list of integers.
154157
157160 | ,+<$a$<0<+1+,+>$a$>0>+$x$+,
158161 | else be
159162 | null
160 = Cons (Int 3) (Int 70)
163 = [3|70]
161164
162165 Take the first 3 elements from a list (in reverse order.)
163166
170173 | abort
171174 | else be
172175 | null
173 = Cons (Cons (Int 40) (Cons (Int 20) (Cons (Int 10) Null))) (Cons (Int 1) Null)
176 = [[40,20,10],1]
174177
175178 Take the first 5 elements from a cyclic list.
176179
183186 | abort
184187 | else be
185188 | null
186 = Cons (Cons (Int 10) (Cons (Int 20) (Cons (Int 10) (Cons (Int 20) (Cons (Int 10) Null))))) (Cons (Int 1) Null)
189 = [[10,20,10,20,10],1]
187190
188191 Macros.
189192 -------
190193
191194 | {*[Five][5]}{Five}
192 = Int 5
195 = 5
193196
194197 | {*[(A][1]}+{(A}+4+
195 = Int 5
198 = 5
196199
197200 | {*[SQR][*{X}*{X}*]}{*[X][5]}{SQR}
198 = Int 25
201 = 25
199202
200203 | {*[}][This is my comment!]}~${}}$
201 = Str "This is my comment!"
204 = ~$This is my comment!$
202205
203206 | {*[Dave][3]}{*[Emily][4]}$Number of Macros Defined$
204 = Int 2
207 = 2
205208
206209 | &~${$&~$*[S][T]}$&
207 = Str "{*[S][T]}"
210 = ~${*[S][T]}$
208211
209212 | &~${$&~$S}$&
210 = Str "{S}"
213 = ~${S}$
211214
212215 | %&~${$&~$*[S][T]}$&%&~${$&~$S}$&%
213 = Str "T"
216 = ~$T$