CraftyFunge

From Esolang
Jump to navigation Jump to search
CraftyFunge
Paradigm(s) imperative
Designed by User:Kequals
Appeared in 2022
Memory system stack-based with register
Dimensions three-dimensional
Computational class Turing complete
Reference implementation Github
Influenced by Befunge
File extension(s) .nbt

CraftyFunge is a 3-dimensional esoteric programming language written by placing Minecraft blocks. Programs can be run directly in Minecraft or with the external interpreter. The external interpreter accepts programs exported from structure blocks. CraftyFunge is executable in vanilla Minecraft using a world with an embedded data pack.

Language overview

Much like other fungeoids, the instruction Pointer (IP) has no fixed direction, and can be redirected in any of 6 possible ways. Each block is treated as one instruction. There is no wraparound, and when executed in Minecraft the IP will continue on until it reaches an unloaded chunk. When executed with the external interpreter it will raise an exception.

For storage, CraftyFunge uses both a stack and variables. Commands read and write to the stack, but for convenience there are commands to read and write to variables. Additionally, as a way of storing data or modifying its own code, CraftyFunge can get and set blocks.

When run in Minecraft, the stack has a maximum length of 128, and there are 128 possible variables from indices 0-127. Further pushes to the stack will overwrite earlier values, and attempting to access indices outside of the allowed range will truncate to the nearest value in range. Each cell is a 32-bit integer with a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647. Attempting to go past these limits will result in wraparound. These limits are removed for the external interpreter.

Instructions

Instruction Block Name Description
Start Command Block Start the program, setting the IP to the direction the command block is pointing.
End Bedrock End the program.
Change Direction Piston Set the IP direction to wherever the piston’s head is pointing.
Random Direction Magenta Glazed Terracotta Set a random IP direction.
Skip Sea Lantern Jump over the next block.
Conditional Skip Redstone Lamp Pop one value off the stack and jump over the next block if zero.
Push 0-9 Concrete Pushes 0-9 to the stack, depending on the block’s color.
Push 10-90 Terracotta Pushes 10-90 to the stack, depending on the block’s color.
Push 100-900 Wool Pushes 100-900 to the stack, depending on the block’s color.
Push 1,000-9,000 Stained Glass Pushes 1000-9000 to the stack, depending on the block’s color.
Push 1,000,000 to 9,000,000 Shulker Box Pushes 1,000,000-9,000,000 to the stack, depending on the block’s color.
Add Iron Block Pop a, b. Push b + a.
Subtract Gold Block Pop a, b. Push b - a.
Multiply Diamond Block Pop a, b. Push b * a.
Integer Divide Emerald Block Pop a, b. Push b / a. Uses integer division.
Modulus Lapis Lazuli Block Pop a, b. Push b % a.
Exponent Netherite Block Pop a, b. Push b^a. Negative exponents will truncate the result to 0.
Negate Coal Block Negates the top of the stack.
Not Obsidian Pop a. Push 1 if a is 0, else push 0.
Greater Than Mossy Stone Bricks Pop a, b. Push 1 if b > a, else push 0.
Less Than Cracked Stone Bricks Pop a, b. Push 1 if b < a, else push 0.
If Observer Pop one value off the stack. If it is 0, change the IP direction to the back of the block, else change the IP direction to the front.
Duplicate Crafting Table Duplicate the top value of the stack.
Pop Magma Block Discard the top value of the stack.
Clear TNT Reset the stack to empty.
Swap Pumpkin Swap the top two elements of the stack.
Rotate Melon Pop a. Rotate the top |a|+1 elements of the stack. If a is positive, make the bottom element on the top. If a is negative, make the top element on the bottom.
Push Length Ancient Debris Push the length of the stack onto the stack. Trailing zero values aren’t counted towards the length.
Numeric Output Dispenser Pop and print the top of the stack as a number, followed by a space.
Text Output Dropper Pop and print the top of the stack as an ASCII character.
Newline Output Bookshelf Prints a newline.
Raise Error Note Block Raises an error and halts the program.
Numeric Input Chest Input a number and push to the stack. Pushes -1 upon EOF or invalid input.
Text Input Ender chest Input one character and push its ASCII value to the stack. Pushes -1 upon EOF.
Push Next Block Value Jukebox Read the next block’s value in the direction of the IP, push it to the stack, then skip over that block. If the value is invalid, does nothing.
Get Block Slime block Pop z, y, x. Get the block’s value at (x, y, z) and push it onto the stack. If the value is invalid, does nothing.
Set Block Honey block Pop z, y, x, B. Set the block at (x, y, z) to the block corresponding to the value of B. If the value is invalid, does nothing.
Get Variable Red Nether Bricks Pop i. Push the value of the variable at index i.
Set Variable Nether Bricks Pop i, v. Set the value of the variable at index i to value v.
Push Current Position Dark Prismarine Push the IP’s current coordinates x, y, z to the stack.
Goto Prismarine Pop z, y, x. Teleport the IP to (x, y, z), retaining the same direction.
Tunnel Deepslate Enter/exit tunneling mode.
Input Number Literal Glass Enter/exit number literal input mode.
Input Text Literal Tinted Glass Enter/exit text literal input mode.

All coordinates are relative to the starting command block, although it is recommended to place the starting block at (0, 0, 0) so the coordinates line up.

Pushing numbers

Numbers can be pushed to the stack using concrete, terracotta, wool, stained glass, or shulker boxes. The value depends on the color and block type. Colors are as follows:

Color Digit
Red 1
Orange 2
Yellow 3
Lime 4
Green 5
Light Blue 6
Cyan 7
Blue 8
Purple 9

Multipliers are as follows:

Block Multiplier
Concrete 1
Terracotta 10
Wool 100
Stained Glass 1,000
Shulker Box 1,000,000

The value pushed is the product of the digit and the multiplier. For example, green concrete would push 5, and cyan wool would push 700.

To push 0 to the stack, use white concrete.

Block values

Get block, set block, and input text literal assign a numeric value to each block. Concrete/terracotta/wool/stained glass/shulker box blocks that can be used to push numbers all have the same block values as their literal forms. An exception to this is air, which has a block value of 0 instead of white concrete, which has the special value of -2,147,483,648. Other blocks are used to fill in the gaps.

List of block values.
Value Block ASCII Character
-2147483648 White Concrete
-172 Waxed Cut Copper
-171 Waxed Copper Block
-170 Warped Wart Block
-169 Warped Stairs
-168 Warped Slab
-167 Warped Planks
-166 Warped Nylium
-165 Warped Hyphae
-164 Verdant Froglight
-163 Tuff
-162 Trapped Chest
-161 Terracotta
-160 Target
-159 Stripped Warped Hyphae
-158 Stripped Spruce Wood
-157 Stripped Spruce Log
-156 Stripped Oak Wood
-155 Stripped Oak Log
-154 Stripped Mangrove Wood
-153 Stripped Mangrove Log
-152 Stripped Jungle Wood
-151 Stripped Jungle Log
-150 Stripped Dark Oak Wood
-149 Stripped Dark Oak Log
-148 Stripped Crimson Hyphae
-147 Stripped Birch Wood
-146 Stripped Birch Log
-145 Stripped Acacia Wood
-144 Stripped Acacia Log
-143 Stonecutter
-142 Stone Stairs
-141 Stone Slab
-140 Stone Bricks
-139 Stone Brick Stairs
-138 Stone Brick Slab
-137 Stone
-136 Sticky Piston
-135 Spruce Wood
-134 Spruce Stairs
-133 Spruce Slab
-132 Spruce Planks
-131 Spruce Log
-130 Spruce Leaves
-129 Sponge
-128 Soul Soil
-127 Soul Sand
-126 Snow Block
-125 Smooth Stone Slab
-124 Smooth Stone
-123 Smooth Sandstone Stairs
-122 Smooth Sandstone Slab
-121 Smooth Sandstone
-120 Smooth Red Sandstone Stairs
-119 Smooth Red Sandstone Slab
-118 Smooth Red Sandstone
-117 Smooth Quartz Stairs
-116 Smooth Quartz Slab
-115 Smooth Quartz
-114 Smooth Basalt
-113 Smoker
-112 Smithing Table
-111 Shulker Box
-110 Shroomlight
-109 Sculk
-108 Sandstone Stairs
-107 Sandstone Slab
-106 Sandstone
-105 Reinforced Deepslate
-104 Redstone Ore
-103 Red Sandstone Stairs
-102 Red Sandstone Slab
-101 Red Sandstone
-100 Red Nether Brick Stairs
-99 Red Nether Brick Slab
-98 Red Mushroom Block
-97 Red Glazed Terracotta
-96 Raw Iron Block
-95 Raw Gold Block
-94 Raw Copper Block
-93 Quartz Stairs
-92 Quartz Slab
-91 Quartz Pillar
-90 Quartz Bricks
-89 Quartz Block
-88 Purpur Stairs
-87 Purpur Slab
-86 Purpur Pillar
-85 Purpur Block
-84 Purple Glazed Terracotta
-83 Prismarine Stairs
-82 Prismarine Slab
-81 Prismarine Bricks
-80 Prismarine Brick Stairs
-79 Prismarine Brick Slab
-78 Polished Granite Stairs
-77 Polished Granite Slab
-76 Polished Granite
-75 Polished Diorite Stairs
-74 Polished Diorite Slab
-73 Polished Diorite
-72 Polished Deepslate Stairs
-71 Polished Deepslate Slab
-70 Polished Deepslate
-69 Polished Blackstone Stairs
-68 Polished Blackstone Slab
-67 Polished Blackstone Bricks
-66 Polished Blackstone Brick Stairs
-65 Polished Blackstone Brick Slab
-64 Polished Blackstone
-63 Polished Basalt
-62 Polished Andesite Stairs
-61 Polished Andesite Slab
-60 Polished Andesite
-59 Podzol
-58 Pink Wool
-57 Pink Terracotta
-56 Pink Stained Glass
-55 Pink Shulker Box
-54 Pink Glazed Terracotta
-53 Pink Concrete
-52 Petrified Oak Slab
-51 Pearlescent Froglight
-50 Packed Mud
-49 Packed Ice
-48 Orange Glazed Terracotta
-47 Ochre Froglight
-46 Oak Wood
-45 Oak Stairs
-44 Oak Slab
-43 Oak Planks
-42 Oak Log
-41 Oak Leaves
-40 Netherrack
-39 Nether Wart Block
-38 Nether Quartz Ore
-37 Nether Gold Ore
-36 Nether Brick Stairs
-35 Nether Brick Slab
-34 Muddy Mangrove Roots
-33 Mud Bricks
-32 Mud Brick Stairs
-31 Mud Brick Slab
-30 Mud
-29 Mossy Stone Brick Stairs
-28 Mossy Stone Brick Slab
-27 Mossy Cobblestone Stairs
-26 Mossy Cobblestone Slab
-25 Mossy Cobblestone
-24 Moss Block
-23 Mangrove Wood
-22 Mangrove Stairs
-21 Mangrove Slab
-20 Mangrove Roots
-19 Mangrove Planks
-18 Mangrove Log
-17 Mangrove Leaves
-16 Magenta Wool
-15 Magenta Terracotta
-14 Magenta Stained Glass
-13 Magenta Shulker Box
-12 Magenta Concrete
-11 Loom
-10 Lodestone
-9 Lime Glazed Terracotta
-8 Light Gray Wool
-7 Light Gray Terracotta
-6 Light Gray Stained Glass
-5 Light Gray Shulker Box
-4 Light Gray Glazed Terracotta
-3 Light Gray Concrete
-2 Light Blue Glazed Terracotta
-1 Lectern
0 Air
1 Red Concrete
2 Orange Concrete
3 Yellow Concrete
4 Lime Concrete
5 Green Concrete
6 Light Blue Concrete
7 Cyan Concrete
8 Blue Concrete
9 Purple Concrete
10 Red Terracotta Newline
11 Iron Block
12 Gold Block
13 Diamond Block
14 Emerald Block
15 Lapis Block
16 Netherite Block
17 Coal Block
18 Obsidian
19 Mossy Stone Bricks
20 Orange Terracotta
21 Cracked Stone Bricks
22 Piston
23 Magenta Glazed Terracotta
24 Sea Lantern
25 Redstone Lamp
26 Deepslate
27 Glass
28 Observer
29 Crafting Table
30 Yellow Terracotta
31 Magma Block
32 Tnt Space
33 Pumpkin !
34 Melon
35 Ancient Debris #
36 Dispenser $
37 Dropper %
38 Bookshelf &
39 Note Block
40 Lime Terracotta (
41 Chest )
42 Ender Chest *
43 Slime Block +
44 Honey Block ,
45 Jukebox -
46 Red Nether Bricks .
47 Nether Bricks /
48 Dark Prismarine 0
49 Prismarine 1
50 Green Terracotta 2
51 Bedrock 3
52 Acacia Leaves 4
53 Acacia Log 5
54 Acacia Planks 6
55 Acacia Slab 7
56 Acacia Stairs 8
57 Acacia Wood 9
58 Amethyst Block :
59 Andesite ;
60 Light Blue Terracotta <
61 Andesite Slab =
62 Andesite Stairs >
63 Azalea Leaves ?
64 Barrel @
65 Basalt A
66 Beacon B
67 Beehive C
68 Birch Leaves D
69 Birch Log E
70 Cyan Terracotta F
71 Birch Planks G
72 Birch Slab H
73 Birch Stairs I
74 Birch Wood J
75 Black Concrete K
76 Black Glazed Terracotta L
77 Black Shulker Box M
78 Black Stained Glass N
79 Black Terracotta O
80 Blue Terracotta P
81 Black Wool Q
82 Blackstone R
83 Blackstone Slab S
84 Blackstone Stairs T
85 Blast Furnace U
86 Blue Glazed Terracotta V
87 Blue Ice W
88 Bone Block X
89 Brick Slab Y
90 Purple Terracotta Z
91 Brick Stairs [
92 Bricks \
93 Brown Concrete ]
94 Brown Glazed Terracotta ^
95 Brown Mushroom Block _
96 Brown Shulker Box `
97 Brown Stained Glass a
98 Brown Terracotta b
99 Brown Wool c
100 Red Wool d
101 Calcite e
102 Cartography Table f
103 Carved Pumpkin g
104 Cauldron h
105 Chiseled Deepslate i
106 Chiseled Nether Bricks j
107 Chiseled Polished Blackstone k
108 Chiseled Quartz Block l
109 Chiseled Red Sandstone m
110 Chiseled Sandstone n
111 Chiseled Stone Bricks o
112 Clay p
113 Coal Ore q
114 Coarse Dirt r
115 Cobbled Deepslate s
116 Cobbled Deepslate Slab t
117 Cobbled Deepslate Stairs u
118 Cobblestone v
119 Cobblestone Slab w
120 Cobblestone Stairs x
121 Cobweb y
122 Composter z
123 Copper Block {
124 Copper Ore
125 Cracked Deepslate Bricks }
126 Cracked Deepslate Tiles ~
127 Cracked Nether Bricks
128 Cracked Polished Blackstone Bricks
129 Crimson Hyphae
130 Crimson Nylium
131 Crimson Planks
132 Crimson Slab
133 Crimson Stairs
134 Crying Obsidian
135 Cut Copper
136 Cut Copper Slab
137 Cut Copper Stairs
138 Cut Red Sandstone
139 Cut Red Sandstone Slab
140 Cut Sandstone
141 Cut Sandstone Slab
142 Cyan Glazed Terracotta
143 Dark Oak Leaves
144 Dark Oak Log
145 Dark Oak Planks
146 Dark Oak Slab
147 Dark Oak Stairs
148 Dark Oak Wood
149 Dark Prismarine Slab
150 Dark Prismarine Stairs
151 Dead Brain Coral Block
152 Dead Bubble Coral Block
153 Dead Fire Coral Block
154 Dead Horn Coral Block
155 Dead Tube Coral Block
156 Deepslate Brick Slab
157 Deepslate Brick Stairs
158 Deepslate Bricks
159 Deepslate Coal Ore
160 Deepslate Copper Ore
161 Deepslate Diamond Ore
162 Deepslate Emerald Ore
163 Deepslate Gold Ore
164 Deepslate Iron Ore
165 Deepslate Lapis Ore
166 Deepslate Redstone Ore
167 Deepslate Tile Slab
168 Deepslate Tile Stairs
169 Deepslate Tiles
170 Diamond Ore
171 Diorite
172 Diorite Slab
173 Diorite Stairs
174 Dirt
175 Dried Kelp Block
176 Dripstone Block
177 Emerald Ore
178 Enchanting Table
179 End Portal Frame
180 End Stone
181 End Stone Brick Slab
182 End Stone Brick Stairs
183 End Stone Bricks
184 Fletching Table
185 Flowering Azalea Leaves
186 Frosted Ice
187 Furnace
188 Gilded Blackstone
189 Glowstone
190 Gold Ore
191 Granite
192 Granite Slab
193 Granite Stairs
194 Gray Concrete
195 Gray Glazed Terracotta
196 Gray Shulker Box
197 Gray Stained Glass
198 Gray Terracotta
199 Gray Wool
200 Orange Wool
201 Green Glazed Terracotta
202 Grindstone
203 Hay Block
204 Honeycomb Block
205 Infested Chiseled Stone Bricks
206 Infested Cobblestone
207 Infested Cracked Stone Bricks
208 Infested Deepslate
209 Infested Mossy Stone Bricks
210 Infested Stone
211 Infested Stone Bricks
212 Iron Ore
213 Jack O Lantern
214 Jungle Leaves
215 Jungle Log
216 Jungle Planks
217 Jungle Slab
218 Jungle Stairs
219 Jungle Wood
220 Lapis Ore
300 Yellow Wool
400 Lime Wool
500 Green Wool
600 Light Blue Wool
700 Cyan Wool
800 Blue Wool
900 Purple Wool
1000 Red Stained Glass
2000 Orange Stained Glass
3000 Yellow Stained Glass
4000 Lime Stained Glass
5000 Green Stained Glass
6000 Light Blue Stained Glass
7000 Cyan Stained Glass
8000 Blue Stained Glass
9000 Purple Stained Glass
1000000 Red Shulker Box
2000000 Orange Shulker Box
3000000 Yellow Shulker Box
4000000 Lime Shulker Box
5000000 Green Shulker Box
6000000 Light Blue Shulker Box
7000000 Cyan Shulker Box
8000000 Blue Shulker Box
9000000 Purple Shulker Box
2147483647 Tinted Glass

Execution modes

Much like Befunge's string mode, CraftyFunge includes several toggleable modes.

Default

While in default mode, the IP will execute instructions according to the instruction table. The IP starts in default mode.

Tunneling

While in tunneling mode, the IP will continue in the same direction until it reaches another deepslate block, ignoring any other instructions.

Numeric literal input

While in numeric literal input mode, the IP will read a number digit-by-digit and push that to the stack. White concrete counts as 0, and colored blocks of concrete/terracotta/wool/stained glass/shulker box (it doesn’t matter the block type) correspond to the other digits 1-9. A coal block will negate the result, and additional coal blocks have no effect. The IP will ignore all other instructions except for direction changes from pistons and will exit when it reaches another glass block. If the IP doesn’t read any valid blocks while in this mode, it will push 0.

Text literal input

While in text literal input mode, the IP will push the block value of each block it encounters to the stack until it reaches another tinted glass block. This is analogous to Befunge’s string mode. One limitation is that tinted glass blocks (having block value INT32_MAX = 2,147,483,647) cannot be read through text literal input. They can still be read through get block or push next block value.

Examples

Hello, World!

Video

Sieve of Eratosthenes

Video

Input

Input in the external interpreter is by default stdin and can be changed to any file.

Input in Minecraft is written in a book and quill called "Input" and is placed in the chest marked "Input" before running a program. Programs are limited to one page of input.

See also

External resources

Interpreter