From Esolang
(Redirected from HAMMERANDSICKLE)
Jump to navigation Jump to search
☭ (HAMMERANDSICKLE)
Paradigm(s) Imperative
Designed by User:Dragoneater67
Appeared in 2026
Memory system Cell-based
Dimensions One-dimensional
Computational class Unknown
Reference implementation C++
Influenced by #b
!I!M!P!O!S!S!I!B!L!E!
Brainfuck
Influenced
File extension(s) .hammerandsickle .☭ .has

(a.k.a. HAMMERANDSICKLE) is an esoteric programming language with the goal of making programming nearly impossible.

Overview

The language is split into 2 phases of execution.

Phase 1

Phase 1 reads the source string character-by-character and executes a command. It has 8 internal registers:

  1. a (uint8, does not affect phase 2)
  2. w (uint8, does not affect phase 2)
  3. h (uint8, the rolling encryption key for output)
  4. q (uint8, the rolling encryption key for input)
  5. p (unbounded, int64 in the reference implementation, the phase 2 memory pointer)
  6. j (unbounded, int64 in the reference implementation, the phase 2 instruction count)
  7. y (unbounded, int64 in the reference implementation, the phase 2 instruction pointer)
  8. g (uint32, PRNG)

They are initialized with these values:

q = '?'
h = '#'
g = 89404137

The rest are initialized to .
Before each command is executed g is recalculated using this formula (where is the current character):

The command is determined by this formula ( is the generated command, is the current character, is the position of the current character):

Command Operation
0
  • a += 3
  • w += 7
  • q -= 43
  • p -= 13
  • g ^= 0xCAFEBABE
1
  • a -= 2
  • w -= 5
  • q += 67
  • p += 17
  • g += a ^ w
2 Generates a character b using this formula:


Subtracts from q
Then, b is appended to the Phase 2 instruction tape and j is incremented.
If b is invalid (not *, # or ?), g is set to 0xDEADBEEF.

Phase 2

Phase 2 is a virtual machine that executes the bytecode generated in phase 1. The virtual machine has:

  • The unbounded memory tape (int8)
  • The unbounded instruction tape (int8)
  • The memory pointer (unbounded, register p)
  • The instruction pointer (unbounded, register y)

Instructions are single ASCII characters. Here is a quick overview of available commands:

Instruction Condition Operation
* Instruction pointer is Odd Adds 251 to the current memory cell, then moves the memory pointer right by 999983 positions.
Instruction pointer is Even Reads a character of input, XORs it with register q, and stores it in the current memory cell, then jumps back 3 instructions.
# Current memory cell is 0 Jumps back 7 instructions, then modifies the instruction at that location by cycling it (*#?* → ...).
Current memory cell is not 0 Moves the memory pointer left by 999979 positions, then adds 241 to the current memory cell.
? Memory pointer is Odd Outputs the character at the current memory cell XORred with the register h, then adds 239 to the current memory cell.
Memory pointer is Even If current memory cell is 0, jump forward 12 instructions. Otherwise, set both memory pointer and the instruction pointer to g mod j.

Any other character is invalid and results in a crash (non-zero exit code). After each instruction is executed:

  1. h is recalculated using this formula ( is current memory cell value and is the current instruction):
  2. q is incremented by 197
  3. y is incremented by 1

The program halts when the instruction pointer goes out of bounds.

Examples

XKCD Random Number

i[G`G0000 T2dySddP>.M!

(NOTE: Most text editors insert a newline at the end of a file, if it fails, that is probably the reason)

External resources

See Also