Brainfunk: Porovnání verzí
Skočit na navigaci
Skočit na vyhledávání
Bez shrnutí editace |
Bez shrnutí editace |
||
Řádek 3: | Řádek 3: | ||
Brainfunk is derivative of [[Brainfuck]] language with aims to: |
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. |
* 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/write program space |
||
* |
* Multiple I/O ports for additional hardware addressing |
||
* Execution of standard brainfuck code |
|||
* Enable brainfuck compatible mode |
|||
* |
* Absolute integer constants |
||
* Stack support (PUSH, POP, PEEK) |
|||
* Call subroutins with return |
|||
{| class="wikitable" |
{| class="wikitable" |
||
Řádek 28: | Řádek 30: | ||
|- |
|- |
||
| style="text-align:center"| <code><nowiki>@</nowiki></code> |
| style="text-align:center"| <code><nowiki>@</nowiki></code> |
||
| Set object selection index to 0. |
| 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 139: | Řádek 141: | ||
| style="text-align:center"| <code><nowiki>?</nowiki></code> |
| style="text-align:center"| <code><nowiki>?</nowiki></code> |
||
| @$$$$$ || Shortcut for program counter PC object |
| @$$$$$ || 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> |
| style="text-align:center"| <code><nowiki>!</nowiki></code> |
||
Řádek 163: | Řádek 171: | ||
| Copy value || <code>>[-]>[-]<<[->+>+<<]>>[-<<+>>]</code> || <code>*@~#^@*~</code> |
| Copy value || <code>>[-]>[-]<<[->+>+<<]>>[-<<+>>]</code> || <code>*@~#^@*~</code> |
||
|- |
|- |
||
| Swap |
| Swap values || <code>>[-]<<[->>+<<]>[-<+>]>[-<+>]</code> || <code>*@~#^^@*~#v*@~#v@*~#^^*@~#v@*~</code> |
||
|- |
|||
| Jump to accumulator (Moves A to PC) || || <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 || || <cope>?@~"v@'~@?~</code> |
|||
|- |
|- |
||
| Return from subroutine || || <cope>'@~"^@^^^^^^^^^?~</code> |
|||
⚫ | |||
|} |
|} |
||
Verze z 16. 7. 2012, 10:58
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/write program space
- 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 | Description |
---|---|
0 | A - Accumulator |
1 | DP - Data pointer |
2 | (DP) - Data value |
3 | IP - Interface pointer |
4 | (IP) - Interface value |
5 | PC - Program counter |
6 | PP - Program pointer |
7 | (PP) - Program value |
8 | SP - Stack pointer |
9 | (SP) - Stack value |
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 | <cope>?@~"v@'~@?~ | |
Return from subroutine | <cope>'@~"^@^^^^^^^^^?~ |