Initial commit
This commit is contained in:
commit
4b69cca60f
32
README
Normal file
32
README
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
Horrlang is an esoteric language, you should not try it.
|
||||||
|
|
||||||
|
In Horrlang, memory and instruction are mixed, so you can use old instruction
|
||||||
|
as new memory places or do some metaprogramation rewriting your code as it run.
|
||||||
|
|
||||||
|
Just like in LISP but ... without lists ... good luck ...
|
||||||
|
|
||||||
|
So in Horrlang you have basically 2 pointers, a memory one and an instruction
|
||||||
|
one. Both starts at 0. The instruction one follow instructions that can move
|
||||||
|
the memory pointer, look at instruction set :
|
||||||
|
|
||||||
|
Instruction set :
|
||||||
|
|
||||||
|
Lx : Move memory head left x chars (defaults to 1)
|
||||||
|
Rx : Move memory head right x chars (defaults to 1)
|
||||||
|
|
||||||
|
Nx : Goto the next char that is x
|
||||||
|
Px : Goto the prev char that is x
|
||||||
|
O : Output current value under memory head
|
||||||
|
I : Read from stdin to the current memory head location
|
||||||
|
K : Decrement current memory location
|
||||||
|
H : Increment current memory location
|
||||||
|
Jx : Jump to prev char X if current memory location != 0
|
||||||
|
|
||||||
|
The Hello World :
|
||||||
|
R9R9R9R4OROROROROROROROROROROROHello World.
|
||||||
|
|
||||||
|
Writing a serie of P should like :
|
||||||
|
R5OP5P or R3OP3
|
||||||
|
|
||||||
|
Write 123456789 using a loop :
|
||||||
|
R9R3:ROHLKJ:81
|
70
horrlang.py
Executable file
70
horrlang.py
Executable file
|
@ -0,0 +1,70 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
class Machine:
|
||||||
|
def __init__(self, code):
|
||||||
|
self.mem = [ord(char) for char in code]
|
||||||
|
self.exc_ptr = 0
|
||||||
|
self.mem_ptr = 0
|
||||||
|
|
||||||
|
def get_integer(self):
|
||||||
|
parameter = 0
|
||||||
|
while chr(self.mem[self.exc_ptr + 1]) >= '0' \
|
||||||
|
and chr(self.mem[self.exc_ptr + 1]) <= '9':
|
||||||
|
self.exc_ptr += 1
|
||||||
|
parameter = parameter * 10 + (self.mem[self.exc_ptr] \
|
||||||
|
- ord('0'))
|
||||||
|
if parameter == 0:
|
||||||
|
parameter = 1
|
||||||
|
return parameter
|
||||||
|
|
||||||
|
def L(self):
|
||||||
|
self.mem_ptr -= self.get_integer()
|
||||||
|
|
||||||
|
def R(self):
|
||||||
|
self.mem_ptr += self.get_integer()
|
||||||
|
|
||||||
|
def O(self):
|
||||||
|
sys.stdout.write(chr(self.mem[self.mem_ptr]))
|
||||||
|
|
||||||
|
def I(self):
|
||||||
|
self.mem[self.mem_ptr] = ord(sys.stdin.read(1))
|
||||||
|
|
||||||
|
def N(self):
|
||||||
|
self.exc_ptr += 1
|
||||||
|
search = self.mem[self.exc_ptr]
|
||||||
|
while self.mem[self.exc_ptr] != search:
|
||||||
|
self.exc_ptr += 1
|
||||||
|
|
||||||
|
def P(self):
|
||||||
|
search = self.mem[self.exc_ptr + 1]
|
||||||
|
self.exc_ptr -= 1
|
||||||
|
while self.mem[self.exc_ptr] != search:
|
||||||
|
self.exc_ptr -= 1
|
||||||
|
|
||||||
|
def J(self):
|
||||||
|
if self.mem[self.mem_ptr] != ord('0'):
|
||||||
|
search = self.mem[self.exc_ptr + 1]
|
||||||
|
self.exc_ptr -= 1
|
||||||
|
while self.mem[self.exc_ptr] != search:
|
||||||
|
self.exc_ptr -= 1
|
||||||
|
|
||||||
|
def H(self):
|
||||||
|
self.mem[self.mem_ptr] = self.mem[self.mem_ptr] + 1
|
||||||
|
|
||||||
|
def K(self):
|
||||||
|
self.mem[self.mem_ptr] = self.mem[self.mem_ptr] - 1
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
while True:
|
||||||
|
if self.exc_ptr >= len(self.mem):
|
||||||
|
sys.exit(0)
|
||||||
|
control = chr(self.mem[self.exc_ptr])
|
||||||
|
if hasattr(self, control):
|
||||||
|
getattr(self, control)()
|
||||||
|
self.exc_ptr += 1
|
||||||
|
|
||||||
|
Machine(sys.argv[1]).run()
|
Loading…
Reference in New Issue
Block a user