Data update

This commit is contained in:
Ingy döt Net 2026-04-30 12:34:36 -04:00
parent 4bb20c9b71
commit cbaf4c4b64
12390 changed files with 318560 additions and 27248 deletions

View file

@ -0,0 +1,134 @@
; AutoFucck
; A AutoIt Brainfuck Interpreter
; by minx
; AutoIt Version: 3.3.8.x
; Commands:
; - DEC
; + INC
; [ LOOP START
; ] LOOP END
; . Output cell value as ASCII Chr
; , Input a ASCII char (cell value = ASCII code)
; : Ouput cell value as integer
; ; Input a Integer
; _ Output a single whitespace
; / Output an Carriage Return and Line Feed
; You can load & save .atf Files.
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <StaticCOnstants.au3>
HotKeySet("{F5}", "_Runn")
$hMain = GUICreate("Autofuck - Real Brainfuck Interpreter", 600, 525)
$mMain = GUICtrlCreateMenu("File")
Global $mCode = GUICtrlCreateMenu("Code")
$mInfo = GUICtrlCreateMenu("Info")
$mCredits = GUICtrlCreateMenuItem("Credits", $mInfo)
$mFile_New = GUICtrlCreateMenuItem("New", $mMain)
$mFile_Open = GUICtrlCreateMenuItem("Open", $mMain)
$mFile_Save = GUICtrlCreateMenuItem("Save", $mMain)
Global $mCode_Run = GUICtrlCreateMenuItem("Run [F5]", $mCode)
Global $lStatus = GUICtrlCreateLabel("++ Autofuck started...", 5, 480, 590, 20, $SS_SUNKEN)
GUICtrlSetFont(-1, Default, Default, Default, "Courier New")
$eCode = GUICtrlCreateEdit("", 5, 5, 590, 350)
GUICtrlSetFont(-1, Default, Default, Default, "Courier New")
$eConsole = GUICtrlCreateEdit("", 5, 360, 590, 115, $ES_WANTRETURN)
GUICtrlSetFont(-1, Default, Default, Default, "Courier New")
GUISetState()
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $mFile_New
GUICtrlSetData($eCode, "")
Case $mFile_Open
GUICtrlSetData($eCode, FileRead(FileOpenDialog("Open Autofuck script", @DesktopDir, "Autofuck (*.atf)")))
Case $mFile_Save
FileWrite(FileOpen(StringReplace(FileSaveDialog("Save Autofuck script", @DesktopDir, "Autofuck (*.atf)"), ".atf", "") &".atf", 2), GUICtrlRead($eCode))
Case $GUI_EVENT_CLOSE
Exit
Case $mCredits
MsgBox(0, "Autofuck", "Copyright by: "&@CRLF&"minx (autoit.de)"&@CRLF&"crashdemons (autoitscript.com)")
EndSwitch
WEnd
Func _Runn()
$Timer = TimerInit()
GUICtrlSetData($lStatus, "++ Program started")
Global $tData=DllStructCreate('BYTE[65536]')
Global $pData=0
GUICtrlSetData($eConsole, "")
Local $aError[6]=['','Unmatched closing bracket during search','Unmatched opening bracket during search','Unexpected closing bracket','Data pointer passed left boundary','Data pointer passed right boundary']
Local $sError=''
Local $i=_Run(GUICtrlRead($eCode))
If @error>=0 And @error<6 Then $sError=$aError[@error]
If StringLen($sError) Then GUICtrlSetData($eConsole, 'ERROR: '&$sError&'.'&@CRLF&'Ending Instruction Pointer: '&($i-1)&@CRLF&'Current Data Pointer: '&$pData)
GUICtrlSetData($lStatus, "++ Program terminated. Runtime: "& Round( TimerDiff($Timer) / 1000, 4) &"s")
EndFunc
Func _Run($Code,$iStart=1,$iEnd=0)
If $iEnd<1 Then $iEnd=StringLen($Code)
For $i = $iStart to $iEnd
Switch StringMid($Code, $i, 1)
Case ">"
$pData+=1
If $pData=65536 Then Return SetError(5,0,$i)
Case "<"
$pData-=1
If $pData<0 Then Return SetError(4,0,$i)
Case "+"
DllStructSetData($tData,1,DllStructGetData($tData,1,$pData+1)+1,$pData+1)
Case "-"
DllStructSetData($tData,1,DllStructGetData($tData,1,$pData+1)-1,$pData+1)
Case ":"
GUICtrlSetData($eConsole, GUICtrlRead($eConsole) & (DllStructGetData($tData,1,$pData+1)))
Case "."
GUICtrlSetData($eConsole, GUICtrlRead($eConsole) & Chr(DllStructGetData($tData,1,$pData+1)))
Case ";"
Local $cIn=StringMid(InputBox('Autofuck','Enter Number'),1)
DllStructSetData($tData,1,Number($cIn),$pData+1)
Case ","
Local $cIn=StringMid(InputBox('Autofuck','Enter one ASCII character'),1,1)
DllStructSetData($tData,1,Asc($cIn),$pData+1)
Case "["
Local $iStartSub=$i
Local $iEndSub=_MatchBracket($Code,$i,$iEnd)
If @error<>0 Then Return SetError(@error,0,$iEndSub)
While DllStructGetData($tData,1,$pData+1)<>0
Local $iRet=_Run($Code,$iStartSub+1,$iEndSub-1)
If @error<>0 Then Return SetError(@error,0,$iRet)
WEnd
$i=$iEndSub
Case ']'
Return SetError(3,0,$i)
Case "_"
GUICtrlSetData($eConsole, GUICtrlRead($eConsole)&" ")
Case "/"
GUICtrlSetData($eConsole, GUICtrlRead($eConsole)&@CRLF)
EndSwitch
Next
Return 0
EndFunc
Func _MatchBracket($Code,$iStart=1,$iEnd=0)
If $iEnd<1 Then $iEnd=StringLen($Code)
Local $Open=0
For $i=$iStart To $iEnd
Switch StringMid($Code,$i,1)
Case '['
$Open+=1
Case ']'
$Open-=1
If $Open=0 Then Return $i
If $Open<0 Then Return SetError(1,0,$i)
EndSwitch
Next
If $Open>0 Then Return SetError(2,0,$i)
Return 0
EndFunc

View file

@ -0,0 +1,34 @@
(do ;;; Simple BF interpreter, based on the Lua sample: "Simple meta-implementation using load"
;;; reads the BF code from stdin, builds an equivalent Pluto program and executes it
(local bf-op { ">" "ptr = ptr + 1"
"<" "ptr = ptr - 1"
"+" "mem[ptr] = mem[ptr] + 1"
"-" "mem[ptr] = mem[ptr] - 1"
"[" "while mem[ptr] ~= 0 do"
"]" "end"
"." "io.write(string.char(mem[ptr]))"
"," "mem[ptr] = string.byte(io.read(1) or \"\\0\")"
}
)
(var bf-program (.. "local mem = setmetatable({}, { __index = function() return 0 end })\n"
"local ptr = 1\n"
)
)
(each [line (io.lines)]
(for [p 1 (length line)]
(local op (. bf-op (line:sub p p)))
(when op
(set bf-program (.. bf-program op "\n"))
)
)
)
(local (bf-code msg) (load bf-program))
(if bf-code
(bf-code)
;else
(error msg)
)
)

View file

@ -0,0 +1,74 @@
use fmt;
use fs;
use io;
use os;
export fn main() void = {
if (len(os::args) != 2) {
fmt::print("Please provide a parameter pointing to a brain**** file.\n")!;
return;
};
let program = slurp(os::args[1])!;
let tape: [30000]u8 = [0...];
let tp: u16 = 0;
defer free(program);
let matches_k: []size = [];
let matches_v: []size = [];
defer free(matches_k);
defer free(matches_v);
for (let pp: size = 0; pp < len(program); pp += 1) {
switch (program[pp]) {
case '>' => tp += 1;
case '<' => tp -= 1;
case '+' => tape[tp] += 1;
case '-' => tape[tp] -= 1;
case '.' => io::write(os::stdout, tape[tp..tp+1])!;
case ',' => io::read(os::stdin, tape[tp..tp+1])!;
case '[' => if (tape[tp] == 0) pp = find_match(pp, program, matches_k, matches_v)!;
case ']' => if (tape[tp] != 0) pp = find_match(pp, program, matches_k, matches_v)!;
case => continue;
};
};
};
fn find_match(pos: size, program: []u8, matches_k: []size, matches_v: []size) (size | !void) = {
for (let i: u16 = 0; i < len(matches_k); i += 1)
if (pos == matches_k[i])
return matches_v[i];
let r = pos;
switch (program[pos]) {
case '[' => {
r += 1;
for (let level = 1; level > 0; r += 1) {
switch (program[r]) {
case '[' => level += 1;
case ']' => level -= 1;
case => continue;
};
};
};
case ']' => {
r -= 1;
for (let level = 1; level > 0; r -= 1) {
switch (program[r]) {
case ']' => level += 1;
case '[' => level -= 1;
case => continue;
};
};
};
case => return;
};
append(matches_k, pos)!;
append(matches_v, r)!;
return r;
};
fn slurp(filename: str) ([]u8 | fs::error | io::error) = {
const file = os::open(filename)?;
defer io::close(file)!;
return io::drain(file)?;
};

View file

@ -1,24 +1,22 @@
local funs = {
['>'] = 'ptr = ptr + 1; ',
['<'] = 'ptr = ptr - 1; ',
['+'] = 'mem[ptr] = mem[ptr] + 1; ',
['-'] = 'mem[ptr] = mem[ptr] - 1; ',
['['] = 'while mem[ptr] ~= 0 do ',
[']'] = 'end; ',
['.'] = 'io.write(string.char(mem[ptr])); ',
[','] = 'mem[ptr] = (io.read(1) or "\\0"):byte(); ',
local repl = {
['>'] = 'ptr = ptr + 1',
['<'] = 'ptr = ptr - 1',
['+'] = 'mem[ptr] = mem[ptr] + 1',
['-'] = 'mem[ptr] = mem[ptr] - 1',
['['] = 'while mem[ptr] ~= 0 do',
[']'] = 'end',
['.'] = 'io.write(string.char(mem[ptr]))',
[','] = 'mem[ptr] = (io.read(1) or "\\0"):byte()',
}
local prog = [[
local prog = {[[
local mem = setmetatable({}, { __index = function() return 0 end})
local ptr = 1
]]
]]}
local source = io.read('*all')
for p = 1, #source do
local snippet = funs[source:sub(p,p)]
if snippet then prog = prog .. snippet end
local source, i = io.read('*all'), 1
for char in source:gmatch"[<>+.,%[%]%-]" do
i, prog[i] = i+1, repl[char]
end
load(prog)()
load( table.concat(prog, " ") )()

View file

@ -0,0 +1,27 @@
do -- Simple BF interpreter, based on the Lua sample: "Simple meta-implementation using load"
-- reads the BF code from stdin, builds an equivalent Pluto program and executes it
local bfOp <const> = { ['>'] = 'ptr += 1 '
, ['<'] = 'ptr -= 1 '
, ['+'] = 'mem[ptr] += 1 '
, ['-'] = 'mem[ptr] -= 1 '
, ['['] = 'while mem[ptr] != 0 do '
, [']'] = 'end '
, ['.'] = 'io.write(string.char(mem[ptr])) '
, [','] = 'mem[ptr] = string.byte(io.read(1) ?? "\\0") '
};
local bfProgram = "local mem = setmetatable({}, { __index = function() return 0 end })\n"
.. "local ptr = 1\n"
for line in io.lines() do
for p = 1, # line do
local snippet = bfOp[ line[ p ] ]
if snippet then bfProgram ..= snippet .. "\n" end
end
end
local bfCode, msg = load( bfProgram )
if bfCode then bfCode() else error( msg ) end
end

View file

@ -0,0 +1,71 @@
import sys
from collections import deque
from itertools import repeat
def interpret(instructions: str, memory_size: int, eof: int | None = None) -> None:
jump_table: dict[int, int] = {}
def jump(ip: int) -> int:
if ip in jump_table:
return jump_table[ip]
if instructions[ip] == "[":
depth = 0
for i in range(ip, len(instructions)):
if instructions[i] == "[":
depth += 1
elif instructions[i] == "]":
depth -= 1
if depth == 0:
jump_table[ip] = i
jump_table[i] = ip
return i
elif instructions[ip] == "]":
depth = 0
for i in range(ip, -1, -1):
if instructions[i] == "]":
depth += 1
elif instructions[i] == "[":
depth -= 1
if depth == 0:
jump_table[ip] = i
jump_table[i] = ip
return i
raise Exception("unbalanced brackets")
tape = deque(repeat(0, memory_size), memory_size)
ip = 0
while ip < len(instructions):
op = instructions[ip]
if op == ">":
tape.rotate(-1)
elif op == "<":
tape.rotate()
elif op == "+":
tape[0] += 1
elif op == "-":
tape[0] -= 1
elif op == ",":
if ch := sys.stdin.read(1):
tape[0] = ord(ch)
elif eof is not None:
tape[0] = eof
elif op == ".":
sys.stdout.write(chr(tape[0]))
elif op == "[" and not tape[0]:
ip = jump(ip)
elif op == "]" and tape[0]:
ip = jump(ip)
ip += 1
if __name__ == "__main__":
prog = "++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>."
interpret(prog, 10)

View file

@ -0,0 +1,83 @@
REBOL [Title: "Brainfuck interpreter"]
tape: make object! [
pos: 1
data: [0]
inc: does [
data/:pos: data/:pos + 1
]
dec: does [
data/:pos: data/:pos - 1
]
advance: does [
pos: pos + 1
if (length? data) <= pos [
append data 0
]
]
devance: does [
if pos > 1 [
pos: pos - 1
]
]
get: does [
data/:pos
]
]
brainfuck: make object! [
data: string!
code: ""
init: func [instr] [
self/data: instr
]
bracket-map: func [text] [
leftstack: []
bm: make map! []
pc: 1
for i 1 (length? text) 1 [
c: text/:i
if not find "+-<>[].," c [
continue
]
if c == #"[" [
append leftstack pc
]
if c == #"]" & ((length? leftstack) > 0) [
left: last leftstack
take/last leftstack
append bm reduce [left pc]
append bm reduce [pc left]
]
append code c
pc: pc + 1
]
return bm
]
run: function [] [
pc: 0
tp: make tape []
bm: bracket-map self/data
while [pc <= (length? code)] [
switch/default code/:pc [
#"+" [tp/inc]
#"-" [tp/dec]
#">" [tp/advance]
#"<" [tp/devance]
#"[" [if tp/get == 0 [
pc: bm/:pc
]]
#"]" [if tp/get != 0 [
pc: bm/:pc
]]
#"." [prin to-string to-char tp/get]
] []
pc: pc + 1
]
print newline
]
]
bf: make brainfuck []
bf/init input
bf/run

View file

@ -0,0 +1,40 @@
Rebol [
title: "Rosetta code: Execute Brain****"
file: %Execute_Brainfuck.r3
url: https://rosettacode.org/wiki/Execute_Brain****
note: "Commented original Red version"
]
brainfuck: function [
"Brainfuck interpreter - executes a Brainfuck program string"
prog [string!]
][
; Initialize 30'000 memory cells (standard Brainfuck tape size)
cells: make string! size: 30000
append/dup cells null size ;; Fill all cells with null (ASCII 0)
;; Parse and execute each Brainfuck instruction
parse prog [
some [
#">" (cells: next cells) ;; Move tape pointer right
| #"<" (cells: back cells) ;; Move tape pointer left
| #"+" (cells/1: cells/1 + 1) ;; Increment current cell
| #"-" (cells/1: cells/1 - 1) ;; Decrement current cell
| #"." (prin cells/1) ;; Output current cell as character
| #"," (cells/1: first input "") ;; Read one character of input into current cell
| #"[" [if (cells/1 = null) thru #"]" | none] ;; If current cell is 0, jump past matching "]"
| #"]" [
;; If current cell is non-zero, jump back to matching "["
pos: if (cells/1 <> null)
(pos: find/reverse pos #"[") :pos ;; Seek backward to find "[", then jump to it
| none ;; Otherwise, do nothing and continue
]
| skip ;; Ignore any unrecognized characters
]
]
]
brainfuck {
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.
>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
}

View file

@ -0,0 +1,31 @@
Red []
bf: function [prog [string!]][
size: 30000
cells: make string! size
append/dup cells null size
parse prog [
some [
">" (cells: next cells)
| "<" (cells: back cells)
| "+" (cells/1: cells/1 + 1)
| "-" (cells/1: cells/1 - 1)
| "." (prin cells/1)
| "," (cells/1: first input "")
| "[" [if (cells/1 = null) thru "]" | none]
| "]" [
pos: if (cells/1 <> null)
(pos: find/reverse pos #"[") :pos
| none
]
| skip
]
]
]
; This code will print a Hello World! message
bf {
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.
>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
}

View file

@ -0,0 +1,76 @@
'Execute BrainFuck
'VBScript Implementation
'The Main Interpreter
Function BFInpt(s, sp, d, dp, i, ip, o)
While sp < Len(s)
Select Case Mid(s, sp + 1, 1)
Case "+"
newd = Asc(d(dp)) + 1
If newd > 255 Then newd = newd Mod 256 'To take account of values over 255
d(dp) = Chr(newd)
Case "-"
newd = Asc(d(dp)) - 1
If newd < 0 Then newd = (newd Mod 256) + 256 'To take account of negative values
d(dp) = Chr(newd)
Case ">"
dp = dp + 1
If dp > UBound(d) Then
ReDim Preserve d(UBound(d) + 1)
d(dp) = Chr(0)
End If
Case "<"
dp = dp - 1
Case "."
o = o & d(dp)
Case ","
If ip = Len(i) Then d(dp) = Chr(0) Else ip = ip + 1 : d(dp) = Mid(i, ip, 1)
Case "["
If Asc(d(dp)) = 0 Then
bracket = 1
While bracket And sp < Len(s)
sp = sp + 1
If Mid(s, sp + 1, 1) = "[" Then
bracket = bracket + 1
ElseIf Mid(s, sp + 1, 1) = "]" Then
bracket = bracket - 1
End If
WEnd
Else
pos = sp - 1
sp = sp + 1
If BFInpt(s, sp, d, dp, i, ip, o) Then sp = pos
End If
Case "]"
BFInpt = Asc(d(dp)) <> 0
Exit Function
End Select
sp = sp + 1
WEnd
End Function
'This Prepares the Intepreter
Function BFuck(source, input)
Dim data() : ReDim data(0)
data(0) = Chr(0)
DataPtr = 0
SrcPtr = 0
InputPtr = 0
output = ""
BFInpt source , SrcPtr , _
data , DataPtr , _
input , InputPtr , _
output
BFuck = output
End Function
'Sample Run
'The input is a string. The first character will be scanned by the first comma
'in the code, the next character will be scanned by the next comma, and so on.
code = ">++++++++[<+++++++++>-]<.>>+>+>++>[-]+<[>[->+<<++++>]<<]>.+++++++..+++.>" & _
">+++++++.<<<[[-]<[-]>]<+++++++++++++++.>>.+++.------.--------.>>+.>++++."
inpstr = ""
WScript.StdOut.Write BFuck(code, inpstr)

View file

@ -0,0 +1,62 @@
void main() {
string code = "++++++++++[>+>+++>++++>+++++++>++++++++>+++++++++>++
++++++++>+++++++++++>++++++++++++<<<<<<<<<-]>>>>+.>>>
>+..<.<++++++++.>>>+.<<+.<<<<++++.<++.>>>+++++++.>>>.+++.
<+++++++.--------.<<<<<+.<+++.---.";
bf(10, code);
}
void bf(int len, string input) {
char[] data = new char[len];
int data_pointer = 0;
for (int i = 0; i < input.length; i++) {
switch (input[i]) {
case '>':
data_pointer++;
break;
case '<':
data_pointer--;
break;
case '+':
data[data_pointer]++;
break;
case '-':
data[data_pointer]--;
break;
case '.':
stdout.printf("%c", data[data_pointer]);
break;
case ',':
stdin.scanf("%c", &data[data_pointer]);
break;
case '[':
if (data[data_pointer] == 0) {
for (int nc = 1; nc > 0;) {
i++;
if (input[i] == '[') {
nc++;
}
else if (input[i] == ']') {
nc--;
}
}
}
break;
case ']':
if (data[data_pointer] != 0) {
for (int nc = 1; nc > 0;) {
i--;
if (input[i] == ']') {
nc++;
}
else if (input[i] == '[') {
nc--;
}
}
}
break;
}
}
}

View file

@ -0,0 +1,13 @@
"+++++++++++[>++++++>+++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>." ##code
?£ƛ
:'+=["D:hi$h$≜"| ##'+'
:'-=["D:hi$h$≜"| ##'-'
:'>=["0J:h0$≜"| ##'>', auto-extends tape
:'<=[":h0$≜"| ##'<'
:'[=["{Dhi|"| ##'['
:']=['}| ##']'
:'.=["DhiO#,"| ##'.'
":h0¥ᑂ$£O≜" ##','
]”
1 0; ## initial tape T. T[0] is the pointer
$ᴥ ##run the code