Files
lvtl-x/examples/bf.vtl
T

73 lines
2.0 KiB
Plaintext
Raw Normal View History

2026-06-22 21:54:46 +03:00
10 ?="BF-VTL BY LUXFERRE"
11 ?="CREATED in 2023, PUBLIC DOMAIN"
12 L=*-&) memory limit
13 L=L>30000*30000) hard limit to 30k
15 I=0) start pre-clearing the memory
16 :I)=0
17 I=I+1
18 #=I<L*16) repeat until reaching the memory limit
20 ?=""
21 ?="BF CODE (END WITH # OR EOF): ";
30 I=0) mem cell index
40 P=0) program index
50 M=0) mem start track
60 C=$) input cmd char
70 #=C-43<5*81) 43 + 44 , 45 - 46 .
72 #=C=60*81) 60 <
74 #=C=62*81) 62 >
76 #=C=91*81) 91 [
77 #=C=35*90) EOC with #
78 #=C=93*81) 93 ]
79 #=C=4*90) EOC with Ctrl+D
80 #=60) skip
81 :P)=C
82 P=P+1
84 #=60) input next char
90 :P)=65535) set end of code marker
91 ?=""
92 ?="EXEC"
96 M=P+1) set memory start
100 P=0) start execution
110 I=M) reset mem cell index
120 C=:P)) loop start
130 #=C=43*250) call + routine
140 #=C=45*270) call - routine
150 #=C=44*290) call , routine
160 #=C=46*310) call . routine
170 #=C=60*330) call < routine
180 #=C=62*360) call > routine
190 #=:I)=0*(C=91)*400) call [ routine if cell=0
200 #=1-(:I)=0)*(C=93)*430) call ] routine if cell>0
210 #=C=65535*240) exit code loop
220 P=P+1) go to the next cmd
230 #=120) process next cmd
240 #=15) return to the start
250 :I)=:I)+1/256*0+%) 8-bit wrap
260 #=!
270 :I)=:I)-1/256*0+%) 8-bit wrap
280 #=!
290 :I)=$) getchar
300 #=!
310 $=:I)) putchar
320 #=!
330 I=I-1) pointer decrement
340 I=I<M*(L-M)+I) wrap around mem limit
350 #=!
360 I=I+1) pointer increment
370 I=I-((I>L)*(L-M))) wrap around mem limit
380 #=!
400 D=1) set the direction to find the ]
410 X=93) set the ] code to decrease BL
415 Y=91) set the [ countercode to increase BL
420 #=450) jump to the common part
430 D=65535) set the direction to find the [
440 X=91) set the [ code to decrease BL
445 Y=93) set the ] countercode to increase BL
450 B=1) starting bracket level
460 R=P) start with current program pointer
470 R=R+D) move along the program tape
480 B=B+(:R)=Y)-(:R)=X)) update the bracket level
490 #=470*(1-(B=0))) proceed while B>0
500 P=R+1) update the program pointer
510 #=120) restart processing loop