Pepp*erdine

From Esolang
Jump to navigation Jump to search

Pepp*erdine is an esoteric programming language by Brody Maddox, based off of Chicken by Torbjörn Söderstedt, in which "pep", "erdine" and concatenations of 'p' are the only valid symbols.

Language overview

A chicken program consists of the tokens "pep", "erdine", varying length strings of 'p', and "\n". The first line begins with 'pep', and the final line has 'erdine'. Every line in between has a number of 'p's joined together. The number of 'p's corresponds to an opcode. Trailing newlines are significant, as an empty line will produce a "0" opcode.

Instructions are loaded onto the stack and executed there directly, which allows for injecting arbitrary code and executing it through a jump. Self-modifying code is also possible because the program stack is not bounded.

The user is able to supply an input value before executing the program. This input is stored in one of the two registers.

Memory model

The stack (represents the memory of the program) has three segments.

The first segment contains two registers. The first register just points to the stack itself (by reference). The second register contains the user input, which is usually a string. These registers are used by the LOAD instruction.

The second segment contains the loaded code. For each line of the code there is a cell on the stack containing the amount of 'p's on that line. This segment is directly used for execution. It is automatically padded with a single EXIT instruction.

The third segment contains the actual program stack. As instructions are executed, they will push and pop values in this space. Since the segments are not isolated, it is possible to modify values in the code space or execute in the user stack space.

Instructions

Pepp*erdine supports the following instructions:

Opcode Name Description
0 exit Stop execution.
1 p Push the string "p" onto the stack.
2 add Add two top stack values.
3 subtract Subtract two top stack values.
4 multiply Multiply two top stack values.
5 compare Compare two top stack values for equality, push truthy or falsy result onto the stack.
6 load Double wide instruction. Next instruction indicates source to load from. 0 loads from stack, 1 loads from user input. Top of stack points to address/index to load onto stack.
7 store Top of stack points to address/index to store to. The value below that will be popped and stored.
8 jump Top of stack is a relative offset to jump to. The value below that is the condition. Jump only happens if condition is truthy.
9 char Interprets the top of the stack as ascii and pushes the corresponding character.
10+ push Pushes the literal number n-10 onto the stack.

Examples

Hello, world!

pep
pppppppppppppppppppp
pppppppppppppppppppp
pppp
ppppppppp
ppppppppppp
ppppppp
pppppppppp
pppppppppppppppp
pppppppppppppppp
pppp
ppp
pppppppppp
ppppppppppppppppp
ppp
pppppppppp
pppppppppp
ppppppppppppp
ppppppppppp
pppppppppppp
pppppp

ppp
pppppppppppppp
pppp
ppppppppppppppppppppp
ppppppppppppp
pppppppppppppppp
pppppppppp
ppppppppppppppp
ppppppppppppp
pppppp

pppp
pppppppppppppppppp
pp
pp
ppppppppp
ppppppppppp
pppppp

pp
ppppppppppp
ppppppp
pppppppppppp
pppppp

pppppppppppp
ppp
pppppppppppp
ppppppp
pppppppppppp
pppppp

pppppppppp
ppppppppppppppppppppppppppppppppppppppp
ppp
pppppppp
ppppppppppp
pppppp
erdine

External resources

  • [1] Python implementation