git @ Cat's Eye Technologies Braktif / a3a3850
Initial import of Braktif version 1.0 revision 2007.0503 sources. catseye 8 years ago
5 changed file(s) with 515 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 000000000000000000 <*<*>*>*<*<*>*>*
1 -----------------d-i---------------
0 <*
1 000000000000000000000000000000000000000000000000000000000 *[---]
2 --------------------------------------------------------d-i- --
0 *
1 <<*[--]*
2 000000000000000000 *[----- --]
3 -----------------d-i-- --------
4
0 #!/usr/bin/perl
1 # eg/braktif/script/braktif.pl - automatically generated from eg/braktif/src/braktif.alp by:
2 # alpaca.pl v0.93
3 # http://catseye.webhop.net/projects/alpaca/
4 ######################################################
5
6 use Alpaca qw(true false guess
7 adjacent_state adjacent_class
8 load_playfield display_playfield process_playfield);
9
10 sub SpaceStateRules {
11 return 'SkipBack' if (($Playfield->[$x][$y-1] eq 'WakeMark' and $Playfield->[$x+1][$y-1] eq 'WendCmd') or ($Playfield->[$x+1][$y] eq 'SkipBack'));
12 return 'SkipStart' if ($Playfield->[$x-1][$y-1] eq 'SkipReply' and $Playfield->[$x][$y-1] eq 'InstrMark');
13 return 'SkipFore' if ($Playfield->[$x-1][$y+1] eq 'SkipStart' or $Playfield->[$x-1][$y] eq 'SkipFore');
14 return 'Space'
15 };
16
17 sub BusStateRules {
18 return $Playfield->[$x+1][$y] if (SignalClassMember($Playfield->[$x+1][$y]));
19 return $Playfield->[$x+1][$y-1] if (SignalClassMember($Playfield->[$x+1][$y-1]));
20 return $Playfield->[$x+1][$y+1] if (SignalClassMember($Playfield->[$x+1][$y+1]));
21 return $Playfield->[$x-1][$y] if (ReplyClassMember($Playfield->[$x-1][$y]));
22 return $Playfield->[$x-1][$y-1] if (ReplyClassMember($Playfield->[$x-1][$y-1]));
23 return $Playfield->[$x-1][$y+1] if (ReplyClassMember($Playfield->[$x-1][$y+1]));
24 return 'ContTool' if ($Playfield->[$x+1][$y] eq 'LeftTool' or $Playfield->[$x-1][$y] eq 'RightTool');
25 return 'ContReply' if ($Playfield->[$x-1][$y] eq 'ContTool');
26 return 'SkipReply' if ($Playfield->[$x-1][$y] eq 'SkipTool');
27 return 'LeftSig' if ($Playfield->[$x+1][$y] eq 'InstrPtr' and $Playfield->[$x+1][$y-1] eq 'LeftCmd');
28 return 'RightSig' if ($Playfield->[$x+1][$y] eq 'InstrPtr' and $Playfield->[$x+1][$y-1] eq 'RightCmd');
29 return 'FlipSig' if ($Playfield->[$x+1][$y] eq 'InstrPtr' and $Playfield->[$x+1][$y-1] eq 'FlipCmd');
30 return 'QuerySig' if ($Playfield->[$x+1][$y] eq 'InstrPtr' and $Playfield->[$x+1][$y-1] eq 'WhileCmd');
31 return 'InstrPtr' if ($Playfield->[$x-1][$y] eq 'WakeMark' or $Playfield->[$x-1][$y+1] eq 'WakeMark' or $Playfield->[$x-1][$y-1] eq 'Wakemark');
32 return 'InstrPtr' if ($Playfield->[$x-1][$y] eq 'InstrPtr' and $Playfield->[$x-1][$y-1] eq 'Space');
33 return 'InstrPtr' if ($Playfield->[$x+1][$y] eq 'SkipBack');
34 return 'SkipStop' if ($Playfield->[$x-1][$y] eq 'SkipFore');
35 return 'InstrPtr' if ($Playfield->[$x-1][$y] eq 'SkipStop');
36 return 'Bus'
37 };
38
39 sub SignalClassRules {
40 return 'Bus' if (1);
41 return 0
42 };
43
44 sub ReplyClassRules {
45 return 'Bus' if (1);
46 return 0
47 };
48
49 sub LeftSigStateRules {
50 return SignalClassRules() || 'LeftSig'
51 };
52
53 sub RightSigStateRules {
54 return SignalClassRules() || 'RightSig'
55 };
56
57 sub FlipSigStateRules {
58 return SignalClassRules() || 'FlipSig'
59 };
60
61 sub QuerySigStateRules {
62 return SignalClassRules() || 'QuerySig'
63 };
64
65 sub ContReplyStateRules {
66 return ReplyClassRules() || 'ContReply'
67 };
68
69 sub SkipReplyStateRules {
70 return ReplyClassRules() || 'SkipReply'
71 };
72
73 sub DataPtrStateRules {
74 return 'FlipTool' if ($Playfield->[$x+1][$y] eq 'FlipSig');
75 return 'LeftTool' if ($Playfield->[$x+1][$y] eq 'LeftSig');
76 return 'RightTool' if ($Playfield->[$x+1][$y] eq 'RightSig');
77 return 'SkipTool' if ($Playfield->[$x+1][$y] eq 'QuerySig' and $Playfield->[$x][$y-1] eq 'OffBit');
78 return 'ContTool' if ($Playfield->[$x+1][$y] eq 'QuerySig' and $Playfield->[$x][$y-1] eq 'OnBit');
79 return 'DataPtr'
80 };
81
82 sub FlipToolStateRules {
83 return 'ContTool' if (1);
84 return 'FlipTool'
85 };
86
87 sub LeftToolStateRules {
88 return 'Bus' if (1);
89 return 'LeftTool'
90 };
91
92 sub RightToolStateRules {
93 return 'Bus' if (1);
94 return 'RightTool'
95 };
96
97 sub ContToolStateRules {
98 return 'DataPtr' if (1);
99 return 'ContTool'
100 };
101
102 sub SkipToolStateRules {
103 return 'DataPtr' if (1);
104 return 'SkipTool'
105 };
106
107 sub OnBitStateRules {
108 return 'OffBit' if ($Playfield->[$x][$y+1] eq 'FlipTool');
109 return 'OnBit'
110 };
111
112 sub OffBitStateRules {
113 return 'OnBit' if ($Playfield->[$x][$y+1] eq 'FlipTool');
114 return 'OffBit'
115 };
116
117 sub InstrPtrStateRules {
118 return 'Bus' if ($Playfield->[$x][$y-1] eq 'Space');
119 return 'InstrMark' if (1);
120 return 'InstrPtr'
121 };
122
123 sub InstrMarkStateRules {
124 return 'WakeMark' if ($Playfield->[$x-1][$y] eq 'ContReply');
125 return 'Bus' if ($Playfield->[$x-1][$y] eq 'SkipReply');
126 return 'InstrMark'
127 };
128
129 sub WakeMarkStateRules {
130 return 'Bus' if (1);
131 return 'WakeMark'
132 };
133
134 sub SkipStartStateRules {
135 return 'Space' if (1);
136 return 'SkipStart'
137 };
138
139 sub SkipStopStateRules {
140 return 'Bus' if (1);
141 return 'SkipStop'
142 };
143
144 sub SkipForeStateRules {
145 return 'Space' if (1);
146 return 'SkipFore'
147 };
148
149 sub SkipBackStateRules {
150 return 'Space' if (1);
151 return 'SkipBack'
152 };
153
154 sub FlipCmdStateRules {
155 return 'FlipCmd'
156 };
157
158 sub LeftCmdStateRules {
159 return 'LeftCmd'
160 };
161
162 sub RightCmdStateRules {
163 return 'RightCmd'
164 };
165
166 sub WhileCmdStateRules {
167 return 'WhileCmd'
168 };
169
170 sub WendCmdStateRules {
171 return 'WendCmd'
172 };
173
174 sub ReplyClassMember {
175 return $_[0] eq 'ContReply' ||
176 $_[0] eq 'SkipReply' ||
177 0
178 };
179
180 sub SignalClassMember {
181 return $_[0] eq 'LeftSig' ||
182 $_[0] eq 'RightSig' ||
183 $_[0] eq 'FlipSig' ||
184 $_[0] eq 'QuerySig' ||
185 0
186 };
187
188 $Appearance = {
189 'Bus' => '-',
190 'ContReply' => 'C',
191 'ContTool' => 'c',
192 'DataPtr' => 'd',
193 'FlipCmd' => '*',
194 'FlipSig' => 'F',
195 'FlipTool' => 'f',
196 'InstrMark' => 'I',
197 'InstrPtr' => 'i',
198 'LeftCmd' => '<',
199 'LeftSig' => 'L',
200 'LeftTool' => 'l',
201 'OffBit' => '0',
202 'OnBit' => '1',
203 'QuerySig' => 'Q',
204 'RightCmd' => '>',
205 'RightSig' => 'R',
206 'RightTool' => 'r',
207 'SkipBack' => '{',
208 'SkipFore' => '}',
209 'SkipReply' => 'S',
210 'SkipStart' => '!',
211 'SkipStop' => '%',
212 'SkipTool' => 's',
213 'Space' => ' ',
214 'WakeMark' => 'W',
215 'WendCmd' => ']',
216 'WhileCmd' => '[',
217
218 };
219
220 $InputCodec = {
221 '-' => 'Bus',
222 'C' => 'ContReply',
223 'c' => 'ContTool',
224 'd' => 'DataPtr',
225 '*' => 'FlipCmd',
226 'F' => 'FlipSig',
227 'f' => 'FlipTool',
228 'I' => 'InstrMark',
229 'i' => 'InstrPtr',
230 '<' => 'LeftCmd',
231 'L' => 'LeftSig',
232 'l' => 'LeftTool',
233 '0' => 'OffBit',
234 '1' => 'OnBit',
235 'Q' => 'QuerySig',
236 '>' => 'RightCmd',
237 'R' => 'RightSig',
238 'r' => 'RightTool',
239 '{' => 'SkipBack',
240 '}' => 'SkipFore',
241 'S' => 'SkipReply',
242 '!' => 'SkipStart',
243 '%' => 'SkipStop',
244 's' => 'SkipTool',
245 ' ' => 'Space',
246 'W' => 'WakeMark',
247 ']' => 'WendCmd',
248 '[' => 'WhileCmd',
249
250 };
251
252 $StateRule = {
253 'Bus' => \&main::BusStateRules,
254 'ContReply' => \&main::ContReplyStateRules,
255 'ContTool' => \&main::ContToolStateRules,
256 'DataPtr' => \&main::DataPtrStateRules,
257 'FlipCmd' => \&main::FlipCmdStateRules,
258 'FlipSig' => \&main::FlipSigStateRules,
259 'FlipTool' => \&main::FlipToolStateRules,
260 'InstrMark' => \&main::InstrMarkStateRules,
261 'InstrPtr' => \&main::InstrPtrStateRules,
262 'LeftCmd' => \&main::LeftCmdStateRules,
263 'LeftSig' => \&main::LeftSigStateRules,
264 'LeftTool' => \&main::LeftToolStateRules,
265 'OffBit' => \&main::OffBitStateRules,
266 'OnBit' => \&main::OnBitStateRules,
267 'QuerySig' => \&main::QuerySigStateRules,
268 'RightCmd' => \&main::RightCmdStateRules,
269 'RightSig' => \&main::RightSigStateRules,
270 'RightTool' => \&main::RightToolStateRules,
271 'SkipBack' => \&main::SkipBackStateRules,
272 'SkipFore' => \&main::SkipForeStateRules,
273 'SkipReply' => \&main::SkipReplyStateRules,
274 'SkipStart' => \&main::SkipStartStateRules,
275 'SkipStop' => \&main::SkipStopStateRules,
276 'SkipTool' => \&main::SkipToolStateRules,
277 'Space' => \&main::SpaceStateRules,
278 'WakeMark' => \&main::WakeMarkStateRules,
279 'WendCmd' => \&main::WendCmdStateRules,
280 'WhileCmd' => \&main::WhileCmdStateRules,
281
282 };
283
284 load_playfield($ARGV[0]);
285
286 display_playfield();
287
288 while (!$done)
289 {
290 process_playfield();
291 display_playfield();
292 }
293
294 exit(0);
295
296 ### END ###
0 /*
1 * The Braktif Cellular Automaton
2 * June 2005, Chris Pressey
3 * BSD License added May 3 2007
4 */
5
6 /*
7 * Copyright (c)2007 Chris Pressey, Cat's Eye Technologies.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notices, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notices, this list of conditions, and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 * 3. Neither the names of the copyright holders nor the names of their
21 * contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES INCLUDING, BUT NOT
26 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38 /*
39 * Braktif is an esoteric programming language very similar to
40 * 'Brainfuck F' and 'Archway', with a small but significant
41 * difference: Braktif is formulated as a 28-state cellular automaton.
42 *
43 * Braktif playfields are divided into a program on the right and
44 * a data storage area on the left. (The data storage area can be
45 * considered to extend indefinately to the left.) The program
46 * and data area are connected by a 'bus'. On the bus sit the
47 * instruction pointer, which rests underneath the part of the
48 * program which is currently executing, and the data pointer, which
49 * rests underneath the part of the storage which is currently being
50 * addressed. The instruction pointer and data pointer communicate
51 * by means of signals (from the IP to the DP) and replies (from the
52 * DP to the IP) sent along the bus.
53 *
54 * The instructions of a Braktif program resemble those of Smallfuck
55 * or Brainfuck F:
56 *
57 * * flip current data bit
58 * > advance DP one cell to the right
59 * < advance DP one cell to the left
60 * [ if current data bit == 0, skip to matching ]
61 * ] skip back to matching [
62 *
63 * The structure of Braktif programs resembles that of Archway. Each
64 * nested loop must be raised up one level. In addition, extra space
65 * must be left after [ instructions, and at least one non-[]
66 * instruction must occur after a ] instruction, so that signals have
67 * sufficient space in which to propagate.
68 *
69 * The data storage area of a Braktif playfield resembles the tape of
70 * a Brainfuck F program (or a Smallfuck program, if an arbitrary limit
71 * is imposed on it) except that it is bounded on the *right*, not the
72 * left.
73 *
74 * The final result of all this is that the following Brainfuck F
75 * program translates to the following Braktif program (the '...'
76 * indicates the quiescent repeating pattern extending off to infinity):
77 *
78 * Brainfuck F: +[>+]
79 *
80 * Braktif:
81 * <*
82 * ... 00000000000000 *[---]
83 * ... -------------d-i- --
84 *
85 * So... why Braktif?
86 *
87 * - eliminates 'spooky action at a distance' from the Brainfuck model:
88 * the communication between the code and the tape is made explicit
89 * (and explicitly planar, FWIW WRT the wire-crossing problem.)
90 * - horribly inefficient because of this. Flipping the n'th data cell
91 * from the m'th instruction of the program is now an O(n+m) operation.
92 * What fun!
93 * - makes a passable "poor man's visual debugger" for Brainfuck F.
94 * - makes experimenting with concurrent models easily. For example it
95 * might be feasible to add a few states what would act as a simple
96 * mutex so that two different programs could share one data store.
97 *
98 * Finally, I do not claim that this is the most efficient formulation
99 * imaginable... there is certainly room for optimization. For
100 * example, half of the 'Tool' states could probably be done away with
101 * entirely if the signals were to transition themselves directly into
102 * responses. But a minimum of states is not the real goal (otherwise
103 * one could just settle for John Conway's Game of Life and be done
104 * with it,) and the 'Tool' states lend a certain straightforwardness.
105 */
106
107 /* -------------------- Transmission Media --------------------- */
108
109 state Space " "
110 to SkipBack when (^ WakeMark and ^> WendCmd) or (> SkipBack),
111 to SkipStart when ^< SkipReply and ^ InstrMark,
112 to SkipFore when v< SkipStart or < SkipFore;
113
114 state Bus "-"
115 to > when > is Signal,
116 to ^> when ^> is Signal,
117 to v> when v> is Signal,
118 to < when < is Reply,
119 to ^< when ^< is Reply,
120 to v< when v< is Reply,
121 to ContTool when > LeftTool or < RightTool,
122 to ContReply when < ContTool,
123 to SkipReply when < SkipTool,
124 to LeftSig when > InstrPtr and ^> LeftCmd,
125 to RightSig when > InstrPtr and ^> RightCmd,
126 to FlipSig when > InstrPtr and ^> FlipCmd,
127 to QuerySig when > InstrPtr and ^> WhileCmd,
128 to InstrPtr when < WakeMark or v< WakeMark or ^< Wakemark,
129 to InstrPtr when < InstrPtr and ^< Space,
130 to InstrPtr when > SkipBack,
131 to SkipStop when < SkipFore,
132 to InstrPtr when < SkipStop;
133
134 /* -------------------- Signals and Replies -------------------- */
135
136 class Signal
137 to Bus;
138
139 class Reply
140 to Bus;
141
142 state LeftSig "L" is Signal;
143 state RightSig "R" is Signal;
144 state FlipSig "F" is Signal;
145 state QuerySig "Q" is Signal;
146
147 state ContReply "C" is Reply;
148 state SkipReply "S" is Reply;
149
150 /* ------------------- Data Store: Data Pointer ---------------- */
151
152 state DataPtr "d"
153 to FlipTool when > FlipSig,
154 to LeftTool when > LeftSig,
155 to RightTool when > RightSig,
156 to SkipTool when > QuerySig and ^ OffBit,
157 to ContTool when > QuerySig and ^ OnBit;
158
159 state FlipTool "f"
160 to ContTool;
161 state LeftTool "l"
162 to Bus;
163 state RightTool "r"
164 to Bus;
165 state ContTool "c"
166 to DataPtr;
167 state SkipTool "s"
168 to DataPtr;
169
170 /* ----------------- Data Store: Tape Contents ----------------- */
171
172 state OnBit "1"
173 to OffBit when v FlipTool;
174 state OffBit "0"
175 to OnBit when v FlipTool;
176
177 /* ----------------- Program: Instruction Pointer -------------- */
178
179 state InstrPtr "i"
180 to Bus when ^ Space,
181 to InstrMark;
182
183 state InstrMark "I"
184 to WakeMark when < ContReply,
185 to Bus when < SkipReply;
186
187 state WakeMark "W"
188 to Bus;
189
190 /* ----------------- Program: Instruction Skipper -------------- */
191
192 state SkipStart "!"
193 to Space;
194 state SkipStop "%"
195 to Bus;
196 state SkipFore "}"
197 to Space;
198 state SkipBack "{"
199 to Space;
200
201 /* -------------------- Program: Instructions ------------------- */
202
203 state FlipCmd "*";
204 state LeftCmd "<";
205 state RightCmd ">";
206 state WhileCmd "[";
207 state WendCmd "]".