Brainfunk: Porovnání verzí
Skočit na navigaci
Skočit na vyhledávání
Bez shrnutí editace |
Bez shrnutí editace |
||
Řádek 10: | Řádek 10: | ||
* Allow absolute integer constants |
* Allow absolute integer constants |
||
==Commands== |
|||
{| class="wikitable" |
{| class="wikitable" |
||
|+ Base commands |
|||
! Command |
! Command |
||
! Description |
! Description |
||
Řádek 18: | Řádek 18: | ||
| 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 27: | ||
| 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> |
||
| |
| Set object selection index to 0. This is index means accumulator, |
||
|- |
|- |
||
| style="text-align:center"| <code><nowiki>$</nowiki></code> |
| style="text-align:center"| <code><nowiki>$</nowiki></code> |
||
Řádek 76: | Řádek 76: | ||
| 0 || Null |
| 0 || Null |
||
|- |
|- |
||
| 1 || Standard |
| 1 || Standard output |
||
|- |
|- |
||
| 2 || Standard |
| 2 || Standard input |
||
|- |
|- |
||
| 3 || Delay [ms] |
| 3 || Delay [ms] |
||
Řádek 85: | Řádek 85: | ||
|} |
|} |
||
==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 |
|||
⚫ | |||
⚫ | |||
| End macro started by : |
|||
|} |
|} |
||
== |
==Aditional macros== |
||
{| class="wikitable" |
{| class="wikitable" |
||
! Symbol |
|||
! Code |
|||
! Description |
! Description |
||
! Brainfuck |
|||
! Brainfunk |
|||
|- |
|- |
||
| |
| style="text-align:center"| <code><nowiki>#</nowiki></code> |
||
| @$ || Shortcut for data pointer DP object |
|||
|- |
|- |
||
| |
| 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 |
|||
⚫ | |||
⚫ | |||
| @$$$$ || 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> |
|||
⚫ | |||
|} |
|||
==Sample code== |
|||
{| class="wikitable" |
|||
! Description |
|||
! Code |
|||
|- |
|- |
||
| |
| Increment accumulator || <code><nowiki>@^</nowiki></code> |
||
⚫ | |||
| Write cell to output || <code>.</code> || <code>#$%</code> |
|||
⚫ | |||
| Read input to cell || <code>,</code> || <code>$#%</code> |
|||
|- |
|- |
||
| |
| Decrement accumulator || code><nowiki>@v</nowiki></code> |
||
|- |
|- |
||
| |
| Cat || <code>,[.,]</code> || <code>,[.,]</code> |
||
|- |
|- |
||
| |
| Clear accumulator || || <code>@!</code> |
||
|- |
|- |
||
| |
| Move value || <code>>[-]<[->+<]</code> || <code>*@~*!#^@*~</code> |
||
|- |
|- |
||
| |
| Copy value || <code>>[-]>[-]<<[->+>+<<]>>[-<<+>>]</code> || <code>*@~#^@*~</code> |
||
|- |
|- |
||
| |
| Swap value || <code>>[-]<<[->>+<<]>[-<+>]>[-<+>]</code> || <code>*@~#^^@*~#v*@~#v@*~#^^*@~#v@*~</code> |
||
|- |
|- |
||
| |
|||
| Swap value || <code>>[-]<<[->>+<<]>[-<+>]>[-<+>]</code> || <code>#@%&++@#%&-#@%&-@#%&++#@%&-@#%</code> |
|||
|} |
|} |
||
Verze z 16. 7. 2012, 10:27
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.
- Introduce fast copy instruction usable between all address spaces.
- Allow macro definition for custom symbol definition and code reduction
- Allow to read/write program space
- Support multiple I/O ports for additional hardware addressing
- Enable brainfuck compatible mode
- Allow absolute integer constants
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
|
@
|
Set object selection index to 0. This is index 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 |
!
|
(v) | Clear selected object. |
Sample code
Description | Code | |
---|---|---|
Increment accumulator | @^
| |
Decrement accumulator | code>@v | |
Cat | ,[.,] |
,[.,]
|
Clear accumulator | @!
| |
Move value | >[-]<[->+<] |
*@~*!#^@*~
|
Copy value | >[-]>[-]<<[->+>+<<]>>[-<<+>>] |
*@~#^@*~
|
Swap value | >[-]<<[->>+<<]>[-<+>]>[-<+>] |
*@~#^^@*~#v*@~#v@*~#^^*@~#v@*~
|