Malfunge

From Esolang
Jump to navigation Jump to search

Malfunge is an esoteric programming language created by User:ArthroStar11 heavily inspired by Befunge and Malbolge

Data Structure

The data structure of Malfunge is an array of 5 stacks of 32-bit signed integers each with a max size of 1000

Playfield

Much like Befunge, Malfunge uses a playfield of fixed size. In the case of Malfunge the playfield is a 256 x 256 table of characters.

Command List

Flow Control

Important note: for brevity this section will mention "h-cond" and "v-cond" these represent behaviors identical to Befunge's "_" and "|" respectively

  • Retroreflectors (<, >, ^, and <)
    • if approaching from the concave side (i.e from the left with ">") will invert the direction of the program (i.e. left for ">")
    • if approaching from the sloped sides (i.e from above or below with ">") will send the program in the direction of the point (identical to Befunge)
    • if approaching from the pointed side (i.e from the right with ">") will perform a v-cond if retroreflector is pointing horizontally, h-cond otherwise
  • Paddles (| and _)
    • | will invert the direction if approaching from the left or right, performs an h-cond otherwise
    • _ will invert the direction if approaching from above or below, performs a v-cond otherwise
  • Mirrors (/ and \)
    • will reflect the direction 90 degrees represented visually by the mirror (behaves identically to AsciiDots)
  • Misc
    • ? changes the direction randomly
    • o skips the next command in the direction of the pointer

Math

  • numbers (0 to 9)
    • pushes the corresponding number to the current stack
  • Operators (P, M, T, D, and m)
    • pops a then b off of the current stack then pushes b(op)a onto <(current stack + 1) % 5>
      • P adds
      • M subtracts
      • T multiplies
      • D divides
      • m performs modulo

Stack Control

  • S shifts to the next stack up
  • s shifts to the next stack down

I/0

on current stack

  • user input
    • , pushes user input as a character
    • . pushes user input as an integer
  • output
    • ; pops value as a character and prints
    • : pops value as an integer and prints

Misc

  • " toggles string mode (identical to Befunge)
  • I pops a then b off the current stack then pushes 1 if b>a, pushes 0 otherwise
  • i pops a off the current stack then pushes 1 if a == 0, pushes 0 otherwise
  • d duplicates top value
  • @ ends the program

Sample Programs

Hello World

0"!dlrow olleh"o>d;v
                >  <
                @

Truth Machine

.o>dd:v
  >   <
  @

Implementation

ArthroStar11's Interpreter (C source)