AF

From Esolang
Jump to navigation Jump to search
AF
Designed by CatLooks
Appeared in 2020
Memory system Stack-based
Computational class Not Turing-complete
Reference implementation CatLooks/af
File extension(s) .af

AF is an esoteric programming language created by CatLooks. Programs written on this language consist of numbers 0, 1, 2 or 3. In each line of code, there are some couples of numbers, which form single command. Here, memory represented as byte stack.

Instructions

As program is formed of number couples, there are 16 instructions in AF.

Instruction Description
00 xx xx Pushes byte to stack
01 Pops top byte from stack
02 xx Dublicates top byte xx times
03 Shuffles 2 top bytes
10 xx ... xx Creates label
11 xx ... xx Moves to label
12 Pushes operations carry to stack
13 xx Pops 2 top bytes from stack and push result of operation.
20 xx Tests 2 top bytes; if test failed jump to 21 (nesting)
21 Mark for 20 instruction
22 Pushes random byte to stack
23 xx ... xx Sets seed for random byte generator
30 xx Outputs byte
31 xx Inputs byte. If xx > 0, then does terminal pause
32 xx xx Sets output text style
33 "text" Outputs text

Math Operations

To do math operations in AF, there is only one instruction 13 that requires operation ID. The language uses bytes as limit for numbers, therefore interpreter allows you to get operation carry after counting.

Note:

  • Operation carry changes every math operation.
  • Top byte is second operand.
  • Operation carry will not store full carry of power.
  • Divide will not produce floats.
  • While using Root, top byte is index, and bottom byte is radicand.
ID Operation Description
00 + Add
01 - Subtract
02 * Multiply
03 / Divide
10 % Modulo
11 ** Power
12 Root
13 & Binary AND
20 | Binary OR
21 ^ Binary XOR

Conditions

To make program flow more flexible, there is condition instruction 20 with Condition ID as argument.

ID Condition Description
00 == Equals
01 != Not Equals
02 > Greater
03 < Less
10 >= Greater / Equals
11 <= Less / Equals

Work of Condition in AF is very similar to languages like C, Java, Python, etc.

20 00
; some code here
21
int x = stack.length;
if (stack[x - 2] == stack[x - 1]) {
    // some code here
};

These are 2 codes that do the same work.

I/O

Output

Printing fixed text in AF is not hard. To print string, you simply type 33 and then the string itself. You can also use special characters like \x00, \n, \t and others.

33 "Hello, there!\n"

You can also pop byte from stack and print it. There are 5 ways to do it.

30 00 ; print ASCII value
30 10 ; print binary value
30 11 ; print octal value
30 12 ; print decimal value
30 13 ; print hexadecimal value

Colors

Unlike esoteric programming languages, AF supports styled text in terminal. 1. To make text colored, you need to type:

32 00 xx

Where xx represents 4-bit color. 2. To make background colored, you need to type:

32 01 xx

Where xx represents 4-bit color. 3. Other style options:

32 02 00 ; reset style
32 02 01 ; bold text
32 02 02 ; underlined text
32 02 03 ; reversed text
ID Color ID Color
00 Black 20 Dark Gray
01 Dark Blue 21 Light Blue
02 Dark Green 22 Light Green
03 Cyan 23 Aqua
10 Dark Red 30 Light Red
11 Purple 31 Pink
12 Orange 32 Yellow
13 Light Gray 33 White

Note: your terminal colors might look different!

Input

In AF, input instruction 31 pushes single character to stack. List of characters, that can be read while inputting: (list may be incomplete for numpad)

  • Letters (ASCII 41 - 5A, 61 - 7A)
  • Numbers (ASCII 30 - 39)
  • Special characters (ASCII 20 - 40, 5B - 60, 7B - 7E)
  • Letters + Control (ASCII 1 - 1A)
  • Function Keys (ASCII BB - C6)
  • Special Keys (ASCII 1B, C7 - C9, CF - D3, CB, CD)

Common input instruction looks like this:

31 00

If argument is 01 - 33 program will do terminal pause.

31 01

External Links