Brainfunk: Porovnání verzí
Skočit na navigaci
Skočit na vyhledávání
Bez shrnutí editace |
|||
(Není zobrazeno 6 mezilehlých verzí od stejného uživatele.) | |||
Řádek 1: | Řádek 1: | ||
==Overview== |
==Overview== |
||
Brainfunk is derivative of [ |
Brainfunk is derivative of [https://esolangs.org/wiki/Brainfuck Brainfuck] language with aims to: |
||
* Unify cell pointer and cell value increment and decrement operations to single + and - operations. Remove > and < operations. |
* Unify cell pointer and cell value increment and decrement operations to single + and - operations. Remove > and < operations. |
||
* |
* Fast copy instruction for instant data transfer usable between all address spaces. |
||
* |
* Macro definition for custom symbol definition and code reduction |
||
* |
* Read program space |
||
* Multiple data pointers |
|||
* |
* Multiple I/O ports for additional hardware addressing |
||
* Enable brainfuck compatible mode |
|||
* Execution of standard brainfuck code |
|||
* |
* Absolute integer constants |
||
* Stack support (PUSH, POP, PEEK) |
|||
* Call subroutins with return |
|||
==Commands== |
|||
{| class="wikitable" |
{| class="wikitable" |
||
|+ Base commands |
|||
! Command |
! Command |
||
! Description |
! Description |
||
Řádek 18: | Řádek 21: | ||
| Increment selected object |
| Increment selected object |
||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>v</nowiki></code> |
||
| Decrement selected object |
| Decrement selected object |
||
|- |
|- |
||
Řádek 27: | Řádek 30: | ||
| Jump back to the matching <code>(</code> if the object value is nonzero |
| Jump back to the matching <code>(</code> if the object value is nonzero |
||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>@</nowiki></code> |
||
| |
| Save object index as previous state. Set new object selection index to 0. Index 0 means accumulator. |
||
|- |
|- |
||
| style="text-align:center"| <code><nowiki>$</nowiki></code> |
| style="text-align:center"| <code><nowiki>$</nowiki></code> |
||
Řádek 45: | Řádek 48: | ||
{| class="wikitable" |
{| class="wikitable" |
||
|+ Object table |
|+ Object table |
||
! Index !! Short name || Name !! Area |
|||
! Index |
|||
⚫ | |||
|- |
|- |
||
| 0 || A |
| 0 || A || Accumulator || Registers |
||
|- |
|- |
||
| 1 || DP |
| 1 || DP || Data pointer || Registers |
||
|- |
|- |
||
| 2 || (DP) |
| 2 || (DP) || Data value || Data memory |
||
|- |
|- |
||
| 3 || IP |
| 3 || IP || Interface pointer || Registers |
||
|- |
|- |
||
| 4 || (IP) |
| 4 || (IP) || Interface value || I/O ports |
||
|- |
|- |
||
| 5 || PC |
| 5 || PC || Program counter || Registers |
||
|- |
|- |
||
| 6 || PP |
| 6 || PP || Program pointer || Registers |
||
|- |
|- |
||
| 7 || (PP) |
| 7 || (PP) || Program value || Program memory |
||
|- |
|- |
||
| 8 || SP |
| 8 || SP || Stack pointer || Registers |
||
|- |
|- |
||
| 9 || (SP) |
| 9 || (SP) || Stack value || Data memory |
||
⚫ | |||
| 10 || DP2 || Data pointer 2 || Registers |
|||
⚫ | |||
| 11 || (DP2) || Data value 2 || Data memory |
|||
|} |
|} |
||
Řádek 76: | Řádek 82: | ||
| 0 || Null |
| 0 || Null |
||
|- |
|- |
||
| 1 || Standard |
| 1 || Standard output |
||
|- |
|- |
||
| 2 || Standard |
| 2 || Standard input |
||
|- |
|- |
||
| 3 || Delay [ms] |
| 3 || Delay [ms] |
||
Řádek 85: | Řádek 91: | ||
|} |
|} |
||
==Brainfuck compatibility code== |
|||
==Macros== |
|||
These are defined as macros for easy brainfuck code inclusion. |
|||
{| class="wikitable" |
{| class="wikitable" |
||
! Symbol |
|||
! Brainfuck |
|||
! Code |
|||
! Brainfunk |
|||
|- |
|- |
||
| style="text-align:center"| <code><nowiki>+</nowiki></code> |
| style="text-align:center"| <code><nowiki>+</nowiki></code> |
||
| |
| @$$^ |
||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>-</nowiki></code> |
||
| @$$v |
|||
⚫ | |||
|- |
|- |
||
| style="text-align:center"| <code> |
| style="text-align:center"| <code><</code> |
||
| @$^ |
|||
| Jump past the matching <code>)</code> if the object value is zero |
|||
|- |
|- |
||
| style="text-align:center"| <code> |
| style="text-align:center"| <code>></code> |
||
| @$v |
|||
| Jump back to the matching <code>(</code> if the object value is nonzero |
|||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>[</nowiki></code> |
||
| @$$( |
|||
| No operation, clear object selection index |
|||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>]</nowiki></code> |
||
| @$$) |
|||
| Increment object selection index |
|||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>,</nowiki></code> |
||
| @$$$(v)^^@$$@$$$$~ |
|||
| Copy value from previous selected object to current selected object |
|||
|- |
|- |
||
| style="text-align:center"| <code><nowiki> |
| style="text-align:center"| <code><nowiki>.</nowiki></code> |
||
| @$$$(v)^@$$$$@$$~ |
|||
| Start macro, first symbol to the right is new defined symbol |
|||
|} |
|||
==Aditional macros== |
|||
{| class="wikitable" |
|||
! Symbol |
|||
! Code |
|||
⚫ | |||
|- |
|- |
||
| style="text-align:center"| <code> |
| style="text-align:center"| <code><nowiki>#</nowiki></code> |
||
| @$ || Shortcut for data pointer DP object |
|||
| End macro started by : |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>*</nowiki></code> |
|||
| @$$ || Shortcut for data value (DP) object |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>&</nowiki></code> |
|||
| @$$$ || Shortcut for interface address IP object |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>%</nowiki></code> |
|||
| @$$$$ || Shortcut for interface value (IP) object |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>?</nowiki></code> |
|||
| @$$$$$ || Shortcut for program counter PC object |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>"</nowiki></code> |
|||
| @$$$$$$$$ || Shortcut for stack pointer SP object |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>'</nowiki></code> |
|||
| @$$$$$$$$$ || Shortcut for stack top value (SP) object |
|||
|- |
|||
| style="text-align:center"| <code><nowiki>!</nowiki></code> |
|||
⚫ | |||
|} |
|} |
||
== |
==Sample code== |
||
{| class="wikitable" |
{| class="wikitable" |
||
Řádek 126: | Řádek 163: | ||
! Brainfunk |
! Brainfunk |
||
|- |
|- |
||
| Increment |
| Increment accumulator || || <code><nowiki>@^</nowiki></code> |
||
|- |
|||
| Decrement accumulator || || <code><nowiki>@v</nowiki></code> |
|||
|- |
|||
⚫ | |||
|- |
|||
| Clear accumulator || || <code>@!</code> |
|||
|- |
|||
⚫ | |||
|- |
|- |
||
| |
| Copy value || <code>>[-]>[-]<<[->+>+<<]>>[-<<+>>]</code> || <code>*@~#^@*~</code> |
||
|- |
|- |
||
| |
| Swap values || <code>>[-]<<[->>+<<]>[-<+>]>[-<+>]</code> || <code>*@~#^^@*~#v*@~#v@*~#^^*@~#v@*~</code> |
||
|- |
|- |
||
| |
| Jump to accumulator (Moves A to PC) || || <code>@?~</code> |
||
⚫ | |||
| Write cell to output || <code>.</code> || <code>#$%</code> |
|||
⚫ | |||
⚫ | |||
|- |
|- |
||
| |
| Halt program (Decrement PC) || || <code>?v</code> |
||
|- |
|- |
||
| |
| Push A to stack || || <code>"v@'~</code> |
||
|- |
|- |
||
| |
| Pop A from stack|| || <code>'@~"^</code> |
||
|- |
|- |
||
| |
| Peek top stack item to A || || <code>'@~</code> |
||
|- |
|- |
||
| |
| Remove top stack item || || <code>"^</code> |
||
|- |
|- |
||
| |
| Call subroutine || || <code>?@~"v@'~@?~</code> |
||
|- |
|- |
||
| Return from subroutine || || <code>'@~"^@^^^^^^^^^?~</code> |
|||
⚫ | |||
|} |
|} |
||
Aktuální verze z 15. 1. 2024, 20:13
Overview
Brainfunk is derivative of Brainfuck language with aims to:
- Unify cell pointer and cell value increment and decrement operations to single + and - operations. Remove > and < operations.
- Fast copy instruction for instant data transfer usable between all address spaces.
- Macro definition for custom symbol definition and code reduction
- Read program space
- Multiple data pointers
- Multiple I/O ports for additional hardware addressing
- Execution of standard brainfuck code
- Absolute integer constants
- Stack support (PUSH, POP, PEEK)
- Call subroutins with return
Command | Description |
---|---|
^
|
Increment selected object |
v
|
Decrement selected object |
(
|
Jump past the matching ) if the object value is zero
|
)
|
Jump back to the matching ( if the object value is nonzero
|
@
|
Save object index as previous state. Set new object selection index to 0. Index 0 means accumulator. |
$
|
Increment object selection index |
~
|
Copy value from previous selected object to current selected object |
:
|
Start macro, first symbol to the right is new defined symbol |
;
|
End macro started by : |
Index | Short name | Name | Area |
---|---|---|---|
0 | A | Accumulator | Registers |
1 | DP | Data pointer | Registers |
2 | (DP) | Data value | Data memory |
3 | IP | Interface pointer | Registers |
4 | (IP) | Interface value | I/O ports |
5 | PC | Program counter | Registers |
6 | PP | Program pointer | Registers |
7 | (PP) | Program value | Program memory |
8 | SP | Stack pointer | Registers |
9 | (SP) | Stack value | Data memory |
10 | DP2 | Data pointer 2 | Registers |
11 | (DP2) | Data value 2 | Data memory |
Address | Description |
---|---|
0 | Null |
1 | Standard output |
2 | Standard input |
3 | Delay [ms] |
4 | Sound [Hz] |
Brainfuck compatibility code
These are defined as macros for easy brainfuck code inclusion.
Symbol | Code |
---|---|
+
|
@$$^ |
-
|
@$$v |
<
|
@$^ |
>
|
@$v |
[
|
@$$( |
]
|
@$$) |
,
|
@$$$(v)^^@$$@$$$$~ |
.
|
@$$$(v)^@$$$$@$$~ |
Aditional macros
Symbol | Code | Description |
---|---|---|
#
|
@$ | Shortcut for data pointer DP object |
*
|
@$$ | Shortcut for data value (DP) object |
&
|
@$$$ | Shortcut for interface address IP object |
%
|
@$$$$ | Shortcut for interface value (IP) object |
?
|
@$$$$$ | Shortcut for program counter PC object |
"
|
@$$$$$$$$ | Shortcut for stack pointer SP object |
'
|
@$$$$$$$$$ | Shortcut for stack top value (SP) object |
!
|
(v) | Clear selected object. |
Sample code
Description | Brainfuck | Brainfunk |
---|---|---|
Increment accumulator | @^
| |
Decrement accumulator | @v
| |
Cat | ,[.,] |
,[.,]
|
Clear accumulator | @!
| |
Move value | >[-]<[->+<] |
*@~*!#^@*~
|
Copy value | >[-]>[-]<<[->+>+<<]>>[-<<+>>] |
*@~#^@*~
|
Swap values | >[-]<<[->>+<<]>[-<+>]>[-<+>] |
*@~#^^@*~#v*@~#v@*~#^^*@~#v@*~
|
Jump to accumulator (Moves A to PC) | @?~
| |
Halt program (Decrement PC) | ?v
| |
Push A to stack | "v@'~
| |
Pop A from stack | '@~"^
| |
Peek top stack item to A | '@~
| |
Remove top stack item | "^
| |
Call subroutine | ?@~"v@'~@?~
| |
Return from subroutine | '@~"^@^^^^^^^^^?~
|