1 Thanks to: https://github.com/matslina/awib
2 # This is the awib frontend
3 # Please refer to the documentation in the full source distribution
4 # of awib for details regarding this file
6 ## Target identification
8 % *T (where T = index of target platform)
9 # read bytes until EOF or bf instruction or '@' is reached
11 % T 0 0 0 1 *inc(X) 0 0 0 (where X is byte read)
13 % T 0 0 0 1 inc(X) *inc(X) 1 0
14 [-[>+++++[-<------->]+<-[-[-[-[--------------[--[-->>+<<[>>-<++
15 [-<--------->]+<[--[>+++++++++[-<++++++++++>]<[-]]]]]]]]]]]<->]
18 % if( X=='@' ) d=1 else if(EOF) X=0 else X = a bf instruction
19 # if '@' was encountered then read a string at most 20 bytes long
20 # whitespace and EOF and bf all terminate the string when read
21 >>>>[->++++++++++++++++++++<<<<[-]>>>+[
22 % T 0 0 0 0 (target) 0 0 0 *1 C (where C = sub(20 strlen(target)))
24 % T 0 0 0 0 (target) X *X 1 0 C
25 [-[---------[-[---[>++++[-<---->]+<+[-----------[-[-[-[--------------
26 [--[>++[-<--------->]+<--[--[>+++++++++[-<++++++++++>]<[-]]]]]]]]]]]]]]]
28 % T 0 0 0 0 (target) X c *0 0 C (where c=(X EOF or bf or whitespace ? 0 : 1))
30 <<<[->>>+>->+<[>-]>[>]<[-<<->>]<<<<<]>>>
31 % T 0 0 0 0 (target) X 0 0 0 *c D
32 % where c=(string terminated ? 0 : 1) and D=(c==1 ? sub(C 1) : C)
34 # if string was ended due to strlen exceeding limit then read one char extra
35 +>[<-]<[<]>[-<<<,>>>>]
36 % T 0 0 0 0 (target) X 0 0 0 *0 D
37 # now check if the read target string matches any known target string
38 # and overwrite the target index T accordingly
39 # we take care not to overwrite the last read X as it may be bf and should
40 # be passed on to the bytecode compiler below
41 <<<<+[->+<]>[-<<[<]<<<+>>>>[>]>]++++++++++++++++++++>>>>[-<<<<->>>>]<<<++++++++
43 % T X 0 0 0 (target) 0 s *8 0 0 (where s = strlen(target))
44 [[->+>+<<]>[-<+>]+>-[-[-[-[-[-[-[-[<->[-]]
46 # build target string for backend index 8
47 % T X 0 0 0 (target) 0 s 8 *0 0
48 >+++++++++[->+>++++++++++++<<]>>[->+>+>+>+>+>+>+>+>+<<<<<<<<<]
49 >>----------->++>----->------------->-->----------->++++++++++>-----------
51 % T X 0 0 0 (target) 0 s 8 *0 0 9 0 "lang_java" 0
54 # build target string for backend index 7
55 % T X 0 0 0 (target) 0 s 7 *0 0
56 >+++++++++[->+>++++++++++++<<]>->[->+>+>+>+>+>+>+>+<<<<<<<<]>>----------->++
57 >----->------------->++++++++>---------
59 % T X 0 0 0 (target) 0 s 7 *0 0 8 0 "lang_tcl" 0
62 # build target string for backend index 6
63 % T X 0 0 0 (target) 0 s 6 *0 0
64 >+++++++++[->+>++++++++++++<<]>>[->+>+>+>+>+>+>+>+>+<<<<<<<<<]>>----------->++
65 >----->------------->++++++>+++++++++>---------->+++++++++++++
67 % T X 0 0 0 (target) 0 s 6 *0 0 9 0 "lang_ruby" 0
70 # build target string for backend index 5
71 % T X 0 0 0 (target) 0 s 5 *0 0
72 >+++++++++++[->+>++++++++++<<]>>[->+>+>+>+>+>+>+>+>+>+>+<<<<<<<<<<<]
73 >-->------------->>------->--------------->++>+++++++++++>++++++>------>+
75 % T X 0 0 0 (target) 0 s 5 *0 0 11 0 "lang_python" 0
78 # build target string for backend index 4
79 % T X 0 0 0 (target) 0 s 4 *0 0
80 >>+++++++[->+++++++<]+++++++>
81 [->++>++>++>++>++>++>++<<<<<<<]>
82 ++++++++++>->++++++++++++>+++++>--->+++++>+++++++++++++
84 % T X 0 0 0 (target) 0 s 4 *0 0 7 0 "lang_go" 0
87 # build target string for backend index 3
88 % T X 0 0 0 (target) 0 s 3 *0 0
89 >>+++++++[->+++++++<]++++++++++>
90 [->++>++>++>++>++>++>++>++>++>++<<<<<<<<<<]>
91 ++++++++++>->++++++++++++>+++++>--->++>+++++++++++++++++++>+++++++++++>
92 +++++++++++>+++++++++++++++++++++++<<<<<<<<<<<<<
93 % T X 0 0 0 (target) 0 s 3 *0 0 10 0 "lang_dummy" 0
96 # build target string for backend index 2
97 % T X 0 0 0 (target) 0 s 2 *0 0
98 >>+++++++[->+++++++<]++++++>[->++>++>++>++>++>++<<<<<<]
99 >++++++++++>->++++++++++++>+++++>--->+<<<<<<<<<
100 % T X 0 0 0 (target) 0 s 2 *0 0 6 0 "lang_c" 0
103 # build target string for backend index 1
104 % T X 0 0 0 (target) 0 s 1 *0 0
105 >>+++++++[->+++++++<]+++++++++>[->+>+>+>++>++>++>++>++>++<<<<<<<<<]
106 >++>+++++++>+++++>--->++++++++++>+++++++>++++++++++++>+++
107 ++++++++++++++++>++++++++++++++++++++++<<<<<<<<<<<<
108 % T X 0 0 0 (target) 0 s 1 *0 0 9 0 "386_linux" 0
110 % T X 0 0 0 (target) 0 s i *0 0 S 0 (string) 0
111 % where S = strlen(string) and i is the backend index of the target (string)
112 # if (target) equals (string) then set T=i and break else decrease s and retry
113 <<[->>+>>-<<<<]>>[-<<+>>]>+>[<++++[->++++<]>[-]]<
114 % T X 0 0 0 (target) 0 s i 0 *e 0 0 (string) 0 (where e=(S==s ? 1 : 0))
117 % T X 0 0 0 *(target) 0 s i 1 0 0 0 (string) 0
119 % T X 0 (target) 0 0 *(F target) 0 s i c 0 (1sled) 0 0 (G string) 0
120 % where c = (strings equal so far ? 1 : 0 ) and (1sled) is a (initially empty)
121 % sequence of cells holding 1 and F/G first cells of respective block
122 [-<+<+>>]<[>>[>]>>>>>[>]>+>[<-]<[<]>[-<<[<]<[-]<<<<[<]<[-]+>>[>]>>>>>[>]>>+<]>-<<<[<]<<<<<[<]<-]
123 % T X 0 (target F) *0 0 (target) 0 s i c 0 (1sled) 0 0 sub(G F) (string) 0
124 >>[>]>>>>>[>]>>[[-]<<<[<]<[-]>>[>]>>]<<+[<]<<<<<[<]>
125 % T X 0 (target F) 0 0 *(target) 0 s i c 0 (1sled) 1 0 0 (string)
127 % T X 0 (target) 0 0 *0 s i c 0 (1sled) 0
128 <<<[[->>+<<]<]>>>[>]>>>>>[>]<[-<]<
129 % T X 0 0 0 (target) 0 s i *c 0
130 # if c==1 then we have a match and write T=i and set i=1
131 [-<<<<[<]<<<<[-]>>>>>[>]>>[-<<<[<]<<<<+>>>>>[>]>>]+>]>
132 % T X 0 0 0 (target) 0 s i 0 *0
134 # remove (string) if string lengths didn't match and then sub 1 from i
137 % T X 0 0 0 (target) 0 s *0 0 0
138 <[-]<<[[-]<]<<<+[->>>>+<<<<]>>>>->>>
142 <<<+[->>>>>>>+<<<<<<<]>>>>>>>-
145 ## Bytecode compilation
147 % T 11(0) *X (where X is user input)
148 # if read char X is not EOF then enter main loop
149 +[[-<+>]>+<]>[-<<->>]<<
151 % T 8(0) (code) 0 0 *X (cells left of code ignored for a while hereafter)
152 # check if X is brainfuck
153 [->+>+<<]>[-<+>]++++++[->-------<]+>-
154 [-[-[-[--------------[--[<+++[->-----
155 --<]+>-[--[<->>+++++++[-<++++++++++++
157 % (code) 0 0 *X isbf(X) 0 0
158 # if bf then add to bytecode
161 % (code) 0 0 *sub(X 42) 1 0 0
162 [-[-[-[-[--------------[--[-----------------------------[
164 # if this closes OPEN SUB(1) or OPEN ADD(1) then overwrite with SET(0)
167 +<<<<-------[>>>>-]>>>>[>>>>]<<<<<<<<+++++++>>>>
168 % (code) P i Q j *c 0 0 1 0 (where c = (P(i) == OPEN(0)))
169 [<<---[>>-]>>[>>]<<[->>>>+<<<<]+
170 << ++[>>-]>>[>>]<<[->>>>+<<<<]<<+>>>>>>
171 % (code) OPEN 0 Q j 0 0 0 1 *d (where d = (Q == ADD or Q == SUB))
172 [-<<<<+<-[>-]>[>]<<+>
173 % (code) OPEN 0 Q j *e 0 0 1 0 (where e = (j == 1) == overwrite SET(0))
174 [->>>-<<<<-<[-]<<++>>]>>>>]<<<<]>
175 % (code) 0 *0 0 f 0 (where f = 1 if append CLOSE)
176 >>[-<<<++++++++>>>>>]<<
177 % (code) CLOSE()/SET(0) 0 *0 0 0
180 # if previous op was SET(0) or CLOSE or if this is the first op
181 # then ignore this loop
183 % (code) 0 0 0 *0 0 0
185 [>>>>>-<<<<<[->>>+<<<]]>>>
186 --------[++++++++[-<+>]<-------->>>-<<]<
187 -[+++++++++[-<<+>>]<<--------->>>>>-<<<]<<+++++++++>>
188 +<[>-]>[>]<[->>>[-<+>]<<<]>>>[-]<<<+++++++>>
189 % (code) OPEN *c 0 0 0 (where c = (should this loop be ignored ? 1 : 0))
191 % (code) OPEN *1 0 0 0 L l
192 >>+<,[>-]>[>]<[-<<->>]+<+[>-]>[>]<[-<<->>]<-
193 % (code) OPEN c *X 0 0 L l (where c = (EOF reached ? 0 : 1) and X = byte read)
194 >+++++++++[-<---------->]+<-[>-]>[>]<[->>
195 { 16b inc >>>++++++++[-<++++++++>]<[->++++<]<
196 [->+>-<<]>+[-<+>]+>-[<->[-]]<[-<[-]<+>>]<< }
198 { 16b dec >>+<[>-<[->>+<<]]>>[-<<+>>]<<->[-<+
199 <->++++++++[->++++++++<]>[-<++++>]<->]<< }
200 <<]+++++++++[-<++++++++++>]<++++[-]
202 { 16b iszero >>+<[>-]>[>]<<<[[->>>+<<<]>>[-]<<]>>>[-<<<+>>>]<<< }
203 # if Ll=0 then delete OPEN and set c=0 to break
204 >>[-<<<<<<[-]<<------->>>>>>]<<<<<<
206 % (code) *0 0 0 0 L l (where Ll is nonzero iff EOF occurred prematurely)
211 # if previous op is RIGHT(i) and i is not 255 then overwrite with RIGHT(inc(i))
212 # else append RIGHT(1)
214 -<<<<<[->>+>+<<<]>>[-<<+>>]<[->+>>+<<<]>[-<+>]
215 % (code) *0 P i 0 (where P(i) = previous op)
216 ++++++++++++++++[->>----------------<<]>>+
217 [<<++++++++++++++++[->>++++++++++++++++<<]+>>[-]]<------[<[-]>++++++[-]]
218 <[->>+<<]++++++>+>[-<-<------<+>]>>
220 % (code) RIGHT(?) 0 *0 0 0
223 # if previous op is LEFT(i) and i is not 255 then overwrite with LEFT(inc(i))
224 # else append LEFT(1)
226 -<<<<<[->>+>+<<<]>>[-<<+>>]<[->+>>+<<<]>[-<+>]
227 % (code) *0 P i 0 (where P(i) = previous op)
228 ++++++++++++++++[->>----------------<<]>>+
229 [<<++++++++++++++++[->>++++++++++++++++<<]+>>[-]]<-----[<[-]>+++++[-]]
230 <[->>+<<]+++++>+>[-<-<-----<+>]>>
232 % (code) LEFT(?) 0 *0 0 0
238 % (code) OUTPUT 0 *0 0 0
241 #if previous op is SUB(i)
242 # if i is 255 then remove previous op
243 # else overwrite with SUB(inc(i))
246 -<<<<<[->>+>+<<<]>>[-<<+>>]<[->+>>+<<<]>[-<+>]
247 % (code) *0 P i 0 (where P(i) = previous op)
248 >---[<+++>+++[-]+>[-]>]>
249 [<++++++++++++++++[->----------------<]>+>+<
250 [<<<+>>++++++++++++++++[->++++++++++++++++<]>[-]>-<]
253 % (code) SET/SUB(?) 0 *0 0 0
259 % (code) INPUT 0 *0 0 0
262 #if previous op is ADD(i)
263 # if i is 255 then remove previous op
264 # else overwrite with ADD(inc(i))
267 -<<<<<[->>+>+<<<]>>[-<<+>>]<[->+>>+<<<]>[-<+>]
268 % (code) *0 P i 0 (where P(i) = previous op)
270 [<++++++++++++++++[->----------------<]>+>+<
271 [<<<+>>++++++++++++++++[->++++++++++++++++<]>[-]>-<]
274 % (code) ADD(?) 0 *0 0 0
277 % (code P i Q j) 0 *0 (where P(i) and Q(j) are the two most recent ops)
278 # if P/Q in (LEFT/RIGHT RIGHT/LEFT ADD/SUB SUB/ADD) and j == 1
279 # remove Q(j) and decrement i
280 # if dec(i) == 0 then remove P(i)
281 >>+<<<+<-[>-]>[>]<<+>[
284 <<<[>>-]>>[>>]<<[->-<]+>[-
287 % add(P Q) i *0 Q 0 0 0 1
288 +<<----[>>-]>>[>>]<<[->>>+<<<]+<<-------[>>-]>>[>>]<<[->>>+<<<]
289 >[-<+<<->>>]+<<<+++++++++++>>>>>
290 % P i Q 1 0 *c 0 1 (where c = add(P Q) in (add(LEFT RIGHT) add(ADD SUB)))
291 [->>-<<<<-<[-]+<-[>-]>[>]<[-<<[-]]>]<]]>>>
292 % (code) 0 0 0 *z (where z = 1 if we should attempt further optimizations)
293 #if P in (ADD SUB) and Q == SET then remove P
294 [>+<-<<<+<<---------[>>-]>>[>>]<<[
297 -<<+<<-[>>-]>>[>>]<<[->>>+<<<]+<<--[>>-]>>[>>]<<[->>>+<<<]<<+++>>>>>
298 % P i 0 j 0 *c 0 0 0 (where c = P in (ADD SUB))
299 [-<<<<<[-]>[-]>>[-<<+>>]]<]<<+++++++++>>>>>]
300 % (code) 0 0 0 *0 z (where z = 1 if we should attempt further optimizations)
301 # if P == SET and Q(j) in (ADD(1) SUB(1)) then inc/dec i and remove Q(j)
303 <<<<+<<<<---------[>>>>-]>>>>[>>>>]<<<<<<<<+++++++++>>>>[
308 <<-[>>-]>>[>>]<<<<+>>[-
310 >>>-<<<<-<<<+++++++[->----------------<]>+[>-]>[>]+<[->-<]>
311 [-<++++++++++++++++[-<++++++++++++++++>]>]
313 +<<---[>>-]>>[>>]<<<<+++>>[-
316 <[>-]>[>]<[+++++++++++++++[-<++++++++++++++++>]]<->
318 % (code) 0 0 0 *z 0 (where z = 1 if we should attempt further optimizations)
319 # if P == CLOSE then try the copy loop optimization
321 -<<<+<<--------[>>-]>>[>>]<<<<++++++++>>[# P == CLOSE
322 ->>>>>>>++++++++<<++++++++[-<++++++++++++++++>]<-[-<+<+>>]
324 % (code) Q j *1 1 0 0 128 128 *0 0 0 P
325 <<[>>-]>>[>>]<<[->-<]>[-<+>]<
326 [ # determine if loop can be optimized
327 % (code) *k 0 0 0 l r a 0 0 (code)
328 % where k = 1 iff next op should be inspected
329 % l = sub(127 num_left)
330 % r = sub(127 num_right)
331 % a = 1 iff SUB(1) on cell 0 processed
332 <<-[>>-]>>[>>]<<[# P == ADD
333 >>>>[->->>+<<<]+>[<-]<[<]>[ # l == r: kill l ->>>[-<<+>>]<<<]
334 >>>[-<<+<+>>>]<<<<<<+<-]+
335 <<--[>>-]>>[>>]<<[# P == SUB
336 >>>>[->->>+<<<]+>[<-]<[<]>[ # l == r
337 >>[<<-]<<[<<]>+>[-<<<<<-[>-]>[>]<<+>[->>>->>>+<<<<<<]+>>>>]
338 <[->>>>[-<<+>>]<<<<]>]
339 >>>[-<<+<+>>>]<<<<<<+<-]+
340 <<--[>>-]>>[>>]<<[# P == LEFT
341 -<[->+>>>+>-[<-]<[<]>[-<<<<[->+<]>>>>]<<<<]>[-<+>]>+<]+
342 <<-[>>-]>>[>>]<<[ # P == RIGHT
343 -<[->+>>>+>>-[<<-]<<[<<]>>[-<<<<[->+<]>>>>]<<<<]>[-<+>]>+<]
344 % (code) sub(P 6) i *0 q 0 0 l r a 0 0 (code) 0
345 % where q = P in (ADD SUB LEFT RIGHT)
346 # keep going if q==1 && l!=0 && r!=0 && next op exists
347 <[->>>>>>>>>+<<<<<<<<<]<++++++[->>>>>>>>>+<<<<<<<<<]
348 +<<[>>->>>+<<<]>>[>>]<<[-]>>>>>>
349 [[-<<+>>]>[[-<<+>>]<<<<+>>>>]<]>[-<<+>>]>[-<<+>>]<<<<<
350 ---[<<<->>>+++[-]]<<<+
351 % (code) *k 0 0 0 l r a 0 0 P i (code)
353 >>>>>>>>+>-------[<-]<[<]>>+++++++
354 <<<[->>+<<]+<<[-<+>>-<]>[>-]>[>]<[->>+<<]>+>---[<-]<[<]>>+++[-]
355 <<<<<[->>+<<]>>[-]>+>
356 % (code) 0 0 0 0 0 0 1 *w 0 (loop)
357 % where w = 1 iff copy loop optimization can be applied
358 [<->->>[-]>[-]<<<<<<<<<+>+>+>+>+>>>>>>
359 [ # replace loop with LMUL/RMUL
360 % (code) 0 1 ::: 1 0 0 n d 0 *P i (loop)
361 % where d = offset to current cell
362 % n = 1 iff offset is negative
363 <+>-[--[--[-[++++++[-]<->]<[ # RIGHT(i)
364 ->>[<<+<[>-]>[>]<[-<<[-]>>]<+>>>-]<<
366 ->>[<<+<[>-]>[>]<[-<<[-]+>>]<->>>-]<<
368 % (code) 0 1 ::: 1 0 0 n d *1 0 i (loop)
369 <[>-]>[>]+<[->-<]>[ # d != 0
370 +++++++++++++++[-<<<<++++++++++++++++>>>>]>[-<<<<<->>>>>]<]<
371 % (code) 0 1 ::: 1 0 sub(256 i) n d *0 0 0 (loop)
373 % (code) 0 1 ::: 1 0 0 n d *1 0 i (loop)
374 <[>-]>[>]+<[->-<]>[ # d != 0
376 % (code) 0 1 ::: 1 0 i n d *0 0 0 (loop)
378 % (code) 0 1 ::: 1 0 y n d *0 0 i (loop)
379 % where y!=0 iff MUL op should be appended to code
380 % and y is the second op argument
382 <+>>[ # n=1 so d negative
383 <<-<[<]++++++++++>->++++++++++>->->[>]
384 >>>[+<<<<[<]<<<+>>>>[>]>>>>>-<<]>+<<-]
385 <<[ # n=0 so d positive
386 -<[<]++++++++++++>->++++++++++++>->->[>]
387 >>>[->>+<<<<<<[<]<<<+>>>>[>]>>>]
390 % (code) LMUL/RMUL y 0 1 ::: 1 0 *0 0 0 n d 0? (loop)
392 % (code) 0 1 ::: 1 0 *0 n d 0 0 i (loop)
393 >[>[+>>-<<]>+<<-]>[->>+<<]
395 % (code) 0 1 ::: 1 0 0 n d 0 *(loop)
397 % (code) 0 1 ::: 1 0 0 n 0 0 *0
398 <<<[-]<<<[-<]+++++++++>>>>>>>>>
399 % (code) SET(0) 0 0 0 0 0 0 0 *0
401 % (code) 0 0 0 0 0 0 v *0 0 (loop)
402 % where v = 1 iff copy loop optimization was not applied
403 <[->>>[[-<<<<<<<<<+>>>>>>>>>]>[-<<<<<<<<<+>>>>>>>>>]>]
409 % 8(0) (code) 0 0 X *0 (where X may be the last byte read)
410 # read next byte and and break if EOF
412 ,+[[-<+>]>+<]>[-<<->>]<<
419 # move code leftwards and ensure that all OPEN/CLOSE are balanced
420 # in the process we calculate the maximum loop (ie OPEN/CLOSE) depth
423 % 0 0 (code) M m D d 0 0 *P p (code) 0 c
424 % where Pp is first op of right code block
425 % Dd holds current loop depth (starting at 1)
426 % Mm holds the max loop depth yet encountered
427 % c = (unbalanced code ? 1 : 0)
428 <<<[->>+<<]<[->>+<<]<[->>+<<]<[->>+<<]>>>>>>>[-<<<<<<+>>>>>>]<
429 [->+<<<<<<<+>>>>>>]+>
430 % 0 0 (code) P p M m D d 1 *P (code) 0 c
431 -------[-[<->++++++++[-]]
433 # P is CLOSE; decrease Dd and leave Mm as it was
434 { 16b dec >>+<[>-<[->>+<<]]>>[-<<+>>]<<->[-<+<->++++++
435 ++[->++++++++<]>[-<++++>]<->]<< }
438 # P is OPEN; if Mm==Dd then Mm=Dd=inc(Dd) else Dd=inc(Dd)
439 % (code) P p M m D d *1 0 (code) 0 c (note: p=0 since P=OPEN)
440 <<[-<<->>>>>+<<<]<<[[->>+<<]>>>>-<<<<]
441 % (code) P p *0 m sub(M D) d e D (code) 0 c (where e=(M==D ? 1 : 0))
442 >>>[-<<-<+>>>]<<[[->>+<<]>>>[-]<<<]
443 % (code) P p d *0 sub(M D) sub(m d) e D (code) 0 c (where e=(Mm==Dd ? 1 : 0))
444 >>[-<<+>>]<<<[->+>>+<<<]>>[-<<+>>]>>>[-<<<+<<+>>>>>]<[-<<<<<+>>>>>]<<
445 % (code) P e M m *D d 0 0 (code) 0 c (where e = (Mm==Dd ? 1 : 0))
446 { 16b inc >>>++++++++[-<++++++++>]<[->++++<]<[->+>-<<]
447 >+[-<+>]+>-[<->[-]]<[-<[-]<+>>]<< }
448 <<<[->[-]>[-]>[-<+<+>>]<[->+<]>>[->+<<<+>>]>[-<+>]<<<<<]>>>>>
450 % 0 0 (code P p) M m D d *0 0 (code) 0 c (where Dd is properly updated)
451 << { 16b iszero [[->>+<<]>>>+<<<]>>[-<<+>>]<[[->+<]>>+<<]>[-<+>]+>[<->[-]]<<< }
452 >>[-<+>>>[>>]>[-]+<<<[<<]]>>
453 % 0 0 (code P p) M m D d 0 0 *(code) 0 c (where c is properly updated)
455 % 0 0 (code) M m D d 0 0 *0 c
457 { 16b dec >>+<[>-<[->>+<<]]>>[-<<+>>]<<->[-<+<->++++++
458 ++[->++++++++<]>[-<++++>]<->]<< }
459 { 16b isnonzero >[>>+<]>[<]<<[[->>+<<]>>>+<<<]>>[-<<+>>]>[[-]<+>]<<< }
460 >>[->>>[-]+<<<]<[-]<[-]<[->+<]<[->+<]>>>>>>>[-<<<<+>>>>]<<<<
462 % 0 1 (code) 0 M m *c 0 0 0
463 # if c==1 output string "Error: unbalanced brackets!\n"
464 [-<[-]<[-]<<<[<<]>->[>>]
465 +++++++++++[->++++++>++++++++++>+++<<<]>
466 % (code) 0 *66 110 33
467 +++.>++++..---.+++.<-----------.>>-.<+++.-------.
468 ------------.-.+++++++++++.-----------.+++++++++++++.
469 -----------.++.-.>.<--.++++++++++++++++.-----------------.
470 ++.++++++++.------.+++++++++++++++.-.>+.---[--->+<]>.[-]<<[-]<[-]>>>]
472 % T *0 b (code) 0 M m
473 % where b = (bytecode OK ? 1 : 0) and Mm = maximum loop depth
475 # This is the Java language backend for awib
476 # Please refer to the documentation in the full source code distribution
477 # of awib for additional details
478 % 23(0) *8 (code) 0 M m
480 ++[-<++++++++<++++++++<++++++++++<++++++++++<+++<++++++++++<++++++++++<+
481 +++++++++<+++<++++++<++<+++++++++++>>>>>>>>>>>>]<<<+++++.++++.+++.-.+++.
482 ++.<<++.>++++++.<<---.>>>++.<<<.>++++++++++++++.>-.++++++.<.>>>-------.<
483 <-.++.>-.-.>>+++.<<.--.<<<<+.>.>>---.<<<<<<-.<----------.<-----.++++.+++
484 .-.+++.++.>>>++.>>+++++.>.>>>++++.<<<.>.<<-.>>>++.<.>>>>----.<<-.-.<+.>+
485 .-.>>++++.<<.--.<<<<<+.>>.>>---.<<<<<<.<.>>>>.>>>.>--.-.+++.++.<<<<<<.>>
486 +.>.>>>++.<<<.>.<<-.>>>++.<.>>>.>----.<----.<++.<<<++.++.>>+.++++.<<<.++
487 ++++.-.<<<.<..<----.+++++.>>>>---.>--.---.<+.<.>.>+++.<--.>>>>-..<<<<<.<
488 +++++++.>>>>+.<<<.>>>>>>+++.<<<<<<<<.>>....>+.>>>>>--.<+.<<-.<<-------.+
489 +.<.>>+.<<<-------.<.>>....>>----.+++++.>>>.<<<<<.>>++.<<<.<.>>....>>>>>
490 >>++++.<<<<<--.++.>>>+.-.>>>++++.<<<.--.<<.----.<---.<<.>>----.<<<.<.>>.
491 ...>>>>>>>>----.<<----.-.<--.>+.-.>>++++.<<.--.<<<++++.----.>>---.<<<<<.
492 >>>>>++.<<<<<<.<..>>....>>>>>+.>+++.<<<+.<+++.---.>+.<<<.<+++++++.>>>---
493 .>>------.>>>.<<--.++.>.-.>>.<<.--.<<<++.----.>>---.<<<<<.>>+++.>>++++.<
494 <<<.>>>>>>>>----.<<+++.-.----.+++++.-.>>++++.<<.--.<<<++++.----.>>.<<<<<
495 .>>>>>++.<---.<<<<.<<<++++++.>.>>........>>++++.<<<-----.>>>+.>++++.>>>+
496 ++++.<<<<<<.>>>---.>>>++.-----.<<<+++.<<--.>>>+++++++.>>++++.<<+.-.+.-..
497 <<<++.<<--.<.>>........>>++.<<<++.>>>>>+.+.+++++.++++.<<<<<<.>>........>
498 >++++.>+++.+.<-.>>-------------.<.<<<<.>>>>.<<<<--.<.>>........>>+.>-.+.
499 <-.>>.>.<<<<<<++.>>>>>>.<<<<<<--.<.>>....<<<++.>..>>....>>---.+++++.<+++
500 ++.>>+++.---.<<+.<.>>+.>>>.<<.<<+.<.>>----.+++.>>>-.<<<<<.++++++++.+.---
501 ------.<<<--.>.>>........>>-.>-.+.<-.>>.<<<-----.>>>++.--------.+.<<<<<.
502 <.>>....<<<++.>..>>....>>---.+++++.<+++.>>+++.---.<<+.<.>>--.+.<--.>.>.<
503 <++.<.>>++.>>>+.<<.<<+.<.>>>>>--.<<<<---.>>.>>+.<-.>>>>.<<----.--.<<<.>>
504 .<<--.<<------.++.<.>++++.>>>>>.<<<.>>>+.<<+.<<<<.<<<--.>.>>........>>>>
505 >.<<--.<+.<<.<+++++++.>>>>+.>-.>>>>.<<++++++.------.+.<<<-.>>-.<++++++.>
506 ----.+++++.<--.>>>>.<<+++++.------.+.<<<.>>-.<++.>++.>+.-.<<-----.+++++.
507 >>--.+++.<-.<------.+.<<<<<-------.<.>>....<<<++.>..>>....>>>>>++.++.<<+
508 +++.<-.<.>--.>----.<<<.>>++.>>>---.------.<<-.<<<.>>----.>>-.+.<<<<.<<<-
509 -.>.>>........>>++.--.+++++++.<<.<<<.>.>>............>>>>>.<+++++.>>---.
510 <<<+.<<.>>-.>------.>++++.<++++.>>--.<<.+++++.--------.<<<<<.<.>>.......
511 .<<<++.>>>.>++.--.>-----.>-.+++++.<<<.>>>>-.>>>.>----.<----.<++++++++.<<
512 <<<++.++.>----.++++.>+.>>++.-.<<<<<.>.>>>+.<<<<.<<<--.++.>.>>....<<<.>..
513 >>....>>----.++.>.>>>--.<<<<<----.>++.>----.<<<.>>++.>>>+.------.<<-.<<<
514 .>>+.>>-.+.<<<<.<<<--.>.>>........>>---.--.>>>>+++.<<<<<<.<<<.>.>>......
515 ......>>---.>>+++++.>>--.-----.<.>++.<<<+.>------.<<--.<------.>+++.<++.
516 >>>+.<<<<<.<.>>............>>-.>>+++++.<+.<---.>>>>+.--.<-.<------.+.<<<
517 <<.<.>>........<<<++.>>>.>>>---.--.>>>+.<<<++.>>.<<<<<.>>>>-.>>>++++.>.<
518 ----.<++++.<<<.++.<++++.++++.>>>+.++++++.-.<<<<<.>>>.>+.<<<<.<<<--.++.>.
519 >>....<<<.>..>>....>>----.++.>++++.>>>--.<<<<<++++.>++.>----.<<<.>>++.>>
520 >+.------.<<-.<<<.>--.>>>+++++++.--------.+.<<<<.<<<--.>.[<]>[[-]>]
521 % 23(0) *0 (code) 0 M m
522 ++++++++++++++++[-<++++++++++++++++>]<-[-<<<<<<<<<<<<<<<+<+>>>>>>>>>>>>>>>>]
523 <<<<<<<<<<<<<<<<<<+<+>>>>>>>>>>>>>>>>>>>>
524 % 4(0) 1 0 255 255 15(0) *0 (code) 0 M m
526 % ::: (stack) 0 1:::1 0 c d 15(0) 1 *P i (code) 0 M m
527 % (where c and d form a two cell counter
528 % P(i) is the next op code)
529 # the stack segment is a sequence of adjacent C and D; these values
530 # are previous values of the cd counter that have been pushed to stack
531 # on OPEN; they are in turn popped on CLOSE
532 -[-[-[-[-[-[-[-[-[-[-[-[[-]
535 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
536 +++++[->+++++++++++++++<]>+++.-[--<+>]<---.-[-->+++<]>--.------[-<++>]<-.-
537 -----------------.+[---->+++++<]>---.+++[-----<++++>]<+.-[-->+<]>----.[-]
539 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
543 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
544 ++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
545 --[----->++<]>-.[-]<<<+>>
546 % ::: (stack) 0 1:::1 0 c d 11(0) 0 0 1 0 *0 0 i (code) 0 M m
550 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
551 +++++[->+++++++++++++++<]>+++.-[--<+>]<---.-[-->+++<]>--.------[-<++>]<-.-
552 -----------------.+[---->+++++<]>---.+++[-----<++++>]<+.-[-->+<]>----.[-]
554 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
558 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
559 ++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
562 % ::: (stack) 0 1:::1 0 c d 11(0) 0 0 1 0 *0 0 i (code) 0 M m
566 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
567 ++++[->++++++<]>[-<++++<+++<+<++>>>>]<-----------.<+.>+++.<++.
568 <<+.>++++++++++.>+++++.>+++++++++.-----.<+++.<+.>>[[-]<]+>>+>>
569 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
573 % ::: (stack) 0 1:::1 0 c d 15(0) *0 0 0 (code) 0 M m
574 # output: ' }\n\n private void '
575 +++++++++++++++++++++++++[-<+<+++++<++++<++<+++>>>>>]<+++++++....<.
576 >>++++++++++..<....<-------------.++.<+++++.>++++.<--------.>--.<++++
577 .>>.<++.-------.<++++.-----.>>.>[[-]<]<<<<<<<<<<<<
578 % ::: (stack) 0 1:::1 *0 c d 15(0) 0 0 0 (code) 0 M m
579 # fetch xy from top of stack
580 <[<]<[->>[>]>>>>+<<<<<[<]<]<[->>>[>]>>>>>+<<<<<<[<]<<]>+>+[>]
581 % ::: (stack) 0 1:::1 *0 c d 0 y x 12(0) 0 0 0 (code) 0 M m
584 >++++++++[->++++++++++++<]>-.[-]
586 ++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
587 >++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
588 >++++++[-<++++++++>]<<[>[-<+<+>>]<.[-]<.[-]>]
589 <[>>[-<<+>>]<<.[-]]>>[-]<<++++++[-<++++++++>]<.[-]<
591 % ::: (stack) 0 1:::1 0 c d *0 14(0) 0 0 0 (code) 0 M m
593 +++++++++++++++++++++++++++++++++++++++++[->+++>+>++<<<]
594 >>-.+.---------.<.<++++++++++.[[-]>]>>>>>>>>>>>
595 % ::: (stack) 0 1:::1 0 c d 15(0) *0 0 0 (code) 0 M m
599 % ::: (stack) 0 1:::1 0 c d 15(0) *0 0 0 (code) 0 M m
601 <<<<<<<<<<<<<<<<[[->>+>>>>>>>>+<<<<<<<<<<]<]
602 >>>>>+<-[>-]>[>]<[+++++++++++++++[-<++++++++++++++++>]<-<->>]<
603 % ::: (stack) 0 1:::1 0 0 0 e *f 6(0) c d 5(0) *0 0 0 (code) 0 M m
604 # push a copy of ef to stack
606 [-<<<<[<]<<+>>>[>]>>>>>>>>>+<<<<<<]>
607 [-<<<<<[<]<+>>[>]>>>>>>>>>>+<<<<<<]>>>>>>>>
608 % ::: (stack ef) 0 1:::1 9(0) e f c *d 5(0) 0 0 0 (code) 0 M m
609 # construct decimal representations of e f c and d
611 % 0 (counters) *n 5(0) 0 0 0
612 % (where n is the rightmost counter)
614 % (counters) *n 5(0) 0 0 0
615 >>++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
616 >++++++++++<<[->>->+<[>-]>[>]<[-<++++++++++<+>>]<<<]++++++++++>>[-<<->>]
617 >++++++[-<++++++++>]<<[>[-<+<+>>]<:[->>>>+<<<<]<:[->>>>>>+<<<<<<]>]
618 <[>>[-<<+>>]<<[->>>>>>+<<<<<<]]>>[-]<<++++++[-<++++++++>]<[->>>>>>>>+<<<<<<<<]
619 % (counters) *0 5(0) n2 n1 n0
620 % (where n2n1n0 is n in base 10
621 % ni is 0 if not significant)
622 # move down remaining counters to make room for next base 10 rep
625 % ::: (stack) 0 1:::1 *0 8(0) e2 e1 e0 f2 f1 f0 c2 c1 c0 *d2 d1 d0 (code) 0 M m
626 # output: ' while(m{p}!=0){_'
627 # but with brackets instead of braces
628 ++++++++++++++++++++++++++++++[->++>+>++++>+++<<<<]>>++........>-.
629 ---------------.+.+++.-------.<++++++++.>++++++++.>+.<+++.>++.
630 <<-------.<+.-------------.-------.>>+++++++++++.>++.>
631 % 0 41 33 123 95 *0 0 0 0 e2 e1 e0 f2 f1 f0 c2 c1 c0 d2 d1 d0
633 # replace c and d with the corresponding decimal representation
635 >[.[-<<<<<<<<<+>>>>>>>>>]]>[.[-<<<<<<<<<+>>>>>>>>>]]>[.[-<<<<<<<<<+>>>>>>>>>]]
636 <<<<<<<<<<<<<.>>>>>>>>>>>>>
637 >[.[-<<<+>>>]]>[.[-<<<+>>>]]>[.[-<<<+>>>]]
638 <<<<<<<<<<<<<<<<<<<-.+.++++++++++++++++++.------------------>>++.
640 % 10 40 *32 125 95 0 c2 c1 c0 e2 e1 e0 f2 f1 f0 d2 d1 d0 0 0 0
641 # output: ' _e_f();\n }\n\n private void _c_d'
642 # again with e f c and d replaced by their base 10 reps
644 >[.[->>>>>>>>>+<<<<<<<<<]]
645 >[.[->>>>>>>>>+<<<<<<<<<]]
646 >[.[->>>>>>>>>+<<<<<<<<<]]
651 % 10 40 32 125 95 0 c2 c1 c0 f2 f1 f0 0 0 *0 d2 d1 d0 e2 e1 e0
653 <<<<.+.++++++++++++++++++.<.>>....>.<<<..>>....>-------------.++.---------.
654 +++++++++++++.>++.<--.>++++.<<.>++.-------.>++++.-----.<<.>>-----.<<<<
655 % *10 59 32 111 95 0 c2 c1 c0 f2 f1 f0 0 0 0 d2 d1 d0 e2 e1 e0
657 >[.[-]]>[.[-]]>[.[-]]
659 >[.[-]]>[.[-]]>[.[-]]
660 % 10 59 32 111 95 0 0 0 0 f2 f1 f0 0 0 0 0 0 *0 e2 e1 e0
662 >[[-<+>]++++++[-<-------->]]
663 >[[-<+>]++++++[-<-------->]]
664 >[[-<+>]++++++[-<-------->]]
666 <[->++++++++++[->++++++++++<]<]
668 <[[->+<]++++++[->--------<]]
669 <[[->+<]++++++[->--------<]]
670 <[[->+<]++++++[->--------<]]
671 >>[->++++++++++<]<[->++++++++++[->++++++++++<]<]
672 % 10 59 32 111 95 0 0 0 0 0 *0 0 f 0 0 0 0 0 0 e 0
674 # and move ef into position
675 <<<<<<<<++++++++.+.---------.>++++++++++++.<<<.
677 >>>>>>>[-<<<<<<<<<<+>>>>>>>>>>]
678 >>>>>>>[-<<<<<<<<<<<<<<<<<<+>>>>>>>>>>>>>>>>>>]
680 # leave behind gh = dec(dec(cd)) = dec(ef)
681 <<<<<<<<<<<<<<<<+<-[>-]>[>]<[+++++++++++++++[-<++++++++++++++++>]<-<->>]
683 % ::: (stack) 0 1:::1 0 g h 15(0) *0 0 0 (code) 0 M m
687 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
688 ++++++++.---[->+++++++++++++++++++<]>--.--[-----<++>]<-.-[-->+++<]>--.[-]<
690 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
694 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
695 ++++++++.---[->+++++++++++++++++++<]>--.--[-----<++>]<+.[--->++++<]>+.[-]<
697 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
701 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
702 ++++++++.---[->++++++++++++++++++++<]>-.+[---<+>]<.+.[-]
704 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 0 0 *0 0 i (code) 0 M m
708 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
709 ++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
710 +++[----->++++<]>+.-[--<+>]<-.[--->++++<]>+.[-]<
712 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
716 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
717 ++++++++.---[->+++++++++++++++++++<]>.[---<+>]<++.+.[-]
719 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 0 0 *0 0 i (code) 0 M m
723 % ::: (stack) 0 1:::1 0 c d 15(0) *1 0 i (code) 0 M m
724 ++++++++.---[->++++++++++++++++++<]>+.------------------.+[----<+++++>]<---.
725 +++[----->++++<]>+.-[--<+>]<---.-[-->+++<]>--.[-]<
727 % ::: (stack) 0 1:::1 0 c d 11(0) 1 0 1 0 *0 0 i (code) 0 M m
729 # optionally append ; and/or itoa(i)
730 % ::: (stack) 0 1:::1 0 c d 11(0) b 0 a 0 *0 0 i (code) 0 M m
731 % (where a==1 iff i should be output
732 % b==1 iff ';\n' should be output)
734 % ::: b 0 0 0 *0 0 i (code) 0 M m
736 ++++++++++>>[-<<-<+>[<-]<[<]>[->++++++++++>+<<]>>>]++++++++++<<[->>-<<]
737 <++++++++++>>[-<<-<+>[<-]<[<]>[->++++++++++>+<<]>>>]++++++++++<<[->>-<<]
738 <++++++[->++++++++<]>>[<[->+>+<<]>.[-]>.[-]<]
739 >[<<[->>+<<]>>.[-]]<<[-]>>++++++[->++++++++<]>.[-]
741 <<[+++++[->++++++++++<]>-.[-]++++++++++.[-]<]>>>>>>[-]
742 % ::: (stack) 0 1:::1 0 c d 15(0) 0 0 *0 (code) 0 M m
743 # copy up cd; extend the 1 sled; process next operation
744 <<<<<<<<<<<<<<<<<<[->>+<<]<[->>+<<]+<+>>>>>>>>>>>>>>>>>>>>
748 >[-]>[-]++++[->++++++++<]>....[->++++<]>---.>++++++++++.<.[-]>.[-]