Tonnyi

From Esolang
Jump to navigation Jump to search
Tonnyi
Paradigm(s) Imperative
Designed by User:Hasin Israk Toaha
Appeared in 2025
Computational class Turing complete
Reference implementation Unimplemented
File extension(s) .ton

Tonnyi is an esoteric programming language and educational interpreter created by User:Hasin Israk Toaha in 2025. The language is characterized by its use of pure binary opcodes for all instructions and Java-based implementation that uses BigDecimal for high-precision arithmetic operations.

Overview

Tonnyi is an assembly-like language where all instructions are written using their 7-bit binary opcode strings (0b0001010). The language features 44 implemented instructions out of 128 possible opcodes, with operations including memory manipulation, arithmetic, bitwise operations, control flow, and I/O.

The interpreter simulates a 64KB memory space addressable with 4-digit hexadecimal values (0x0000 to 0xFFFF) and supports both integer and floating-point operations with arbitrary precision.

Language Specification

Memory Model

  • Memory Space: 64KB addressable memory (0x0000 to 0xFFFF)
  • Addressing: 4-digit hexadecimal values (e.g., 0x001A, 0xFFFF)
  • Immediate Values: Prefixed with # (e.g., #100, #3.14159, #-42)

Syntax

Programs are written in text files with .ton extension. The basic syntax consists of:

  • Instructions: BINARY_OPCODE operand1 operand2
  • Labels: Defined on their own line ending with colon (:)
  • Comments: Start with //

Example instruction: 0b0001010 0x002A 0x002B (Add values at addresses)

Instruction Set

Tonnyi implements 44 instructions across several categories:

System Operations

  • 0b0000000 - HALT: Stops program execution
  • 0b0000001 - NOP: No operation
  • 0b0000010 - DUMP MEMORY: Prints all non-zero memory values (debug mode only)

Memory Operations

  • 0b0000011 - PRINT: Prints value at address
  • 0b0000100 - LOAD IMMEDIATE: Loads immediate value into destination
  • 0b0000101 - LOAD FROM MEMORY: Copies value from source to destination
  • 0b0000110 - MOV: Alias for LOAD FROM MEMORY
  • 0b0000111 - STORE: Alias for LOAD FROM MEMORY
  • 0b0001000 - SWAP: Swaps values at two addresses
  • 0b0001001 - CLEAR: Sets address to zero

Arithmetic Operations

  • 0b0001010 - ADD: dest = dest + src
  • 0b0001011 - SUBTRACT: dest = dest - src
  • 0b0001100 - MULTIPLY: dest = dest × src
  • 0b0001101 - DIVIDE: dest = dest ÷ src
  • 0b0001110 - MODULO: dest = dest % src
  • 0b0001111 - INCREMENT: addr = addr + 1
  • 0b0010000 - DECREMENT: addr = addr - 1
  • 0b0010001 - POWER: dest = dest ^ src
  • 0b0010010 - NEGATE: addr = -addr
  • 0b0010011 - ABSOLUTE: addr = |addr|

Bitwise Operations

  • 0b0010100 - AND: Bitwise AND
  • 0b0010101 - OR: Bitwise OR
  • 0b0010110 - XOR: Bitwise XOR
  • 0b0010111 - NOT: Bitwise NOT
  • 0b0011000 - SHIFT LEFT: Left shift
  • 0b0011001 - SHIFT RIGHT: Right shift (arithmetic)

Comparison & Control Flow

  • 0b0011010 - COMPARE: Compares two values, sets internal flag
  • 0b0011011 - JUMP: Unconditional jump to label
  • 0b0011100 - JUMP IF ZERO: Jump if comparison result == 0
  • 0b0011101 - JUMP IF NOT ZERO: Jump if comparison result != 0
  • 0b0011110 - JUMP IF EQUAL: Jump if comparison result == 0
  • 0b0011111 - JUMP IF NOT EQUAL: Jump if comparison result != 0
  • 0b0100000 - JUMP IF GREATER: Jump if comparison result > 0
  • 0b0100001 - JUMP IF LESS: Jump if comparison result < 0
  • 0b0100010 - CALL: Push current PC and jump to subroutine
  • 0b0100011 - RETURN: Pop return address and return from subroutine

Stack Operations

  • 0b0100100 - PUSH: Push value onto call stack
  • 0b0100101 - POP: Pop value from call stack

I/O Operations

  • 0b0100110 - INPUT: Read number from stdin into address
  • 0b0100111 - PRINT CHAR: Print value as ASCII character
  • 0b0101000 - PRINT STRING: Print null-terminated string

Special Operations

  • 0b0101001 - RANDOM: Store random number (0-100) in address

Debug Operations

  • 0b0101010 - DEBUG MODE ON: Enable verbose debug output
  • 0b0101011 - DEBUG MODE OFF: Disable verbose debug output

Examples

Hello World

// Load immediate values for 'H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd', '!'
0b0000100 0x1000 #72    // 'H'
0b0000100 0x1001 #101   // 'e'
0b0000100 0x1002 #108   // 'l'
0b0000100 0x1003 #108   // 'l'
0b0000100 0x1004 #111   // 'o'
0b0000100 0x1005 #32    // ' '
0b0000100 0x1006 #87    // 'W'
0b0000100 0x1007 #111   // 'o'
0b0000100 0x1008 #114   // 'r'
0b0000100 0x1009 #108   // 'l'
0b0000100 0x100A #100   // 'd'
0b0000100 0x100B #33    // '!'
0b0000100 0x100C #0     // Null terminator

// Print the string starting at address 0x1000
0b0101000 0x1000

// Halt the program
0b0000000

Addition Program

// Read two numbers and print their sum
0b0100110 0x2000       // INPUT first number
0b0100110 0x2001       // INPUT second number
0b0000101 0x2002 0x2000 // COPY first number
0b0001010 0x2002 0x2001 // ADD second number
0b0000011 0x2002       // PRINT result
0b0000000              // HALT

Implementation

The Tonnyi interpreter is implemented in Java and uses BigDecimal for all arithmetic operations, providing high-precision calculations. The interpreter performs two passes over the source code: first to collect labels, and second to execute instructions.

Computational Class

Though not formally proven, Tonnyi appears to be Turing complete as it supports:

  • Conditional jumps
  • Unbounded memory (within 64KB simulation)
  • Subroutine calls with a stack
  • Arbitrary memory manipulation

External Resources