• Stars
    star
    229
  • Rank 174,666 (Top 4 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 3 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

vizh

An esoteric visual language that takes image files as input based on a multi-tape turing machine, designed for compatibility with C.

Overview

Here is an implementation of memcpy:

Implementation of memcpy in vizh

Yes, you literally pass an image file to the compiler.

The "parser" is based on computer vision and the backend produces C code.

Here's how the parser understands the program (produced if you pass --debug-parser when compiling):

Image decorated with the instructions that are recognised

Here's a C program which calls into the function:

#include <stdio.h>
// Supplied by linking with the vizh object file
void memcopy(uint8_t*,uint8_t*,uint8_t*);

int main() {
    uint8_t str[] = "Hello!";
    uint8_t size = sizeof(str);
    uint8_t to[sizeof(str)];

    memcopy(&size, str, to);
    puts(to);
}

We can compile this into an executable in a single command:

$ vizh memcopy.png main_memcopy.c -o memcopy

Then run it:

$ ./memcopy
Hello!

Errors

But what if you make an error, like this?

Version of the memcopy program with some instructions changed

Well you get the best compiler errors you'll ever see:

The errors highlighted and explained

Implementation

The provided implementation is called vizh and compiles to C and can link executables.

Installation

You can install vizh directly from PyPi:

$ pip install vizh

Dependencies

vizh depends on OpenCV, cffi, and Tesseract OCR.

You can install OpenCV and cffi with pip:

$ pip install opencv-python cffi

You'll have to install Tesseract OCR separately. See their documentation for instructions.

Usage

Usage: vizh [OPTIONS] [INPUTS]...

Options:
  --version               Show the version and exit.
  -c, --compile-only      Only compile, don't link.
  -o, --output-file PATH  Output file for executables or vizh object files.
  -q, --quiet             Suppress output.
  --debug-parser          Display how the parser understands your source file.
  --help                  Show this message and exit.

The compiler can take any combination of image files, C sources files, and object files.

You may need to set the TESSDATA_PREFIX environment variable to the folder containing Tesseract data. If you're on Linux this is likely /usr/share/tesseract-ocr/<version>/tessdata.

Language

Abstract Machine

The vizh abstract machine consists of:

  • Some number of tapes which are contiguous groups of 8-bit unsigned integers
  • A read/write head with storage for a single 8-bit unsigned integer

The initial state of the abstract machine is:

  • A single tape of size 4096 is allocated with all cells initialised to 0
  • The read/write head is initialised to the left-most cell of this tape

See instructions for the valid operations on the abstract machine.

Program

A vizh program consists of a number of functions, each in its own image file. (What image types are allowed? Ideally at least png and jpg)

The entry point to a vizh program is a function called main. (Note that the main function gets mangled as vizh_main. For all other functions the symbol name is the same as the vizh name).

Functions

A vizh function is an image file containing:

  • The name of the function at the top left of the image
  • The number of arguments (tapes) it takes at the top right of the image
  • A sequnce of instructions in a horizontal lines

Function names are alphanumeric: [a-zA-Z][a-zA-Z0-9]*.

The tapes available to a vizh function consist of its tape arguments. On entry to the function the r/w head is initialised to the start of the first tape argument, if any.

A function returns when control flow reaches the end of its instructions.

Any tapes allocated by a function are automatically deallocated when the function exits.

Function Calls

When you call a function subsequent pointer arguments are taken from the currently active tape onwards.

For example, given the following state of the abstract machine where ^ is the last position of the r/w head on that tape and $ is the active tape:

 t1 01234
     ^
$t2 99999
    ^
 t3 00000
    ^

Then a call to a function that takes two tapes would supply the arguments t2, t3.

Instructions

The valid instructions in vizh and their encodings are:

  • Left arrow: move the r/w head left
  • Right arrow: move the r/w head right
  • Up arrow: move the r/w head to the tape above the current one
  • Down arrow: move the r/w head to the tape below the current one
  • Function name in a circle: call the given function
  • +: increment the value pointed to by the r/w head by 1
  • -: decrement the value pointed to by the r/w head by 1
  • Equilateral triangle with the point at the top: read the cell pointed to by the r/w head into the r/w head storage
  • Equilateral triangle with the point at the bottom: write the value stored in r/w head storage into the cell pointed to by the r/w head
  • [<instructions>]: loop over the instructions between the brackets until the value pointed to by the r/w head at the start of the loop is 0

When you move the r/w head up or down, the position it was last at for the previous tape is saved. E.g. given this state of the abstract where ^ is the last position of the r/w head on that tape and $ is the active tape:

$t0 01234
    ^  
 t1 01234
    ^

The sequence of instructions "right right right down" would result in this state:

 t0 01234
       ^  
$t1 01234
    ^

Comments

Comments in vizh are anything enclosed in a rectangle. Stick what you want in there.

Standard Library

The vizh standard library is called libv. Much of it is implemented in vizh itself and it is built when you install vizh. It provides the following functions:

I/O

  • readin: read an ASCII character from stdin and write its integral representation into the cell pointed to by the r/w head
  • print: print the value of the cell pointed to by the r/w head to stout, interpreted as an ASCII character
  • putstr: write the null-terminated ASCII string starting at the position pointed to by the r/w head to stdout.

Strings

  • geta: puts the character a at the current position of the r/w head.
  • getA: puts the character A at the current position of the r/w head.

Arithmetic

  • add given tape cells a,b from the r/w head, results in a+b,0.
  • mul given tape cells a,b,c from the r/w head, results in a*b,0,0.
  • zero given tape cell a from the r/w head, results in 0

Memory

  • newtape: allocate a new secondary tape underneath the last one currently allocated for this function (or the primary tape if there are no secondary tapes)
  • freetape: deallocate the bottom-most secondary tape for this function (no-op if there are not any)

More Repositories

1

expected

C++11/14/17 std::expected with functional-style extensions
C++
1,307
star
2

optional

C++11/14/17 std::optional with functional-style extensions and reference support
C++
793
star
3

minidbg

A mini x86 linux debugger for teaching purposes
C++
507
star
4

function_ref

A lightweight, non-owning reference to a callable.
C++
168
star
5

typeclasses

Future C++ implementation of Rust-like trait objects with no boilerplate
C++
116
star
6

cpp-documentation-example

An example of setting up Sphinx for C++ and building with CMake and Read the Docs
CMake
85
star
7

actions-eleventy

GitHub Action for generating a static website with Eleventy
Shell
84
star
8

non-binary

πŸ’›β™‘β™₯πŸ’œ
Isabelle
76
star
9

ranges

Ranges that didn't make C++20
C++
73
star
10

generator

Single-header, ranges-compatible generator type built on C++20 coroutines
C++
57
star
11

tl

A bunch of small C++ utilities
C++
54
star
12

caginator

TypeScript
43
star
13

secret-hitler-strategies

Unofficial Secret Hitler strategy guide
HTML
34
star
14

etkf

Embarrassingly templated keyboard framework
C
32
star
15

enjamb

An esoteric programming language where it's not what's in your lines that matters β€” it's where you break them.
C++
29
star
16

dltrace

A demonstration of tracing dynamic library loading and unloading on Linux.
C++
15
star
17

tartanllama.github.io

CSS
15
star
18

piscrn

A screenshot server, library, and command-line utility for the Raspberry Pi
C
12
star
19

advent-of-code-2020

Rust
11
star
20

lameduck

Terrible Brainfuck to x64 compiler developed live in an hour
C++
11
star
21

aoc-2021

C++
7
star
22

writing-a-linux-debugger

7
star
23

icu-emscripten

Binaries and headers for ICU built for Emscripten
C
7
star
24

aoc-2022

C++
5
star
25

koura

A C++ text template engine.
C++
5
star
26

cppquiz17

Porting questions on cppquiz.org to C++17
C++
4
star
27

rustcpp

Rust
4
star
28

tl-docs

Documentation for the tl libraries
Python
4
star
29

jork

C++
4
star
30

li1I

A domain-specific programming language for integer calculations. Includes LLVM-based compiler.
C++
4
star
31

cppcon-cmake

CMake
3
star
32

cpppaperbot

Python
3
star
33

amer

A C++17 static website generator
CSS
3
star
34

tl-cmake

CMake
3
star
35

advent-of-code-2018

C++
3
star
36

retroman

LaTeX template for writing retro-style technical manuals
TeX
3
star
37

pet_bee

Lua
3
star
38

raytracer

Simple C++ raytracer
C
2
star
39

secrethitler.tv

Secret Hitler on your TV!
JavaScript
2
star
40

sybrand.ink

HTML
2
star
41

shotts

C++
2
star
42

codeart

Sass
2
star
43

elfheadedit

Small ELF file header editor
C++
2
star
44

elmscrew

An online brainfuck debugger
Elm
2
star
45

trashheap

an online """""art"""" journal whomst uploads trash
JavaScript
1
star
46

actions-eleventy-test

1
star
47

caginator-test

1
star
48

azure-keyvault-encryption-test

C++
1
star
49

actions-test

C++
1
star
50

presentation_optional_expected

CSS
1
star
51

cpp-con

C++
1
star
52

cpphalloffame

HTML
1
star
53

tartanllama.xyz

HTML
1
star
54

constraint-solver

[OLD] A constraint solver
Common Lisp
1
star