Blacktime

From Esolang
Jump to navigation Jump to search

Blacktime is a Whitespace derivative designed and originally implemented in 2014 by Three If By Whiskey. It was inspired by the realization that Whitespace's 24 distinct operations would map very well into a system of encoding instructions as times.

Syntax

 _  _  _  _ 
|_||_||_||_|
|_||_||_||_|

Blacktime programs are composed entirely of spaces (' '), underscores ('_'), vertical pipes ('|'), and line breaks. Instructions are written as contiguous groups of four seven-segment displays, representing either a complete 24-hour time or a "time delta", explained below. There are no syntax errors; if the character in a given position is not the underscore or pipe expected for that position, it is simply ignored.

Evaluation

The initial instruction in a Blacktime program (the "seed") must be a complete, zero-padded, 24-hour time. Each subsequent instruction is a "time delta" whose segments are XOR'd with the previous time's to produce the current time. It is a runtime error, and program execution terminates, if at any point an invalid time is generated by this process.

The previous hour is subtracted from the current, and this value (modulo 24, with the result taking the sign of the divisor) indicates which operation to perform. This same calculation is applied to the minutes (modulo 60) to produce the argument supplied to the operation, if applicable.

Operations

The first eight operations are the ones which take an argument, denoted as n in their descriptions.

Opcode Name Description
0 push Place n at the top of the stack.
1 copy Place at the top of the stack the value n levels deep, such that copy 0 is a synonym for dup.
2 slide Remove the n values beneath the top of the stack.
3 label Create a label called n, to be used as a jump target.
4 call Call the "subroutine" starting at label n; a subsequent ret will resume execution from the point of this call.
5 jump Jump to label n.
6 jz Remove the value at the top of the stack and jump to label n if it was 0.
7 jn ″ if it was negative.
8 pop Remove the value at the top of the stack.
9 dup Duplicate the value at the top of the stack.
10 swap Swap the two values at the top of the stack.
11 add Remove the two values at the top of the stack and push back their sum.
12 sub ″ difference.
13 mul ″ product.
14 div ″ quotient.
15 mod ″ remainder.
16 store Remove the two values at the top of the stack and store the first in the heap at the address indicated by the second.
17 load Replace the value at the top of the stack with the value at the indicated heap address.
18 ret Return from a call operation.
19 ichr Place at the top of the stack the value of a user-supplied character.
20 inum ″ number.
21 ochr Remove the value at the top of the stack and output its value as a character.
22 onum ″ number.
23 exit Terminate program execution, perhaps prematurely.

Example programs

Hello, world!

 _  _     _                    _              _                          _                 _  _  _  _       
 _|| ||_||_|                    |         | ||_             |_  _|      |                  _ |_||  |_|      
|_ |_|  ||_|                   _             |_       | |     ||        |_ |              |_| _ |_ |_       
 _  _                    _  _           _              _                 _                       _  _       
|   _                | | _  _       |_ |_             |   _           _ |                  _|   |           
|_ |_|               | ||_||_|        ||_             |_ |_|          _ |_ |              |     |_  _       
 _  _              _     _                    _        _  _                    _     _                      
|    |            |_|   |  | |            |_ |        |              |         _ |  |                    |  
|_  _              _ | ||_ | |               |_|      |_||_          |        |_|   |_ | |                  
 _                       _                 _              _  _                    _  _  _        _          
 _          |_ |        |                 |            _||  |    |            | | _ |    |      |  |_       
|_|| |        || |      |_ |              |_          |   _ |_ |                 |_ |_  _       |_          
             _  _                                _                       _          
   |_       |  |           |_                    _          |_  _       |    |      
            |_  _          |                    |_|           |         |_ |        

Cat

 _        _     _  `push 0` operations              _                   
 _|  |  | _||_ |   are good places to   _                   |_ |_       
|_   |  | _|  ||_  store commentary.   |            _         |         
    _        _        _                                   _             
|_ |_|      |  | |   |     |_           _|           |     |   |_       
  ||_       |_ |      _    |           |           |      _    |_

Computational class

Because it is possible to interpret brainfuck in Whitespace, Blacktime is trivially Turing-complete.