Channeler
Channeler is an esoteric programming language created by User:Doridian. It is based around the idea of messaging channels (essentially function calls).
Channeler uses 3 registers. R1, R2, RC and has a channel messaging (aka call) stack. This stack also keeps track of register values, so beyond the outlined special channels, your own channels cannot modify register values after they return control back to the caller. There also is a single memory cell called M that can be read and written to at will and is unaffected by the stack.
Reference interpreter in Python (with example programs also outlined here): https://github.com/Doridian/channeler
The design is not finalized and I welcome suggestions via GitHub issues, discussion page or whichever other method you prefer.
Instructions
OpCode | Description |
---|---|
T
|
Sends a message to the channel named by the ASCII code of the contents of RC |
CR#
|
Puts the number # (can have an arbitrary amount of digits, terminated by whitespace) into register specified by R or the memory cell (must be either 1, 2, c/C or m/M) |
cRC
|
Puts the ASCII code of C into the register specified by R or the memory cell (must be either 1, 2, c/C or m/M) |
HC
|
Registers a channel handler for channel specified by ASCII code of C to the code following this (this gets parsed at interpreter startup, like a label). Must be right after a newline |
h#
|
Registers a channel handler for channel specified by number # (can have an arbitrary amount of digits, terminated by whitespace) (this gets parsed at interpreter startup, like a label). Must be right after a newline |
R
|
Return from channel handler (causes program to exit if called outside of a channel handler) |
mR
|
Copies value of memory cell to register specified by R (must be either 1, 2 or c/C) |
MR
|
Copies value of register specified by R (must be either 1, 2 or c/C) to memory cell |
X
|
Terminate program immediately |
#
|
Ignores all code until a newline, making comments feasible |
Unrecognized OpCodes cause an error!
Special channels
Channel | Description |
---|---|
+
|
Sets R1 = R1 + R2 |
-
|
Sets R1 = R1 - R2 |
*
|
Sets R1 = R1 * R2 |
/
|
Sets R1 = R1 / R2 (integer division) |
$
|
Sets R1 = R1 ^ R2 (pow function) |
%
|
Sets R1 = R1 % R2 |
#
|
Sets R1 = 1 if R1 was positive, -1 if negative and 0 if 0 (sign operation) |
.
|
Outputs contents of R1 as an ASCII character |
:
|
Outputs contents of R1 as a number |
,
|
Reads ASCII character from input into R1 |
;
|
Reads one character as a number into R1 |
x
|
Swaps R1 and R2 |
X
|
Swaps R1 and RC |
^
|
Increments R1 by 1 |
v
|
Decrements R1 by 1 |
Example programs
Hello World
cc. # Put . into RC c1HT c1eT c1lT c1lT c1oT # Put first word into R1 sequentially and transmit each c1 T # Put space into R1 and transmit c1WT c1oT c1rT c1lT c1dT c1!T # Put second word into R1 sequentially and transmit each
OUTPUT: Hello World!
cat
ccC T # Jump to channel C (loop) HC # Put "," into RC, transmit to read char, then put "." into RC, transmit to write it out. Then jump back to the start (">" in RC, -29 in R1, transmit) cc, T ccY T cc. T ccC T R HY # Check for 0 in R1 cc# T # sign operation ccX T # swap R1 to RC T # call channel by sign R h0 X R h1 R
OUTPUT: Your input, terminates on end-of-input
Truth Machine
cc, T # Put "," into RC, transmit to read input into R1 ccX T # Put "X" into RC, transmit to swap RC with R1 (so now input is in RC) T # Transmit, essentially jumping to channel described by user input R # Return to exit program H0 c10 cc. T R # Handler for 0, put 0 into R1, "." into RC, transmit (prints 0), then return H1 c11 cc. T cc1 T R # Handler for 1, put 1 into R1, "." into RC, transmit (prints 1), then call self (Added R to allow for tail-call optimization)
OUTPUT: 0 if you input 0, an infinite string of 1s if you input 1