171 lines
29 KiB
Plaintext
171 lines
29 KiB
Plaintext
<!-- TITLE: implementing goto statements in python (in under 50 lines)-->
|
|
<!-- DATE: 2024-09-12 08:43:04 -->
|
|
python is extremely extensible, though I'm not sure that is intentional.
|
|
<hr>
|
|
firstly, here is the end product of this venture:
|
|
<pre>
|
|
<span class="-keyword">from</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto_label</span></span> <span class="-keyword">import</span> <span class="Operator"><span class="SpecialChar">*</span></span>
|
|
<span class="-variable">count</span> <span class="Operator">=</span> <span class="Number">0</span>
|
|
<span class="Comment"><span class="-spell">#LABEL lol</span></span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'this prints twice'</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable">count</span> <span class="Operator">+=</span> <span class="Number">1</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineError">goto</span></span> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">lol</span></span> <span class="-keyword">if</span> <span class="-punctuation-bracket">(</span><span class="-variable">count</span> <span class="Operator"><=</span> <span class="Number">1</span><span class="-punctuation-bracket">)</span> <span class="-keyword">else</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto</span></span> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">goto_statements_are_a_perfectly_reasonable_thing_to_have_in_python</span></span>
|
|
|
|
<span class="Comment"><span class="-spell">#LABEL last_print</span></span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'this prints last'</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">stop</span></span></span><span class="-variable"></span>
|
|
|
|
<span class="Comment"><span class="-spell">#LABEL ellipsis</span></span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'at least Ellipsis() has some use now, for normal reasons that make sense'</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">last_print</span></span></span><span class="-variable"></span>
|
|
|
|
<span class="Comment"><span class="-spell">#LABEL goto_statements_are_a_perfectly_reasonable_thing_to_have_in_python</span></span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'I am sure this is how the variety of language features I am abusing were intended to be used'</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable">ellipsis</span></span><span class="-variable"></span>
|
|
<span class="Comment"><span class="-spell">#LABEL stop</span></span>
|
|
<span class="-punctuation-delimiter">...</span>
|
|
|
|
</pre>
|
|
its beautiful.<br>
|
|
this outputs the following:
|
|
<pre>
|
|
this prints twice
|
|
this prints twice
|
|
I am sure this is how the variety of language features I am abusing were intended to be used
|
|
at least Ellipsis() has some use now, for normal reasons that make sense
|
|
this prints last
|
|
</pre>
|
|
<hr>
|
|
now then, how does it work?
|
|
<h3>design decisions</h3>
|
|
given that evidence suggests python programs can be edited, I decided not to use line number based gotos and instead define labels that could be jumped to.
|
|
this makes things less annoying to edit and maintain, and developer experience is obviously a very important consideration with this project.<br>
|
|
additionally, to maximize ease with which this ""library"" can be utilized, one must only import the file to experience the wonder of python with goto statements.
|
|
<h3>technical implementation</h3>
|
|
firstly, labels: <br>
|
|
goto_label.py has a function prepare_labels(fp, scope).
|
|
this function looks for any labels (defined via /^#LABEL labelname/) in the file at fp, and defines them under the scope scope.
|
|
each label is defined as a label object. I resent using an object for this (which you can see by my not using the class keyword), but python is python and you cannot override operators without having a class.
|
|
I could just not override the operators, but I want goto to be called in a unique way that is separate from how a function would be called.
|
|
label objects have only one attribute: lineno, which is determined by an extremely rudimentary parser and then offset by 2 to account for the fact that lines are 0 indexed in the "parser" but not in real life and the fact that the label definition comment takes its own line.
|
|
<br><br>
|
|
the actual goto implementation:<br>
|
|
I don't remember how this works because I wrote most of the _goto function like 3 months ago after reading the sys and inspect module docs.
|
|
my projects have this fun property where they are in one of three states: done; not touched or thought about for 2-36 months; and done.
|
|
oh well, the goto function is vaguely self explanatory anyways.
|
|
<br>
|
|
there is some weirdness with operator overloading and how every goto statement is actually just calling what would normally be the bitwise and operator on an instance of the class _goto (not to be confused with the function _goto) and a label object, but that is both very simple and not required to understand this.<br>
|
|
also, I don't want to explain it because I am tired.
|
|
<br><br>
|
|
automatically parsing the importing file on import:<br>
|
|
normally, globals are not shared between modules, but python has this cool feature where if there is a general statement to be made about it then this statement can be invalidated using either the sys, inspect, or ctypes library.
|
|
this is easily the simplest part as we just grab the filename and global scope of the importing file via the inspect library and pass them to prepare_labels().
|
|
<hr>
|
|
<h3>goto_label.py</h3>
|
|
<pre>
|
|
<span class="-keyword">import</span> <span class="-variable">sys</span><span class="-punctuation-delimiter">,</span> <span class="-variable">inspect</span>
|
|
|
|
<span class="-variable">debug</span> <span class="Operator">=</span> <span class="Boolean">False</span>
|
|
|
|
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">prepare_labels</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">fp</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable">scope</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-keyword">with</span> <span class="-variable"><span class="-function"><span class="-function-builtin">open</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">fp</span><span class="-punctuation-delimiter">,</span> <span class="String">'r'</span><span class="-punctuation-bracket">)</span> <span class="-keyword">as</span> <span class="-variable">f</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable">lines</span> <span class="Operator">=</span> <span class="-variable">f</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">readlines</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span>
|
|
|
|
<span class="-keyword">for</span> <span class="-variable">lineno</span><span class="-punctuation-delimiter">,</span> <span class="-variable">line</span> <span class="-keyword-operator">in</span> <span class="-variable"><span class="-function"><span class="-function-builtin">enumerate</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">lines</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-keyword">if</span> <span class="-variable">line</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">startswith</span></span></span><span class="-punctuation-bracket">(</span><span class="String">'#LABEL'</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="Comment"><span class="-spell"># 1 + 1, first to account for 0 index then to account for comment line</span></span>
|
|
<span class="-variable">scope</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-constant-builtin"><span class="-variable"><span class="-function">__setitem__</span></span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">line</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">split</span></span></span><span class="-punctuation-bracket">(</span><span class="String">' '</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">[</span><span class="Number">1</span><span class="-punctuation-bracket">]</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">strip</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type">type</span></span></span></span><span class="-punctuation-bracket">(</span>
|
|
<span class="String">'label'</span><span class="-punctuation-delimiter">,</span>
|
|
<span class="-punctuation-bracket">(</span><span class="-variable"><span class="Type">object</span></span><span class="-punctuation-delimiter">,</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">,</span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type">dict</span></span></span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">line</span></span><span class="Operator">=</span><span class="-variable">lineno</span><span class="Operator">+</span><span class="Number">2</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">)</span>
|
|
|
|
<span class="-variable">_goto</span> <span class="Operator">=</span> <span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type"><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError">type</span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"></span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"></span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"></span></span></span><span class="DiagnosticUnderlineError"><span class="DiagnosticUnderlineError"><span class="-punctuation-bracket">(</span><span class="String">'goto'</span><span class="-punctuation-delimiter">,</span> <span class="-punctuation-bracket">(</span><span class="-variable"><span class="Type">object</span></span><span class="-punctuation-delimiter">,</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-function"><span class="-function-builtin"><span class="Type">dict</span></span></span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-constant-builtin"><span class="-variable">__and__</span></span></span><span class="Operator">=</span><span class="-keyword-function">lambda</span> <span class="-variable"><span class="-variable">_</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable">other</span></span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="-function">_goto</span></span><span class="-punctuation-bracket">(</span><span class="-variable">other</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">line</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">)</span></span><span class="-punctuation-bracket"></span></span><span class="-punctuation-bracket"></span>
|
|
|
|
<span class="-variable">goto</span> <span class="Operator">=</span> <span class="-variable"><span class="-function"><span class="DiagnosticUnderlineError">_goto</span></span><span class="DiagnosticUnderlineError"></span></span><span class="DiagnosticUnderlineError"><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span></span><span class="-punctuation-bracket"></span>
|
|
|
|
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">_goto</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">lineno</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-keyword">if</span> <span class="-variable">debug</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">lineno</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable">frame</span> <span class="Operator">=</span> <span class="-variable">sys</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">_getframe</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_back</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="DiagnosticUnderlineError">f_back</span></span></span>
|
|
<span class="-variable">called_from</span> <span class="Operator">=</span> <span class="-variable">frame</span>
|
|
|
|
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">hook</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">frame</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable">event</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable"><span class="-variable"><span class="Comment">arg</span></span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-keyword">if</span> <span class="-variable">event</span> <span class="Operator">==</span> <span class="String">'line'</span> <span class="-keyword-operator">and</span> <span class="-variable">frame</span> <span class="Operator">==</span> <span class="-variable">called_from</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-keyword">try</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_lineno</span></span> <span class="Operator">=</span> <span class="-variable">lineno</span>
|
|
<span class="-keyword">except</span> <span class="-variable"><span class="Type"><span class="Type">ValueError</span></span></span> <span class="-keyword">as</span> <span class="-variable">e</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="String">"jump failed:"</span><span class="-punctuation-delimiter">,</span> <span class="-variable">e</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-keyword">while</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_trace</span></span> <span class="Operator">=</span> <span class="-constant-builtin">None</span>
|
|
<span class="-variable">frame</span> <span class="Operator">=</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_back</span></span>
|
|
<span class="-keyword">return</span> <span class="-constant-builtin">None</span>
|
|
<span class="-keyword">return</span> <span class="-variable">hook</span>
|
|
|
|
<span class="-keyword">while</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_trace</span></span> <span class="Operator">=</span> <span class="-variable">hook</span>
|
|
<span class="-variable">frame</span> <span class="Operator">=</span> <span class="-variable">frame</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_back</span></span>
|
|
<span class="-variable">sys</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">settrace</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">hook</span><span class="-punctuation-bracket">)</span>
|
|
|
|
<span class="-variable"><span class="-function">prepare_labels</span></span><span class="-punctuation-bracket">(</span><span class="-variable">inspect</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">stack</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">[</span><span class="Operator">-</span><span class="Number">1</span><span class="-punctuation-bracket">]</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">frame</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_code</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">co_filename</span></span><span class="-punctuation-delimiter">,</span> <span class="-variable">inspect</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable"><span class="-function">stack</span></span></span><span class="-punctuation-bracket">(</span><span class="-punctuation-bracket">)</span><span class="-punctuation-bracket">[</span><span class="Operator">-</span><span class="Number">1</span><span class="-punctuation-bracket">]</span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">frame</span></span><span class="-punctuation-delimiter">.</span><span class="-variable"><span class="-variable">f_globals</span></span><span class="-punctuation-bracket">)</span>
|
|
|
|
</pre>
|
|
<hr>
|
|
I find much enjoyment in the syntax for calling a goto statement being goto &label. it looks like something that thoroughly does not belong in python.
|
|
<br><br>
|
|
ideas for future improvement:
|
|
making label names override builtin function names (unreasonably possible) and making a __call__ method on label objects that jumps to that label.
|
|
hopefully no one creates any labels named "print".
|
|
<hr>
|
|
random other programs I (badly) implemented using if conditions only for goto statements out of boredom:
|
|
<h3>fibonacci</h3>
|
|
<pre>
|
|
<span class="-keyword">from</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto_label</span></span> <span class="-keyword">import</span> <span class="Operator"><span class="SpecialChar">*</span></span>
|
|
|
|
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">fib</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">n</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable">depth</span> <span class="Operator">=</span> <span class="Number">0</span>
|
|
<span class="-variable">a</span> <span class="Operator">=</span> <span class="Number">1</span>
|
|
<span class="-variable">b</span> <span class="Operator">=</span> <span class="Number">0</span>
|
|
<span class="Comment"><span class="-spell">#LABEL fib_start</span></span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable">a</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable">a</span><span class="-punctuation-delimiter">,</span> <span class="-variable">b</span><span class="-punctuation-delimiter">,</span> <span class="-variable">depth</span> <span class="Operator">=</span> <span class="-variable">b</span><span class="-punctuation-delimiter">,</span> <span class="-variable">b</span> <span class="Operator">+</span> <span class="-variable">a</span><span class="-punctuation-delimiter">,</span> <span class="-variable">depth</span> <span class="Operator">+</span> <span class="Number">1</span>
|
|
<span class="-keyword">if</span> <span class="-variable">depth</span> <span class="Operator">></span> <span class="-variable">n</span><span class="Operator">+</span><span class="Number">1</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">fib_end</span></span></span><span class="-variable"></span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">fib_start</span></span></span><span class="-variable"></span>
|
|
<span class="Comment"><span class="-spell">#LABEL fib_end</span></span>
|
|
<span class="-punctuation-delimiter">...</span>
|
|
|
|
<span class="-variable"><span class="-function">fib</span></span><span class="-punctuation-bracket"><span class="MatchParen">(</span></span><span class="Number">20</span><span class="-punctuation-bracket"><span class="MatchParen">)</span></span>
|
|
|
|
</pre>
|
|
<h3>fizzbuzz</h3>
|
|
<pre>
|
|
<span class="-keyword">from</span> <span class="-variable"><span class="DiagnosticUnderlineError">goto_label</span></span> <span class="-keyword">import</span> <span class="Operator"><span class="SpecialChar">*</span></span>
|
|
|
|
<span class="-keyword-function">def</span> <span class="-variable"><span class="-function">fizzbuzz</span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="-variable">n</span></span><span class="-punctuation-bracket">)</span><span class="-punctuation-delimiter">:</span>
|
|
<span class="-variable">count</span> <span class="Operator">=</span> <span class="Number">0</span>
|
|
<span class="Comment"><span class="-spell">#LABEL fizz_start</span></span>
|
|
<span class="-variable"><span class="Type">str</span></span> <span class="Operator">=</span> <span class="String">''</span>
|
|
<span class="-keyword">if</span> <span class="-variable">n</span> <span class="Operator">==</span> <span class="-variable">count</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">fizz_end</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
|
|
<span class="-variable">count</span> <span class="Operator">+=</span> <span class="Number">1</span>
|
|
<span class="-keyword">if</span> <span class="-variable">count</span> <span class="Operator">%</span> <span class="Number">3</span> <span class="Operator">==</span> <span class="Number">0</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">fizz</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
|
|
<span class="Comment"><span class="-spell">#LABEL buzz_check</span></span>
|
|
<span class="-keyword">if</span> <span class="-variable">count</span> <span class="Operator">%</span> <span class="Number">5</span> <span class="Operator">==</span> <span class="Number">0</span><span class="-punctuation-delimiter">:</span> <span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">buzz</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">output</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
|
|
|
|
<span class="Comment"><span class="-spell">#LABEL fizz</span></span>
|
|
<span class="-variable"><span class="Type">str</span></span> <span class="Operator">+=</span> <span class="String">'fizz'</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">buzz_check</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
|
|
<span class="Comment"><span class="-spell">#LABEL buzz </span></span>
|
|
<span class="-variable"><span class="Type">str</span></span> <span class="Operator">+=</span> <span class="String">'buzz'</span>
|
|
<span class="Comment"><span class="-spell">#LABEL output</span></span>
|
|
<span class="-variable"><span class="-function"><span class="-function-builtin">print</span></span></span><span class="-punctuation-bracket">(</span><span class="-variable"><span class="Type">str</span></span> <span class="-keyword">if</span> <span class="-variable"><span class="Type">str</span></span> <span class="-keyword">else</span> <span class="-variable">count</span><span class="-punctuation-bracket">)</span>
|
|
<span class="-variable"><span class="DiagnosticUnderlineWarn"><span class="DiagnosticUnderlineError">goto</span></span></span><span class="DiagnosticUnderlineWarn"> <span class="Operator">&</span><span class="-variable"><span class="DiagnosticUnderlineError">fizz_start</span></span></span><span class="-variable"></span><span class="-punctuation-delimiter">;</span>
|
|
<span class="Comment"><span class="-spell">#LABEL fizz_end </span></span>
|
|
<span class="-punctuation-delimiter">...</span>
|
|
|
|
<span class="-variable"><span class="-function">fizzbuzz</span></span><span class="-punctuation-bracket"><span class="MatchParen">(</span></span><span class="Number">100</span><span class="-punctuation-bracket"><span class="MatchParen">)</span></span>
|
|
|
|
</pre>
|
|
<hr>
|
|
<footnote>number of times the python interpreter segfaulted today: 7</footnote><br>
|
|
<footnote>syntax highlighting here is done via :TOhtml in vim. it should work?</footnote>
|