Truffle

From Esolang
Jump to navigation Jump to search

This language is dedicated to User:Truttle1.


Truffle is a language by User:PixelatedStarfish that does not use goto statements or any statement that descends from a goto. Any operation that moves a pointer is prohibited, which makes branching hard and parsing harder. It may not be Turing complete, but that’s part of the fun.

Code is written entirely on one line. That is the only way to write code. The program state is defined as a single number of arbitrary length. This number is mutated to another number according to operations defined in the program state.

Mutations

A number is mutated such that a number n is first divided by 1.618 (an approximation of the golden ratio) then n is set to itself mod u where u is the floor of the maximum value in the range of a 64 bit floating point number. This keeps mutations varied and in a reasonable range.

The Stack

Surprise! To determine which stack operation to do next let m be the value of the last mutation and let n be the cardinality of the set of all stack operations, or the number of operations to use. The next stack operation is equal to m mod n.

A value on the stack is in the range of 0 to 255. 255 plus 1 is 0 and 0 minus 1 is 255. Bytes are what you get. The stack starts empty.

Operation Codes

 0 - Push 0 onto the stack.
 1 - Pop and output as a character.
 2 - Increment top.
 3 - Decrement top.
 4 - Double top and push.
 5 - Half top and push floor.
 6 - If top is 0 do last op, otherwise do op 0. 
 7 - Empty stack.
 8 - Push top value (duplicate).
 9 - Swap top and second from top.
10 - Push random value onto the stack.

Errors

There are a small number of errors in this language:

Error
  The generic error case for all possible errors.
Stack Overflow 
  The stack is too large for memory.
Empty Pop
  Popping from an empty stack.
Ranging Error
  This mutation is outside the range of 64 bits.

An error message looks like this:

Stack Overflow 
Attempted op 8
Top of Stack: 255
Mutation: [Current mutation]