Possible Extentions to Piet Language
4 posters
Page 1 of 1
Possible Extentions to Piet Language
I've been thinking a lot about ways to extend and add more commands to piet. I thought a cool way to do it would be to add gray (#7F7F7F) as a new color. As you enter a gray square, no operation is performed, but as you leave a gray block, there can be a new set of commands based on which color you go to. Operation will be chosen by absolute, rather than relative color, ie. Gray-> Light Red will always do the same thing, regardless of how you got into gray.
This will open up space for 18 new commands. I have a few ideas for possibilities:
Any other ideas or functions you would like to see implemented? Anything that would make programming piet less painful?
This will open up space for 18 new commands. I have a few ideas for possibilities:
Jump - Pop top two values off stack and move cursor to that location (x,y)
PushLocation - Push Current cursor location (x,y) onto stack.
DuplicateLoc - pop top as n, read stack value n deep and push it on top of stack.
Logical operations on top two values:
OR
AND
NAND
XOR
NOR
Decimal Division
Square Root
File IO?
Any other ideas or functions you would like to see implemented? Anything that would make programming piet less painful?
captncraig- Posts : 5
Join date : 2009-09-18
Re: Possible Extentions to Piet Language
Another thought would be to have a codel that moves the reading counterclockwise, as opposed to clockwise. Also, the AND statement could work by splitting up the interpreter path into 2 seperate paths, starting one codel apart from each other. The hardest part of that would be reading 2 sets of data at the same time, so maybe one could read 1 step after the other. That way, programs could look much more elegant!
Re: Possible Extentions to Piet Language
As I see it, Piet is like assembly language. It's a different paradigm than standard assembly, however, and we have to recognize it. We don't really need jump instructions, or an explicit call stack.
Simple moving through the codel-space can be a jump. It's just a question of structure, rather than instructions.
Also, modern computers don't implement a call stack in hardware. A C compiler handles using the machine code to implement a call stack. If there were a C compiler for Piet, it would/should simply make use of the basic instructions.
I'm convinced Piet is turing-complete as-is, and the key to making it more useable is a series of libraries for doing certain tasks, and the development of patterns for programming.
Unfortunately, I don't see these things happening. Wish there was more interest in Piet from more people, and more who are willing to put code together. I imagine a brainf*ck interpreter would generate interest.
Simple moving through the codel-space can be a jump. It's just a question of structure, rather than instructions.
Also, modern computers don't implement a call stack in hardware. A C compiler handles using the machine code to implement a call stack. If there were a C compiler for Piet, it would/should simply make use of the basic instructions.
I'm convinced Piet is turing-complete as-is, and the key to making it more useable is a series of libraries for doing certain tasks, and the development of patterns for programming.
Unfortunately, I don't see these things happening. Wish there was more interest in Piet from more people, and more who are willing to put code together. I imagine a brainf*ck interpreter would generate interest.
skwirl42- Posts : 7
Join date : 2009-08-06
Re: Possible Extentions to Piet Language
I agree completely.
If we could convince the creator of Piet to allow for some new codels for things like file I/O, then interpreters could be made in piet for other languages, and it would gain more popularity. Also, I've been toying with an idea of possibly making a compiler for it, but I need to get much better at programming first.
If we could convince the creator of Piet to allow for some new codels for things like file I/O, then interpreters could be made in piet for other languages, and it would gain more popularity. Also, I've been toying with an idea of possibly making a compiler for it, but I need to get much better at programming first.
Re: Possible Extentions to Piet Language
You don't really need file IO to do that, just something that can mediate the standard IO coming into the piet interpreter.
skwirl42- Posts : 7
Join date : 2009-08-06
Re: Possible Extentions to Piet Language
Piet has everything to build any logical function you need. Just take your time to figure them out by yourself, which is more satisfying than just copying them from below
Piet already comes with two logical operators:
GRT (originally GRE) (greater than) and NOT
I’m working on a Piet interpreter and compiler in Julia. Many of the logical operations are very complex and tedious to enter, so I added a bunch of new opcodes that can get replaced for further processing, if readability isn’t needed anymore. Maybe I’ll also implement a reverse function to make the opcode more understandable by inserting these ‘shorthands’ again.
****Spoilers****
Here are ALL logical opcodes with their replacements. PSH is push, because I don’t like the sound of PUS
As you can see, there is no need for new opcodes to realize the other logical operators.
And Piet is Turing-complete. So, you don’t need any of these other “fancy” things, which would take away too much of the esoteric-ness of Piet. It’s supposed to be painful to program, and it makes it more satisfying once you solved a problem. Jumping around with a simple instruction would destroy much of the juggling with the stack and the roll function. It would make Piet just too boring and simple.
For usefulness, we have languages like Malbolge or Ook! Just kidding.
Imagine someone would want more sophisticated instructions for brainfuck. It would take away all the fun
Besides, you don’t need IO instructions. You can take the output and process it. That’s how the Piet Quine works. The interpreter takes the output of the Piet program and saves it as a file with the ending PNG without further processing. And voilá! You have a Piet program painting itself.
The DuplicateLoc(ation) instruction can already be realized with a negative ROL, then DUP, then ROL back. Use your imagination, a pen and paper. Try it out with a short stack, like 4 or 5 elements long.
Okay, here is a demonstration how digging up a value from the stack works.
Let’s put a copy of the (3) at depth 5 on top of the stack, and return the stack to its original configuration (except the copy on top, of course). The whole procedure takes 9 steps:
Simple pen and paper are everything you need to figure out these little tricks, if you’re absolutely clueless at the beginning. Draw the stack step by step, even if it seems to be tedious, but it helps you to avoid bugs, without needing a computer
All in all—skwirl42 got it right. Programming Piet is similar to programming in assembly code, with a reduced instruction set, and a single stack. And a brainfuck interpreter in Piet is already there!
Piet already comes with two logical operators:
GRT (originally GRE) (greater than) and NOT
I’m working on a Piet interpreter and compiler in Julia. Many of the logical operations are very complex and tedious to enter, so I added a bunch of new opcodes that can get replaced for further processing, if readability isn’t needed anymore. Maybe I’ll also implement a reverse function to make the opcode more understandable by inserting these ‘shorthands’ again.
****Spoilers****
Here are ALL logical opcodes with their replacements. PSH is push, because I don’t like the sound of PUS
- Code:
GRT >
NOT ! (invert)
-----------------------------------
GRQ >= : PSH 2, PSH 1, ROL, GRT, NOT
LES < : PSH 2, PSH 1, ROL, GRT (= NOT GRQ)
LEQ <= : GRT, NOT (=NOT GRT)
EQU == : SUB, NOT
NEQ != : SUB, NOT, NOT
AND && : MUL, NOT, NOT
OR || : NOT, NOT, PSH 2, PSH 1, ROL, NOT, NOT, ADD, NOT, NOT
NAN !&&: MUL, NOT (NAND)
NOR !||: NOT, NOT, PSH 2, PSH 1, ROL, NOT, NOT, ADD, NOT
XOR : NOT, DUP, NOT, PSH 3, PSH 2, ROL, NOT, DUP, NOT, PSH 4, PSH 1, ROL, MUL, PSH 3, ...
PSH 1, ROL, MUL, ADD
XNR : NOT, DUP, NOT, PSH 3, PSH 2, ROL, NOT, DUP, NOT, PSH 4, PSH 1, ROL, MUL, PSH 3, ...
PSH 1, ROL, MUL, ADD, NOT
(XNOR=NOT XOR), logical equality
As you can see, there is no need for new opcodes to realize the other logical operators.
And Piet is Turing-complete. So, you don’t need any of these other “fancy” things, which would take away too much of the esoteric-ness of Piet. It’s supposed to be painful to program, and it makes it more satisfying once you solved a problem. Jumping around with a simple instruction would destroy much of the juggling with the stack and the roll function. It would make Piet just too boring and simple.
For usefulness, we have languages like Malbolge or Ook! Just kidding.
Imagine someone would want more sophisticated instructions for brainfuck. It would take away all the fun
Besides, you don’t need IO instructions. You can take the output and process it. That’s how the Piet Quine works. The interpreter takes the output of the Piet program and saves it as a file with the ending PNG without further processing. And voilá! You have a Piet program painting itself.
The DuplicateLoc(ation) instruction can already be realized with a negative ROL, then DUP, then ROL back. Use your imagination, a pen and paper. Try it out with a short stack, like 4 or 5 elements long.
Okay, here is a demonstration how digging up a value from the stack works.
Let’s put a copy of the (3) at depth 5 on top of the stack, and return the stack to its original configuration (except the copy on top, of course). The whole procedure takes 9 steps:
- Code:
initial depth...<-1--2--3--4-*5*-6->
< TOP...........[ 7 6 5 8 (3) 2 ] BOTTOM >
------------------------------------------------------
PSH*5*.......[ 5 7 6 5 8 (3) 2 ]
PSH 1.....[ 1 5 7 6 5 8 (3) 2 ]
PSH 2..[ 2 1 5 7 6 5 8 (3) 2 ] prepare for negative roll!
SUB.......[-1 5 7 6 5 8 (3) 2 ] create a -1 for negative roll
ROL.............[(3) 7 6 5 8 2 ] 3 from addr. 5 appears on top
DUP..........[ 3 (3) 7 6 5 8 2 ] create a copy
PSH 6.....[ 6 3 (3) 7 6 5 8 2 ] rolling back to former depth + 1
(the stack is 1 higher than before!)
PSH 1..[ 1 6 3 (3) 7 6 5 8 2 ] positive roll this time!
ROL..........[(3) 7 6 5 8 3 2 ] the copy gets buried in the stack,
the original is on top now
Done! In 9 steps.
Simple pen and paper are everything you need to figure out these little tricks, if you’re absolutely clueless at the beginning. Draw the stack step by step, even if it seems to be tedious, but it helps you to avoid bugs, without needing a computer
All in all—skwirl42 got it right. Programming Piet is similar to programming in assembly code, with a reduced instruction set, and a single stack. And a brainfuck interpreter in Piet is already there!
Last edited by DIN99 on Tue Apr 28, 2015 6:33 pm; edited 3 times in total (Reason for editing : More “tricks”)
DIN99- Posts : 4
Join date : 2015-04-17
Location : Germany
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|