Created
March 18, 2017 08:00
-
-
Save bennydictor/e2a4a7e68e4b441d4839fc29080c6272 to your computer and use it in GitHub Desktop.
Brainfuck on Vim macros
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This is a Brainfuck interpreter written in vim macros | |
To use it, copy the fourth line to `a' register (4G"ayy), | |
and run the macro (@a). | |
{macro} | |
/^{letterh} | |
$h"cyl/^{program} | |
j0"cx/^{code:c} | |
j"myy@m | |
Your program here: | |
{program} | |
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+. | |
The tape: | |
{tapebefore} | |
{tapeafter} | |
Input: | |
{input} | |
Output: | |
{output} | |
=== IMPLEMENTATION === | |
{letterh} | |
=== READTAPE === | |
Appends zeroes to the tape if nesessary. | |
{readtape} | |
v"cd"cPmr/{readtape:c} | |
j"myy@m | |
{readtape: | |
} | |
'ri0 0 | |
{readtape:0} {readtape:1} {readtape:2} {readtape:3} {readtape:4} {readtape:5} {readtape:6} {readtape:6} {readtape:7} {readtape:8} {readtape:9} | |
'r | |
=== CODE === | |
{code:.} // actially search for {code:.} matches all blocks, so the actual `.' is first | |
/^{readtape} | |
j"myy/^{tapeafter} | |
j@myw/^{output} | |
j$p@a | |
{code:,} | |
/^{readtape} | |
j"myy/^{tapeafter} | |
j@mdw/^{input} | |
jdw/^{tapeafter} | |
jP@a | |
{code:+} | |
/^{readtape} | |
j"myy/^{tapeafter} | |
j@m:s/256/0/e | |
@a | |
{code:-} | |
/^{readtape} | |
j"myy/^{tapeafter} | |
j@m:s/-1/255/e | |
@a | |
{code:>} | |
/^{readtape} | |
j"myy/^{tapebefore} | |
j@m/^{readtape} | |
j"myy/^{tapeafter} | |
j@m/^{tapeafter} | |
jdw/^{tapebefore} | |
jP@a | |
{code:<} | |
/^{readtape} | |
j"myy/^{tapebefore} | |
j@m/^{readtape} | |
j"myy/^{tapeafter} | |
j@m/^{tapebefore} | |
jdw/^{tapeafter} | |
jP@a | |
{code:[} | |
/^{program} | |
jI[/^{readtape} | |
j"myy/^{tapeafter} | |
j@m"wyw/{cycle:w} | |
j"myy@m | |
{code:]} | |
:echo "something went horribly wrong" | |
{code:h} | |
/^{output} | |
j:echo "done!" | |
{cycle:0 } | |
/^{program} | |
jva[d@a | |
{cycle:1 } {cycle:2 } {cycle:3 } {cycle:4 } {cycle:5 } {cycle:6 } {cycle:7 } {cycle:8 } {cycle:9 } {cycle:10 } {cycle:11 } {cycle:12 } {cycle:13 } {cycle:14 } {cycle:15 } {cycle:16 } {cycle:17 } {cycle:18 } {cycle:19 } {cycle:20 } {cycle:21 } {cycle:22 } {cycle:23 } {cycle:24 } {cycle:25 } {cycle:26 } {cycle:27 } {cycle:28 } {cycle:29 } {cycle:30 } {cycle:31 } {cycle:32 } {cycle:33 } {cycle:34 } {cycle:35 } {cycle:36 } {cycle:37 } {cycle:38 } {cycle:39 } {cycle:40 } {cycle:41 } {cycle:42 } {cycle:43 } {cycle:44 } {cycle:45 } {cycle:46 } {cycle:47 } {cycle:48 } {cycle:49 } {cycle:50 } {cycle:51 } {cycle:52 } {cycle:53 } {cycle:54 } {cycle:55 } {cycle:56 } {cycle:57 } {cycle:58 } {cycle:59 } {cycle:60 } {cycle:61 } {cycle:62 } {cycle:63 } {cycle:64 } {cycle:65 } {cycle:66 } {cycle:67 } {cycle:68 } {cycle:69 } {cycle:70 } {cycle:71 } {cycle:72 } {cycle:73 } {cycle:74 } {cycle:75 } {cycle:76 } {cycle:77 } {cycle:78 } {cycle:79 } {cycle:80 } {cycle:81 } {cycle:82 } {cycle:83 } {cycle:84 } {cycle:85 } {cycle:86 } {cycle:87 } {cycle:88 } {cycle:89 } {cycle:90 } {cycle:91 } {cycle:92 } {cycle:93 } {cycle:94 } {cycle:95 } {cycle:96 } {cycle:97 } {cycle:98 } {cycle:99 } {cycle:100 } {cycle:101 } {cycle:102 } {cycle:103 } {cycle:104 } {cycle:105 } {cycle:106 } {cycle:107 } {cycle:108 } {cycle:109 } {cycle:110 } {cycle:111 } {cycle:112 } {cycle:113 } {cycle:114 } {cycle:115 } {cycle:116 } {cycle:117 } {cycle:118 } {cycle:119 } {cycle:120 } {cycle:121 } {cycle:122 } {cycle:123 } {cycle:124 } {cycle:125 } {cycle:126 } {cycle:127 } {cycle:128 } {cycle:129 } {cycle:130 } {cycle:131 } {cycle:132 } {cycle:133 } {cycle:134 } {cycle:135 } {cycle:136 } {cycle:137 } {cycle:138 } {cycle:139 } {cycle:140 } {cycle:141 } {cycle:142 } {cycle:143 } {cycle:144 } {cycle:145 } {cycle:146 } {cycle:147 } {cycle:148 } {cycle:149 } {cycle:150 } {cycle:151 } {cycle:152 } {cycle:153 } {cycle:154 } {cycle:155 } {cycle:156 } {cycle:157 } {cycle:158 } {cycle:159 } {cycle:160 } {cycle:161 } {cycle:162 } {cycle:163 } {cycle:164 } {cycle:165 } {cycle:166 } {cycle:167 } {cycle:168 } {cycle:169 } {cycle:170 } {cycle:171 } {cycle:172 } {cycle:173 } {cycle:174 } {cycle:175 } {cycle:176 } {cycle:177 } {cycle:178 } {cycle:179 } {cycle:180 } {cycle:181 } {cycle:182 } {cycle:183 } {cycle:184 } {cycle:185 } {cycle:186 } {cycle:187 } {cycle:188 } {cycle:189 } {cycle:190 } {cycle:191 } {cycle:192 } {cycle:193 } {cycle:194 } {cycle:195 } {cycle:196 } {cycle:197 } {cycle:198 } {cycle:199 } {cycle:200 } {cycle:201 } {cycle:202 } {cycle:203 } {cycle:204 } {cycle:205 } {cycle:206 } {cycle:207 } {cycle:208 } {cycle:209 } {cycle:210 } {cycle:211 } {cycle:212 } {cycle:213 } {cycle:214 } {cycle:215 } {cycle:216 } {cycle:217 } {cycle:218 } {cycle:219 } {cycle:220 } {cycle:221 } {cycle:222 } {cycle:223 } {cycle:224 } {cycle:225 } {cycle:226 } {cycle:227 } {cycle:228 } {cycle:229 } {cycle:230 } {cycle:231 } {cycle:232 } {cycle:233 } {cycle:234 } {cycle:235 } {cycle:236 } {cycle:237 } {cycle:238 } {cycle:239 } {cycle:240 } {cycle:241 } {cycle:242 } {cycle:243 } {cycle:244 } {cycle:245 } {cycle:246 } {cycle:247 } {cycle:248 } {cycle:249 } {cycle:250 } {cycle:251 } {cycle:252 } {cycle:253 } {cycle:254 } {cycle:255 } | |
/^{program} | |
jvi[y0P@a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment