Streamlang
Streamlang is an esoterical language that works with streams/queues.
Streamlang only has one operator, the arrow. Each item of a stream is equivalent in size to a signed long long.
Syntax
The Arrow
in -> out
This code is an example cat program, as it will take an item from the input stream, and put it on the output stream.
The arrow expects the same amount of streams on each side. Streams do not have to be unique.
a -> b a b -> c d a a b -> c d c
Since the delimiter of the operation is the amount of Streams, it is possible to stack operations
a -> b c -> d e -> f
which is equivalent to
a -> b c -> d e -> f
Literals
Instead of a stream, you can also use a constant literal as a source.
1 -> a 'h' -> b 0x43 -> c "Hello, world!" -> d 0b10101101 -> e
When a literal is used as a destination, it acts as a void and consumes its input.
a -> 0
There are 3 types of literals:
Integers
Basically the same as every other language ever
1 -> a +0 -12 -> b a 0x3b 0b10011 -> c d
Streamlang does not support floats.
Characters
'a' -> a
Strings
"More than one character!" -> a
Strings are a bit special, because unlike all previous items, they push the entirety of themselves into the stream, which means they push more than once
Comments
# Everything now gets ignored #
Comments are started and ended with a octothorpe. They are completely ignored and only server documentary purposes.
Execution
Order of operations
In Streamlang, an interpreter should go through every operation in order until it finds one that is actually executable. When found, it should execute this operation and then return back to the top.
An operation is executable, when
- All of its left-hand streams are not empty
- All of its left-hand streams are constants, and this operation hadn't been previously executed yet.
When the entire list has been traversed, and no executable stream has been found, unless the program can still receive external input through the in stream, it should halt, as no further operations are possible.
Special Streams
In order to make Streamlang Turing complete, certain streams have special functionality.
| Keyword | Functionality |
|---|---|
| - | IO |
| in | READONLY Pulls data from stdin into the program |
| out | WRITEONLY Pushes data from the program into stdout |
| - | Comparisons |
| eq | Compares every item in it. If they are equal, it is pullable from. Flushes eitherway. |
| neq | Compares every item in it. If they are unequal, it is pullable from. Flushes eitherway. |
| lt | Compares every item in it. If they are less than the previous, it is pullable from. Flushes eitherway. |
| gt | Compares every item in it. If they are greater than the previous, it is pullable from. Flushes eitherway. |
| - | Arithmetic |
| sum | When pulled from, outputs the sum of all items inside. |
| prd | When pulled from, outputs the product of all items inside. |
| neg | Negates an item. |
| - | Binary operations |
| and | When pulled from, outputs the binary and of all items inside. |
| or | When pulled from, outputs the binary or of all items inside. |
| not | Inverts an item. |
| - | Misc |
| dup | Duplicates an element. |
| rng | READONLY Returns a random value. |
| hlt | WRITEONLY Halts the program on push. |
Examples
More examples can be found in the repository listed down below.
in -> out
in '1' -> eq eq eq -> a a '1' -> a out '0' 1 -> out hlt
Implementation
- https://codeberg.org/barracudalake/streamlangc (This interpreter hasn't really been bug tested, so any feedback is wanted!)