Recently Written · git

recentlywritten

my writings (done recently)

git clone https://github.com/equwal/recentlywritten

Log | Files | Refs


git/LispBrain/commit/6b9687c3ea2bf2d795e7743ad85bc0a88e21a58b.html (4894 bytes)

1 <!DOCTYPE html>
2 <html lang="en"><head><meta charset="UTF-8" />
3 <meta name="viewport" content="width=device-width, initial-scale=1" />
4 <title>LispBrain 6b9687c3 - Recently Written</title>
5 <link rel="stylesheet" href="../../stagit.css" />
6 </head><body>
7 <div id="top"><a href="../../../index.html">Recently Written</a> &middot; <a href="../../index.html">git</a></div>
8 <h1>LispBrain</h1><span class="desc">The best Brainfuck debugger available, if you know how the Common Lisp debugger works. Uses Common Lisp&#x27;s ease of debugging to make debugging Brainfuck code easy. Almost entirely useless.</span><p class="url">git clone https://github.com/equwal/LispBrain</p><p><a href="../../LispBrain/index.html">Log</a> | <a href="../../LispBrain/files.html">Files</a> | <a href="../../LispBrain/refs.html">Refs</a></p><hr/>
9 <div id="content">
10 <pre>commit 6b9687c3ea2bf2d795e7743ad85bc0a88e21a58b
11 Spenser Truex &lt;struex0@gmail.com&gt;
12 2016-02-16 20:38:29 -0800
13 
14 Added parentheses to *separators*
15 
16 </pre><pre> interpreter.lisp | 33 ++++++++++++++++++++++-----------
17  1 file changed, 22 insertions(+), 11 deletions(-)
18 </pre><pre>diff --git a/interpreter.lisp b/interpreter.lisp
19 index d33923b..20e1f91 100644
20 --- a/interpreter.lisp
21 +++ b/interpreter.lisp
22 <span class="h">@@ -22,12 +22,16 @@</span>
23  (defvar *output* &quot;&quot;
24    &quot;Defaults to an empty string because it is setf&#x27;d by other functions&quot;)
25  
26 <span class="a">+(defvar *loop-depth* 0</span>
27 <span class="a">+  &quot;Used to produce helpful error messages about extra &#x27;]&#x27; characters in </span>
28 <span class="a">+BF code extra &#x27;[&#x27; characters are not helped by this variable&quot;)</span>
29 <span class="a">+</span>
30  (defparameter *initial-element* 0
31    &quot;initial value for inside the byte array&quot;)
32  
33 <span class="d">-(defparameter *separators* &#x27;(#\Newline #\Space)</span>
34 <span class="d">-  &quot;#F notation separators.</span>
35 <span class="d">-These can be changed to allow whitespace comments&quot;)</span>
36 <span class="a">+(defparameter *separators* &#x27;(#\Newline #\Space #\))</span>
37 <span class="a">+  &quot;#F notation separators. These can be changed to allow whitespace comments </span>
38 <span class="a">+or to break a right parentheses immediately to the right side&quot;)</span>
39  
40  (defun make-tape-array ()
41    &quot;Creates a new tape array&quot;
42 <span class="h">@@ -70,12 +74,14 @@ These can be changed to allow whitespace comments&quot;)</span>
43    (char-list-&gt;string-aux char-list (make-string (length char-list)) 0))
44  
45  (defun shorthand-fuck-aux (stream list)
46 <span class="a">+  &quot;Recursive reader macro. A compiler from within Lisp!&quot;</span>
47    (let ((char (read-char stream nil nil)))
48 <span class="d">-    ;; TODO: Replace the #\Space, #\Newline, #\Tab with proper separations</span>
49      (if (or (some #&#x27;(lambda (x) (char-equal x char))
50  		  *separators*)
51  	    (null char))
52 <span class="d">-	(char-list-&gt;string (nreverse list))</span>
53 <span class="a">+	(progn (when (char= #\) char)</span>
54 <span class="a">+		 (unread-char char stream))</span>
55 <span class="a">+	       (char-list-&gt;string (nreverse list)))</span>
56  	(shorthand-fuck-aux stream (push char list)))))
57  
58  (defun shorthand-fuck (stream char subchar)
59 <span class="h">@@ -183,7 +189,8 @@ These can be changed to allow whitespace comments&quot;)</span>
60  	    (skip-loop-aux (1+ position) depth)))))
61  
62  (defun skip-loop (position)
63 <span class="d">-  (skip-loop-aux position 0))</span>
64 <span class="a">+  (handler-case (skip-loop-aux position 0)</span>
65 <span class="a">+    ))</span>
66  
67  (defun fuck (brainfuck-string)
68    &quot;Interpret the brainfuck&quot;
69 <span class="h">@@ -192,10 +199,14 @@ These can be changed to allow whitespace comments&quot;)</span>
70    ;; Loop over each character in the string
71    (loop for position to (1- (length *brainfuck*))
72       do (handler-case (one-off-fuck position)
73 <span class="d">-	  ;; Handles looping with the condition system</span>
74 <span class="d">-	  (end-of-loop () (setf position</span>
75 <span class="d">-				(1- (goto position))))</span>
76 <span class="d">-	  (open-loop-at-zero () (setf position</span>
77 <span class="d">-				      (1- (skip-loop position))))))</span>
78 <span class="a">+	  ;; Handles brainfuck looping with the condition system</span>
79 <span class="a">+	  (end-of-loop () (if (&lt;= *loop-depth* 0)</span>
80 <span class="a">+			      (error &quot;Extra right square bracket &#x27;]&#x27; does not match a &#x27;[&#x27; somewhere else&quot;)</span>
81 <span class="a">+			      (progn (decf *loop-depth*)</span>
82 <span class="a">+				     (setf position</span>
83 <span class="a">+					   (1- (goto position))))))</span>
84 <span class="a">+	  (open-loop-at-zero () (progn (incf *loop-depth*)</span>
85 <span class="a">+				       (setf position</span>
86 <span class="a">+					     (1- (skip-loop position)))))))</span>
87    *output*)
88  </pre>
89 </div></body></html>